set update help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
speedamp
Forum Commoner
Posts: 45
Joined: Tue Apr 29, 2003 3:59 pm

set update help

Post by speedamp »

hello everybody,

i have an update script that will not pass the proper variable for me. What i want to do is have a cusotmer update thei minutes/seconds depending on their variable $email (passed from the login screen).

Right now the output i get is not including the $email variable. Am I using the Update Set Where syntax properly?

-----------------------------------------------------------------------

<?php


$db = mysql_connect("localhost", "....", ".....");
mysql_select_db("......_com_prix",$db);
if($submit){


$sql = "UPDATE entrants SET minutes=$minutes,seconds=$seconds WHERE email=$email";
$result = mysql_query($sql);
header ("Location: http://www......com/change/edit_verify.php?email=".$email. "");

} else{

$query="SELECT * FROM entrants where email='$email' ";
$result=mysql_query($query);
$myrow=mysql_fetch_array($result);
?>

<form method="post" action="<?php echo $PHP_SELF?>">
First:&nbsp;&nbsp;<?php echo $myrow["first_name"]?>&nbsp;<?php echo $myrow["last_name"]?><br>
Email:&nbsp;&nbsp;
<?php echo $email ?><br>

Minutes:&nbsp;&nbsp;<select name="minutes"><br>
<OPTION VALUE="<?php echo $myrow["minutes"]?>"><?php echo $myrow["minutes"]?>
<OPTION VALUE="00">00
<OPTION VALUE="01">01
<OPTION VALUE="02">02
<OPTION VALUE="59">59
</SELECT>

&nbsp;&nbsp;&nbspSeconds:&nbsp;&nbsp;<select name="seconds"><br>
<OPTION VALUE="<?php echo $myrow["seconds"]?>"><?php echo $myrow["seconds"]?>
<OPTION VALUE="00">00
<OPTION VALUE="01">01
<OPTION VALUE="05">05
<OPTION VALUE="58">58
<OPTION VALUE="59">59</SELECT><br>

<input type="Submit" name="submit" value="Update Information">
</form>
<?php
}
?>
-------------------------------------------------

any help would be great?

-Michael
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

You need to wrap the email address with single quotes.

This is what you have:
$sql = "UPDATE entrants SET minutes=$minutes,seconds=$seconds WHERE email=$email";

Change it to:
$sql = "UPDATE entrants SET minutes=$minutes,seconds=$seconds WHERE email='$email'";

Or, even better:
$sql = "UPDATE entrants SET minutes = ".$minutes.", seconds = ".$seconds." WHERE email = '".$email."'";
speedamp
Forum Commoner
Posts: 45
Joined: Tue Apr 29, 2003 3:59 pm

Post by speedamp »

none of these methods actually pass the $email variable. The minutes and seconds are passed fine (using echo $sql), but the email variable is empty.

any suggestions?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

maybe i am confused

but your wanting to update the emal, seconds and minutes field correct?

Code: Select all

$sql = "UPDATE entrants SET minutes=$minutes,seconds=$seconds WHERE email=$email";
Look at that, of course its not going to pass the email field, the only thing email wise in that line is only telling where to set the minutes n seconds.
speedamp
Forum Commoner
Posts: 45
Joined: Tue Apr 29, 2003 3:59 pm

Post by speedamp »

sorry for the confusion, but the scope of this is that i want the user to be able to update their time (minutes/seconds) depending on their login email. I do not want their email changed or sent to the database.

When i display the $sql command i get this:
UPDATE entrants SET minutes=12,seconds=06 WHERE email=


so, the concept is working, but HOW do i get the email field to populate properly so it updates the database. i would rather not use sessions, but if it's my only choice, could somebody help me with them?

the email field is being passed to this page properly through the header, however once it enters the SQL command (and further into the header) it is lost.


I have tried formatting with '$email', $email, ".$email."

help!

-mike
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Oh, I see what the other guys were saying.

You aren't passing $email from the form page. You are just showing it on the screen. At the very least, you have to create a hidden form field called "email" that contains the $email address.
Post Reply