Jump to content

Archived

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

johnqpublic24

Help - My PHP update form won't update my MySQL database

Recommended Posts

Thanks for looking. I made this PHP page to update information already in my database:

 

<head> 

<title> View Client </title> 

</head> 

<body> 



<?php 



// Connect to the database server 

$dbcnx = @mysql_connect(\'localhost\'); 

if (!$dbcnx) { 

die( \'<p>Unable to connect to the \' . 

\'database server at this time.</p>\' ); 

} 



// Select the jokes database 

if (! @mysql_select_db(\'online\') ) { 

die( \'<p>Unable to locate the \' . 

\'database at this time.</p>\' ); 

} 



?> 









<?php 



if (isset($_POST[\'submit\'])): 



$dbcnx = mysql_connect(\'localhost\'); 

mysql_select_db(\'online\'); 



$Status = $_POST[\'Status\']; 

$sql = "UPDATE data SET Status=\'$Status\' WHERE SessionID=\'$results\'"; 



if (@mysql_query($sql))  



echo(\'<p>data added</p>\'); 



else

  

echo(\'<p>Error adding new data: \' . 

mysql_error() . \'</p>\'); 







endif; 



?>











<?php 



if (isset($_GET[\'record\'])): 



$record = $_GET["record"]; 





echo("$record"); 





echo("<form action=\'$_SERVER[PHP_SELF]\' method=post>"); 



echo(\'<table border=1 cellpadding=5><TR bgcolor="#e5e5e5"><TD>SessionID</TD><TD>Student Number</TD><TD>First Name</TD><TD>Last Name</TD><TD>Email</TD><TD>Status</TD></TR>\'); 













$result = @mysql_query("SELECT SessionID, StudentNumber, FirstName, LastName, Email, Status FROM data WHERE SessionID=\'$record\'"); 



while ($row = mysql_fetch_array($result) ) { 

$SessionID=$row[\'SessionID\']; 

$StudentNumber=$row[\'StudentNumber\']; 

$FirstName=$row[\'FirstName\']; 

$LastName=$row[\'LastName\']; 

$Email=$row[\'Email\']; 

$Status=$row[\'Status\']; 





echo(\'<TR bgcolor="#e5e5e5"><TD>\' .$SessionID . \'</TD><TD><input type=text name=StudentNumber value=\' .$StudentNumber . \'></TD><TD><input type=text name=FirstName value=\' .$FirstName . \'></TD><TD><input type=text name=LastName value=\' .$LastName . \'></TD><TD><input type=text name=Email value=\' .$Email . \'></TD><TD><input type=text name=Status value=\' .$Status . \'></TD></TR>\'); 





} 



echo(\'<input type=submit name=submit value=submit></form>\'); 









?> 





<?php 

else: // Allow the user to enter a new author 

?> 



<form action="<?=$_SERVER[\'PHP_SELF\']?>" method="get"> 

<p>Look up a client (using session ID #):<br /> 

Email: <input type="text" name="record" size="20" maxlength="255" /><br /> 

<input type="submit" value="lookup"></p> 

</form> 







<?php endif; ?> 



</body> 

</html>

 

And the form seems to work properly, and tells me the data has been added. However, when I check the database, the new information hasn\'t been updated. What am I doing wrong?

Share this post


Link to post
Share on other sites

remove the error supression (@) in front of the myslq_query and see if mysql spits up some kind of an error message.

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.