Jump to content

Archived

This topic is now archived and is closed to further replies.

anthonydamasco

Setting a variable

Recommended Posts

Alright Using hidden fields I've been pushing this variable through a 5 page form, so when I use "UPDATE" i can run a WHERE = "id" to target the correct row to update,

$orderid

Well this is how I am declaring my VAR

[code=php:0]
else if($_POST['slow']){

//insert the values
$sql = "INSERT INTO joborder VALUES (NULL, '$usedbefore', '$nearestlocation', '$companyname', '$firstname', '$lastname', '$department', '$phone', '$fax', '$email', '$address', '$addresstwo', '$city', '$state', '$country', '$zip', '$positiontype', '$dressreq', '$dresscode',  '$positionclassification', '$positiontitle', '$employeesneeded', '$timeneeded', '$startdate', '$workinghours', '$workAddress', '$workaddresstwo', '$workcity', '$workstate', '$workzip', '$positiondescription', '$skillsrequired', '$educationrequired', '$additionalrequirements', '$checkedby', '$hourlyrate', SYSDATE(), '$reportto')";
mysql_query($sql) or die ( mysql_error() );

if(!$sql){
    echo 'There has been an error creating your order. Please contact the webmaster.';
} else {
$orderid = mysql_insert_id();
include '2rrf.html';
}
mysql_close();


?>
[/code]

then on the 2rrf.html page of have this field

[code]
<input name="orderid" id="<?php echo '$orderid' ?>" value="<?php echo '$orderid' ?>" size="25" checked />
[/code]

its literally posting "$orderid" instead of the var i want

Share this post


Link to post
Share on other sites
try
[code=php:0]
<input name="orderid" id="<?php echo $orderid; ?>" value="<?php echo $orderid; ?>" size="25" checked />
[/code]

Share this post


Link to post
Share on other sites
It is literally posting $orderid because you're telling the script to. You must note that anything within single quotes ('here') will display exactly as it is. PHP will NOT format variables in it. If you want the value of $orderid to show, you must use double quotes ("here").

So this: <input name="orderid" id="<?php echo '$orderid' ?>" value="<?php echo '$orderid' ?>" size="25" checked />
becomes: <input name="orderid" id="<?php echo "$orderid" ?>" value="<?php echo "$orderid"?>" size="25" checked />

If you want an even shorter way to code this into your HTML, you can use [i]<?=$orderid?>[/i]. [i]<?=[/i] signifies that PHP should echo the variable after the equal sign. So, for example, you could use this:
<input name="orderid" id="<?=$orderid?>" value="<?=$orderid?>" size="25" checked />

Let me know if you do not understand or need any more help.

Share this post


Link to post
Share on other sites
Also if Im echo'ing long strings and I have to put a variable somewhere I normaly use brackets... Like
echo "hello my name is corbin and I am {$age} years old";

That would work with out the brackets too, but I just hate going back and finding stupid errors later so I try to prevent them.

Share this post


Link to post
Share on other sites
well now that the vars are going through I'm battling this other problem

I have a hidden field pushing "orderid" on the fallowing page

I think im calling WHERE wrong
[code=php:0]
$orderid = $_POST['orderid'];

$sql = "UPDATE joborder
SET positiontype = '$positiontype', dressreq = '$dressreq', dresscode = '$dresscode',  positionclassification = '$positionclassification', positiontitle = '$positiontitle', employeesneeded = '$employeesneeded', timeneeded = '$timeneeded', startdate = '$startdate', workinghours = '$workinghours', hourlyrate = '$hourlyrate'
WHERE orderid = '$orderid'";
mysql_query($sql) or die ( mysql_error() );
[/code]

its not updating my database, but i knows its connectiong and everything

Share this post


Link to post
Share on other sites
echo out your query and run it in phpmyadmin - it will tell you if there is an error.  Alternatively the query will only 'work' if something is altered; if you try to update a record with the same data that is already there then affected rows will be 0

Share this post


Link to post
Share on other sites
You may want to try this:

[code]$sql = "INSERT INTO joborder (positiontype,dressreq,dresscode,positionclassification,positiontitle,employeesneeded,timeneeded,startdate,workinghours,hourlyrate) values ('$positiontype', '$dressreq', '$dresscode', '$positionclassification', '$positiontitle', '$employeesneeded', '$timeneeded', $startdate', $workinghours', '$hourlyrate')";
mysql_query($sql) or die (mysql_error());[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.