Assigning A Variable To The Result Of An If Else Statement
I would like to make the result of my if else statement to be added into an arithmetic equation, so I would like to make it a variable. Code:
View Complete Forum Thread with Replies
Related Forum Messages:
What? Assigning A Session Variable Also Assigns The Local Variable?
Alright, In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is burns. Here is the code: $frank = "burns"; $_SESSION['frank'] = "black"; echo "DEBUG: frank's last name is is $frank"; What is coming into play here? I thought of register_globals but I thought that only dealt with GET, POST, REQUEST, etc.
View Replies !
Assigning JS Variable To PHP
Suppose I have a variable like this JS var index =1; I need to assign this to a PHP variable like this <?php $index = echo "index"; ?> Somehow this doesnt work and the page fails to load. What wrong am I doing ?
View Replies !
Assigning Variable
I'm a newbie when it comes to PHP, I've hit a brick wall trying to figure this out. I want to look up "user_id" from a table and assign it to the variable $user_id. I keep getting an undefined index notice and I need it to be defined. $query = "SELECT user_id FROM users WHERE last_name = '{$last_name}'"; if(!($result = @mysql_query($query, $connection))) showerror(); $row = mysql_fetch_row($result); $user_id = $row[user_id];
View Replies !
Assigning A Variable
I'm trying to multiply $total before I write to the database. $total is always the number of tickets times 25 ($25 per ticket) plus any donations this is what I have: PHP Code: <?php if ($submit) { Â Â Â Â Â Â Â Â {$total = $tix*25+$donation} Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â $sql = "INSERT INTO vday (name,address,city,state,zip,email,vp,day,tix,donation,total,ccname,ccnum,ccmonth,ccyear,cctype,notes,entered) VALUES ('$name','$address','$city','$state','$zip','$email','$vp','$day','$tix','$donation','$total','$ccname','$ccnum','$ccmonth','$ccyear','$cctype','$notes', Ɔ')"; Â Â Â Â Â Â Â Â $result = mysql_query($sql);Â Â Â Â Â Â Â Â } ?>
View Replies !
Assigning Function To Variable
I've been trying to pass a function name to a variable to store it and run it later.. here's a snippet: $this->timer(1,"ping",$this->action->ping(),REPEAT); Not putting "$this->action->ping()" in quotes runs it, however putting it in quotes results in the error: Code:
View Replies !
Assigning A Variable To A Table
I have a master page with a list of products - that list comes from a table that contains a column of other table names. These other tables break down the products into subcategories (like if you click on cars, it gives a break down of honda, ford, etc.). I set this up so once you click on, say cars, in the master page, the url sends a $_GET value with the subcategory table name to the next page. I then assign a variable (say $displayTable) to that $_GET variable and run the query below to extract the subcategories, like honda, toyota, etc. Works pretty good since all the subcategory tables (like cars, pickup trucks, etc.) have the same column names - only the items in the tables change. I just can't seem to find any books or tutorials that assign a variable to a table (or even a database for that matter). Is there any problem with doing that? $query="SELECT product FROM $displayTable"; $result=mysql_query($query); while ($row=mysql_fetch_assoc($result)) { echo $row['product']; echo "<br>";}
View Replies !
Assigning Variables To A Variable / Mail()
What I want to do is send a list of variables through email. I have the mail() working. My problem is assigning the varibles. $what2mail = $ price1 $price2 $subtotal ; $to = $email; mail($to, "Order", $what2mail,"From:me@mycompany.com"); Obviously the $what2mail line is not correct. This will also include some text, i.e. Your order has been received.
View Replies !
IF Statement Giving Wrong Result After Image Resize
This bit of script copys an uploaded image to a directory after it has been resized. The image resize works and the image is copied to the required destination. The only problem is what is echoed to the screen. Since all actions have been performed, it should echo "File stored sucessfully as $filename.". Instead it echos "Could not save file as $filename". Any pointers to where i may be going wrong? PHP Code:
View Replies !
MySQL UNION: Only The First Select Statement Returns A Result.
I am attempting to join multiple select statements into a single query. However, I am not able to extract the result of any of the UNIONED selects. $query1 = mysql_query (" ( SELECT SUM(deposits) AS total_deposits FROM table1 ) UNION ALL ( SELECT SUM(withdrawals) AS total_withdrawals FROM table1 ) ") or die (mysql_error()); $result1 = mysql_fetch_array($query1); extract($result1); When I echo the results of the second select statement I get nothing. echo $total_withdrawals;
View Replies !
Result Mysql As Variable
I have an select on which the user choose property, arrival and departure dates for calculating the price, works perfect. But I need to put in some sort of error if the person choose dates higher than end date in the database, What I want to do is this, but don´t work of course: sep_fin is an datecolumn in the database if ($salida>"sep_fin") { echo "¡ There are no prices yet!"; } elseif ($row = mysql_fetch_array($result)){
View Replies !
Getting MYSQL Result Into Single Variable
I have a MYSQL query running that returns a single string of data but it is returned as an array. What I need to do is store that single piece of data in a variable. I know it's probably a really simple process but it has been irritating me for far too long. the result I get when I use print_r($result) is: Array ( [ADDDATE(񟭇-04-05', INTERVAL 6 DAY)] => 2007-04-11 ) I can't figure out how to store the 2007-04-11(the result) into a single variable named $end_date.
View Replies !
Convert CURL Result Into A Variable
I have am XML query sent through cURL. The query that is sent returns another xml file which contains more info (for credit reports i.e., you send a name, ssn etc and get back the result) The problem is the reult comes back like this: "Firstname lastname ssn otherinfo .. . . . ." I think the explode function would work well with this but first I need to convert the cUrl result into a a variable.. Code:
View Replies !
Sql Statement As Variable.
$field = 'phone_number' $customer = 'fred' $query = mysql_query("SELECT `'{$field}'` FROM `customers` WHERE `name` = '{$fred}' "); // note the back quotes around $field.
View Replies !
Assign MySQL Function Result To PHP Variable
I know to use: mysql_fetch_row($result) to convert a row from a SQL query result set into an array for use with PHP. but in the case of SQL queries that return one value, such as calls to MySQL functions, is there another PHP mysql api function I should use. For example, right now I use a "workaround" technique from PHPBuilder: $result=mysql_query("SELECT COUNT(*) FROM tablename"); list($numrows)=mysql_fetch_row($result); Rather than using this "workaround" code is there a way to simply assign the result of the MySQL function query to a variable. $result=mysql_query("SELECT COUNT(*) FROM tablename"); $numrows=mysteryfunction($result);
View Replies !
Variable Select Statement
I would like to have a form that gives the user choices for selection parameters for email, printing etc. A real simple example: Give me all ______ who ______ when _______ where _______ I can figure this out if all of the selections are filled, but NOT if they just decide to use only one of the selection choices. I'm sure this is idiotic, but I'm really new to php and my ideas are writing checks my programming skills can't cash.
View Replies !
Problem Getting The Variable From The URL Into My SQL Statement.
Having a problem getting the variable from the URL into my SQL statement. What am I doing wrong? If I hard code a variable in, I get the output. whatson.php .... echo"<tr> <td width=ཋ%' align='right'><font face='Trebuchet MS' size=ƈ'>$startdate</font></td> <td width=ƈ%'><font face='Trebuchet MS' size=ƈ'> </font></td> <td><font face='Trebuchet MS' size=ƈ'>$title</font></td> <td width=ཋ%'><font face='Trebuchet MS' size=ƈ'><a href='whats_detail.php?$wid=$whatsid'>More >></a></font></td> </tr>"; ..... ..........................
View Replies !
Need To Enter Variable In SQL Statement
I have a php file that exports my MySQL DB to a spreadsheet (see below). This is great, but I need one more piece of functionality to finish what I'm doing. I need a form (HTML) to come up, prompting the user for a lead number (the primary key). I then want all the records AFTER AND INCLUDING that number to be exported to the spreadhseet, instead of the current way I have it set up, where it exports the entire DB every time. Code:
View Replies !
Passed Variable Not Working In An If Statement
I am setting up a website where students can login and browse their course information and handouts. I have set up a database with there courses in and have managed to get each students courses to appear after they have logged in correctly. The course shows as a hyper link and is passed to a page where an if statement checks which course it is and then directs them to the relevant page. Code:
View Replies !
Making An Echo Statement A Variable
I have a form, where the user uploads images, this works fine, but once the image is uploaded I would like to have the page refreshed with the specific image that the user uploaded. I have it set up so that when the user uploads the image, it goes into a specific folder, like so move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; So my question is how can I get the image to show up in the user section so that they can see what image they've just uploaded.
View Replies !
Using A Variable Inside Of An EXEC() Statement
I am running into an issue... exec('schtasks /CREATE /ST 15:00 /TN $id /TR c:second.php /SC once /RU "NT AUTHORITYSYSTEM"'); above is the command i am trying to execute within a php script, and $id is a variable that is passed through another program. $id is represented by a 5 digit number. What i am trying to do is create a task once my script runs that has the $id number as the task name. each time i run the above, my task is named $id and not the number that the variable represents.
View Replies !
Variable As Column Name In MySQL Statement
Let's say db has 4 cols: user id, favorite color, shoe size, hair color. User only has the option of entering 2 variables. 1 has to be user id, 2nd one (radio button) can be color OR size OR hair color. Depending on what user entered, php should look up user id #, and then locate parameter under variable 2 col (whatever was entered for variable 2: fave color or shoe size or hair color) that belongs to that user id.
View Replies !
Using ISSET To Set POST Variable To Part Of Where Statement
I am trying to check to see if the post value CategoryID submitted from the page before is there and if it is then to assign two variables and do a query with them. I am getting an error PHP Parse error: syntax error, unexpected T_STRING in line 13 which is the line that has the query in it......
View Replies !
Write The Sql Query Using A WHERE Statement For The Session Variable
I have initiated a session variable at log-on that holds the user's user name which is his/hers email address. I want to use this user name from the session variable to insert data to the correct user in the db. How do I write the sql query using a WHERE statement for the session variable. i.e. INSERT into client(name,surname) values ('$name','$surname') WHERE email = (this is where I'm lost!)
View Replies !
Correct Syntax For If Statement Inside Variable Definition
What is the correct syntax for the "if statement" below? I want to concatonate it with the information on either side. Without the information, the page shows Member_First Member_Last, as it should. With the "if statement," it shows a blank page. I know the syntax is incorrect. What should it be? <?php $thisPage=($row_rs_Member['Member_First'].' '.<?php if ($row_rs_Member['Member_Middle'] <> NULL) echo $row_rs_Member['Member_Middle'].' '; ?>.$row_rs_Member['Member_Last']); ?>
View Replies !
Assigning A Value
Hi all, I have a form that when submitted goes to the script below: <? $date_in = date("Ymd"); $db = mysql_connect('localhost', '', ''); if (!$db) { echo "Error: Could not connect to database. Please try again later."; exit; } mysql_select_db("rip"); $query = "insert into securepay(pay_id, name, address, city, postcode, telephone, instructions, ponum, optional_info, amount, merchant_id, date_in) values('$pay_id','$name','$address','$city','$postcode','$telephone','$instructions','$ponum','$opti onal_info','$amount','$merchant_id','$date_in')"; $result=mysql_query($query); if($result) header ("Location: sales_cc.php?pay_id=$pay_id"); echo "<br><a href="membership.php">Back to Members</a>"; ?> My problem is that when the data is inserted into the database and the header function is executed the $pay_id value on the sales_cc.php page always equals "0". How can i assign the correct value for $pay_id corresponding to the form entry? I don't know if i have explained this too clearly but if you reply i can answer your questions. Cheers, micmac
View Replies !
$Variable Won't Work In "if" Statement
The PHP code below is a snippet from an image upload script on which I am working. If I extract the $AllowableImageHeight variable value from the MySQL database the " if" statement works - but the value of $AllowableImageHeight is "zero". However, if I assign the value to the $AllowableImageHeight variable within the script like so: $AllowableImageHeight = "50"; the "if" statement works just fine. As a test, I have echoed the $AllowableImageHeight variable outside of the if statment - it outputs just fine whether the variable is extracted from the MySQL database or whether the variable is assigned on the script page. I can't figure it out. I've been wrestling with this problem since yesterday. If I extract the variable from the MySQL database it outputs in the browser but it won't work in the "if" statement. However, if I assign the value to the variable directly on the script page the variable works perfectly fine in the "if" statement!!
View Replies !
Assigning A Null Value
I have a set of radio buttons labelled 1-5 and a 'not selected' option which I have coded as 6. I later use responses of 1-5 to calculate a score, but at the moment the 6 is included in that score when it should really be excluded as null. Is there a way to tell PHP that any values of ƌ' should be null, and to use Ɖ' instead?
View Replies !
Assigning A $_SESSION
I need to be able to pass a very large array between PHP pages. $_SESSION['holder_array'] = array(); and then assign to the $_SESSION['holder_array'] as though it were just created as $holder_array = array();
View Replies !
Assigning Places
Im trying to figure out how to designate places to teams and how it should be coded. For example, I have 5 teams. After a tournament each teams results are input one at a time. How should I code the places (1st, 2nd, 3rd, etc.) Do I need to add a field to the results table for places? And if so, do all of the results get input and then click a button to designate each teams place or have it check the result getting added to the database against whats already there and then designate the appropriate place.
View Replies !
Assigning Values To Arrays
I am performing a MySQL SELECT (which returns multiple rows) to $result and then extracting the results with mysql_fetch_array($result). I then want to build a number of arrays using the fields of each row. Here is the relevant code: <snip> $result = $i = 1; while ($row = mysql_fetch_array($result)) { extract($row); /* break the row into its fields */ $array0[$i] = $row[0]; /* 1st Field of Row */ $array1[$i] = $row[1]; /* 2nd Field of Row */ $array2[$i] = $row[2]; /* 3rd Field of Row */ $i++; } </snip>
View Replies !
Assigning Values Within Href
I'm having a hard time finding information (probably due to how I'm phrasing my searches) on how to assign a variable to an href. The big picture is I have a bunch of photos I'm trying to put on my website. I have an equally large bunch of thumbnails with links, all to the same page (pictures.php) that has a snippet of php (seen below). In my links I am attempting to assign a value to a variable that corresponds with a picture. Code:
View Replies !
Assigning Perl's Output
I have a perl script that retrieves country name based on an ip. I need to pass it on to my php code as a variable. I tried php's Perl extension but that won't work. The "virtual" function almost does its job, however it does not work with ob_start that looks very simple: I only need to assign perl's output to php variable.
View Replies !
Assigning Id Value From Database Table
I have a products table and an uploads table. uploads stores image and product stores product info. okay heres the prob. Within my form im posting all the neccessary details but i also need to pass the upload_id from the uploads table to be stored as a value in the products table. Currently my script seems to be logging the same image id and ultimately pulls the wrong image. Ill include the code: ....
View Replies !
Assigning Unique Names
I'm creating an upload page where I use dreamweaver to create a multi form to upload multiple Images. The page I'm working on has 6 images. I currently have it so when the user hits submit, it uploads the image into my ftp's images folder and renames it to 1_image1.jpg. I need to have the images in a named scheme such as 1_image1.jpg, 1_image2.jpg, 1_image3.jpg, 1_image4.jpg etc. I was wondering if there was a way to have dreamweaver name it, (between the form tags), so when it arrives in my ftp folder, it's already named, and I wouldn't have to code php to change the name.
View Replies !
Assigning Values To Variables
I was attemping to make an array of configuration variables for Smarty when I ran into this little problem. Here's some example code first of all: <?php class Testclass { var $testvar = 'something'; } $test = new Testclass; echo "before foreach: $test->testvar "; # echos 'something' $arr = array('testvar', 'something elseeeee'); foreach ($arr as $key => $value) { $test->$key = $value; # set $test->[variable] to $value } echo "after foreach: $test->testvar "; #echos 'something' Problem. This outputs "something" in both places, while I expected it to echo "something elseeee" after the foreach is done. Setting $test->testvar manually and outputting it workes fine, but breaks in the foreach. To me this seems weird, but might just be how PHP workes. If that's the case, how do I work around this?
View Replies !
Assigning Variables To DB Rows
What I want to achieve (hand have thus far failed to figure out): I have a database table with a serveral coloumns. One column is called 'images' this contains the names of images in a directory on my server (e.g.table row 1 contains the image name 'image23.gif). On the front end of the site I have a html page with many images that can be changed via this database. So for instance it's possible to click on an image and link to a page that allows the image name to be altered in the above database (e.g. 'Pick another image'). Once picked the database row is updated to the new image name. Code:
View Replies !
Assigning Array Key And Values
I am having difficulty with this script. I am trying to assign specific values to the $pid_list array. For example $pid_list[121] = 1 $pid_list[122] = 1 and so forth. But when I try to assign these values it just auto-increments the $pid_list[$k] key value to 0,1,2... and so forth... Here is a snippet of code, i just included the whole while loop, but i think the error is just one of the end lines where i assign the values to the array. Code:
View Replies !
Assigning Lines To An Array Or Db
I have a page where a user will enter information copied from an email into a text box part of a form such as below TransactionId : 21884948 Custref : 6988822309 Product : 359672006270600 SID : TARRIFF : VZ2253MHP I am looking to put each piece of information into a field in a MYSQL table or into an array but am unsure how to break up the information. The problem i'm having is that there is nothing but a new line between one piece of information and the next title and that sometimes there will be blank spaces instead if information.
View Replies !
Assigning Variables To An Array (maybe?)
At the moment I am trying to rewrite a small peice of software so that there's very little text that's html and it's all coming from the database (so that non-coders can edit all of the site.) At the moment I have a table in MySQL (config_options) which has two fields (config_name and config_text) Code:
View Replies !
Convert An IF ELSE Statement To A SWITCH CASE Statement?
How do I convert an IF ELSE statement to a SWITCH CASE statement? The switch case below doesn't work. $textlen = strlen($descr); if($textlen>10 && $textlen<50) { $completeness = 1; $deduct = 1000; } elseif($textlen>50 && $textlen<100) { $completeness = 2; $deduct = 500; } else { $completeness = 0; $deduct = 2000; } switch($textlen) { case >10 && < 50: $completeness = 1; $deduct = 1000; break; case >50 && < 100: $completeness = 2; $deduct = 500; break; default: $completeness = 0; $deduct = 2000; break;
View Replies !
|