Jump to content


Photo

Setting a variable


  • Please log in to reply
9 replies to this topic

#1 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 18 August 2006 - 08:23 PM

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

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();

}  
?>

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

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

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

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 18 August 2006 - 08:32 PM

remove the single quotes

follow me on twitter @PHPsycho

#3 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 18 August 2006 - 08:32 PM

try
<input name="orderid" id="<?php echo $orderid; ?>" value="<?php echo $orderid; ?>" size="25" checked />

Why doesn't anyone ever say hi, hey, or whad up world?

#4 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 August 2006 - 08:34 PM

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 <?=$orderid?>. <?= 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.

#5 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 18 August 2006 - 08:34 PM

thanks fixed it! huray! ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D

#6 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 18 August 2006 - 08:37 PM

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.
Why doesn't anyone ever say hi, hey, or whad up world?

#7 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 18 August 2006 - 08:42 PM

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
$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() );

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

#8 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 18 August 2006 - 08:54 PM

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
follow me on twitter @PHPsycho

#9 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 18 August 2006 - 08:56 PM

Does the query die or does it just not do anything?
Why doesn't anyone ever say hi, hey, or whad up world?

#10 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 August 2006 - 09:04 PM

You may want to try this:

$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());





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users