r2ks Posted June 15, 2009 Share Posted June 15, 2009 I am trying to do a Simple PHP mysql Update and it is Not working nothing gets updated in the Data base. <?php include ('conn.php'); error_reporting(0); $id = $_GET['id']; $result = mysql_query("SELECT * FROM users WHERE id=$id",$con); $myrow = mysql_fetch_array($result); ?> <h4 align="left" class="style1"> Update Participant </h4> <form action="_updateparticipant.php" method="post" id="_editform" > <table> <tr> <td>Create Username:</td> <td><input type="username" value="<?php echo $myrow['username'] ?>"input name ="username" / ></td> </tr> <tr> <td>Password: <font size=-1><br> (Minimum 4 letters)</font></td> <td><input type="password" value="<?php echo $myrow['password'] ?>" input name="password" /></td> </tr> <tr> <td>Name:</td> <td><input type="name" value="<?php echo $myrow['name'] ?>"input name="name" /> </td> </tr> <tr> <td>Street</td> <td><input type="street" value="<?php echo $myrow['street'] ?>"input name="street" /></td> </tr> <tr> <td valign="top">City:</td> <td><input type="city" value="<?php echo $myrow['city'] ?>"input name="city" /></td> </tr> <tr> <td valign="top">State:</td> <td><input type="state" value="<?php echo $myrow['state'] ?>"input name="state" /></td> </tr> <tr> <td valign="top">Zip:</td> <td><input type="zip"value="<?php echo $myrow['zip'] ?>"input name="zip" /></td> </tr> <tr> <td valign="top">Contact Phone: </td> <td><input name="phone" value="<?php echo $myrow['phone'] ?>"type="phone" /></td> </tr> <tr> <td valign="top">Email:</td> <td><input type="email"value="<?php echo $myrow['email'] ?>"input name="email" /> </td> </tr> <tr> <td valign="top">Additional Information:</td> <td><textarea name="info" value="<?php echo $myrow['info'] ?>"rows=6 cols=25></textarea></td> </tr> <tr> <td>Administrative Privileges</td> <td><input type="radio" name="admin" id = "admin"value=<?php echo $myrow['admin'] ?>NO<br> <input type="radio" name="admin" id = "admin" value=<?php echo $myrow['admin'] ?>YES<br> </td> </tr> <tr> <td colspan=2 align=center> <input name="id" type="hidden" value="<?php $myrow['id'] ?>" /> <input type="submit" name="Update Participant" value="Update Participant" /> Return to <a href="adminparticipants.php">Admin Area </a></td> </tr> </table> This is my Form <?php error_reporting(E_ALL); ini_set('display_errors',1); session_start(); include ('conn.php'); mysql_select_db("realityt_pledges", $con); //Replace with your MySQL DB Name $id=$_POST['id']; $username= $_POST['username']; $password= md5 ($_POST ['password']); $name= $_POST['name']; $street= $_POST['street']; $city= $_POST['city']; $state= $_POST['state']; $zip= $_POST['zip']; $phone= $_POST['phone']; $email = $_POST ['email']; $info= $_POST ['info']; $admin = $_POST ['admin']; $_rs ="UPDATE users SET users.username ='$username', users.password ='$password', users.name ='$name', users.street ='$street', users.city ='$city', users.state ='$state', users.zip ='$zip', users.phone ='$phone', users.email ='$email', users.info ='$info', users.admin = '$admin' WHERE users.id = '$id'"; $query=mysql_query($_rs); echo "<p>record has been updated click </p> <a href=\"adminparticipants.php\"> here </a> to continue"; //header("Location:index.php"); mysql_close(); ?> and this is my PHP Script Please Help Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/ Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 Echo out '$_rs' to ensure the correct values, if any, are being passed to the '_updateparticipant.php' script. Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-856665 Share on other sites More sharing options...
PFMaBiSmAd Posted June 15, 2009 Share Posted June 15, 2009 When you did a "view source" of your form in your browser, did you happen to notice that the value="..." for your hidden id field was empty? There is no echo statement in the following - <input name="id" type="hidden" value="<?php $myrow['id'] ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-856669 Share on other sites More sharing options...
r2ks Posted June 16, 2009 Author Share Posted June 16, 2009 Maq: I echo $_rs and Got These Values UPDATE users SET users.username ='guest', users.password ='8c2c38e0642a49f8fca80c49437b2e19', users.name ='guest', users.street ='', users.city ='', users.state ='ME', users.zip ='0', users.phone ='0', users.email ='guest@et.co', users.info ='', users.admin = '', WHERE users.id = '31' Which are correct Values. PFMaBiSmAd: <input name="id" type="hidden" value="<?php echo $myrow['id'] ?>" /> Thanks over looked that i did echo that. Still no luck will not update I can Create Record and Delete Record can not update ??? Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-856692 Share on other sites More sharing options...
Maq Posted June 16, 2009 Share Posted June 16, 2009 So you've checked user id in the database to make sure it's not being updated? (SELECT * from users WHERE id = 31) If not, how do you know the table isn't being updated? Doesn't make any sense. I guess I'm missing something. If the query was invalid then the error reporting would display an error for you mysql_query call. I guess you can add the or die clause to see if your query is failing: (make sure to take it out when we're done) $query=mysql_query($_rs) or die(mysql_query()); By the way, if you are using a single table you don't need to have the format 'table'.'field', you can just do 'field'. Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-856701 Share on other sites More sharing options...
r2ks Posted June 16, 2009 Author Share Posted June 16, 2009 $query=mysql_query($_rs) or die(mysql_query()); You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 14 $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; 13 ,14, 15 Hmmm i am very confused Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-856794 Share on other sites More sharing options...
PFMaBiSmAd Posted June 16, 2009 Share Posted June 16, 2009 The line number in the SQL error is the line of the SQL query, not the line in the php code. In the post where you echoed $_rs, there is an extra comma before the WHERE. However, the code you posted for that query does not contain the extra comma. You need to stop randomly changing your code. That just wastes everyone's time and it makes the symptoms you are reporting not match what the code is. Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-856804 Share on other sites More sharing options...
r2ks Posted June 16, 2009 Author Share Posted June 16, 2009 First I am really Sorry i am working on 2 areas Same issues One was what i Posted that issue was in a area called Participants Same Database Different Table. This is working Now ... I this it had to do with some radio buttons on the Form.. Any ways from this Point Forward i will be Careful of what i Post and when i change info The Area in Question Not updating Called Sponsors This is the Form <?php session_start(); include ('conn.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><link rel="stylesheet" type="text/css" href="fw-2-1-col/main.css" /> <head><link rel="stylesheet" media="all" type="text/css" href="cssmenus/Menu/menu_style.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Pledge Main </title> </head> <body> <div id="wrapper"> <div id="header"> <div align="right"> <P>Welcome <? echo $_SESSION["valid_user"]?> <?php // Display logout link echo "<p><B><a href=\"logout.php\">Click here to logout!</a></b></p>"; ?> </P> </div> </div> <div id="content"><div class="menu bubplastic horizontal lime"> <ul> <li><span class="highlight"><a href="pl_user.php" target="_self"><span class="menu_ar"></span></a></span></li> <li class="menu_r"><span class="menu_r"><a href="http://www.cssmenumaker.com"><span class="menu_ar"></span></a></span></li> </ul> <br class="clearit" /> </div> <p> </p> <div id="example"> <?php error_reporting(0); $id = $_GET['id']; $result = mysql_query("SELECT * FROM pl_users WHERE id=$id",$con); $myrow = mysql_fetch_array($result); ?> <form action="_updatesponser.php" method="post" id="_editform" > <table width="75%" border="1" align="center"> <tr> <td width="27%">EDIT RECORD </td> </tr> <tr> <td width="27%">FIRSTNAME</td> <td width="73%"><input type="text" value="<?php echo $myrow['firstname'] ?>" name="firstname" /></td> </tr> <tr> <td>LASTNAME</td> <td><input type="text" value="<?php echo $myrow['lastname'] ?>" name="lastname" /></td> </tr> <tr> <td>STREET</td> <td><input type="text" value="<?php echo $myrow['street'] ?>" name="street" /></td> </tr> <tr> <td>CITY </td> <td><input type="text" value="<?php echo $myrow['city'] ?>" name ="city" /></td> </tr> <tr> <td>STATE</td> <td><input type="text" value="<?php echo $myrow['state'] ?>" name="state" /></td> </tr> <tr> <td>ZIP CODE </td> <td><input type="text"value="<?php echo $myrow['zip'] ?>" name ="zip" /> </td> </tr> <tr> <td>HOME PHONE </td> <td><input type="text" value="<?php echo $myrow['hphone'] ?>" name ="hphone" /></td> </tr> <tr> <td>CELL PHONE </td> <td><input type="text" value="<?php echo $myrow['cphone'] ?>" name ="cphone" /></td> </tr> <tr> <td>E-MAIL</td> <td><input type="text" value="<?php echo $myrow['email'] ?>" name ="email" /></td> </tr> <tr> <td>PLEDGE DATE </td> <td><input type="text" value="<?php echo $myrow['pldate'] ?>" name ="pldate" /></td> </tr> <tr> <td>PLEDGE AMOUNT </td> <td><input type="text" value="<?php echo $myrow['plamount'] ?>" name ="plamount" /></td> </tr> <tr> <td>Paid</td> <td><input type="text" value="<?php echo $myrow['paid'] ?>" name ="paid" /> </td></tr> <tr> <td> </td> <td><input name="id" type="hidden" value="<?php echo $myrow['id'] ?>" /> <input type="submit" name="Submit" value="Update Sponser " /> CLICK<a href="adminsponser.php"> HERE </a>TO GO BACK</td> </tr> </table> </form> </div> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> </div> <div id="footer">Content for id "footer" Goes Here</div> <div id="footer1">Designed by Reality 2000 Software.com</div> </div> </body> </html> And here is the Script <?PHP error_reporting(E_ALL); ini_set('display_errors',1); session_start(); include ("conn.php"); mysql_select_db("realityt_pledges", $con); //Replace with your MySQL DB Name $id = $_POST['id']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $street = $_POST['street']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $hphone = $_POST['hphone']; $cphone = $_POST['cphone']; $email = $_POST['email']; $pldate = $_POST['pldate']; $plamount = $_POST['plamount']; $paid = $_POST['paid']; $_rs ="UPDATE pl_users SET firstname ='$firstname', lastname ='$lastname', street ='$street', city ='$city', state ='$state', zip ='$zip', hphone ='$hphone', cphone ='$cphone', pldate ='$pldate', plamount ='$plamount', email ='$email', paid ='$paid' WHERE id ='$id' LIMIT 1,"; $query= mysql_query($_rs) or die(mysql_error()); //$result = mysql_query($_rs) //or die(mysql_query()); //$query=mysql_query($_rs); echo "$_rs"; echo "<p>record has been updated click </p> <a href=\"adminsponser.php\"> here </a> to continue"; //header("Location:index.php"); mysql_close(); ?> I still can not see why this one would not be Updateing This is the Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 14 Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-857155 Share on other sites More sharing options...
r2ks Posted June 16, 2009 Author Share Posted June 16, 2009 OK i have No Idea all i did was this Went from email ='$email', paid ='$paid' WHERE id ='$id' LIMIT 1,"; To this email ='$email', paid ='$paid' WHERE id = '$id' LIMIT 1"; Removed the Comma after the 1 OK I need to understand better Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-857334 Share on other sites More sharing options...
Maq Posted June 16, 2009 Share Posted June 16, 2009 That's the third time your query has changed... The reason is because you don't need that comma there, that's it. Quote Link to comment https://forums.phpfreaks.com/topic/162306-solved-php-mysql-update/#findComment-857340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.