robman2100 Posted March 25, 2010 Share Posted March 25, 2010 I am having some trouble with Updating My database. I can get the form to Pre Populate from the info in the database. I can Also Get my other form to create a new entry. But for some reason i cant get it to update existing information in the database. This is my Pre Populated FORM called set_user.php <?php function get_option($arr_option, $selected){ $return = ''; foreach ($arr_option as $key => $value) { $tmp = ($value==$selected)? ' selected' : ''; $return .= "<option value=\"$key\"$tmp>$value</option>"; } return $return; } $db = new Database(); $id = intval($_GET['id']); $sql = "SELECT * FROM Login WHERE userID = $id LIMIT 1"; $arr_user = $db->get_row($sql); $arr_type = $db->get_enum_values('Login','user_type'); ?> <form method="POST" action="updated.php"> <input type="hidden" name="userID" value="<?php echo $arr_user->userID?>"> <table width="446" border="1" align="center"> <tr> <td colspan="2">USER ID <?php echo $arr_user->userID?> <input type="text" name=".$userID" value="<?php echo $arr_user->userID?>" /> DO NOT CHANGE USER ID</td> </tr> <tr align="left"> <td width="100px">First Name</td> <td width="200px"><input type="text" name=".$FirstName" value="<?php echo $arr_user->FirstName?>"></td> </tr> <tr align="left"> <td width="100px">Last Name</td> <td width="200px"><input type="text" name=".$LastName" value="<?php echo $arr_user->LastName?>"></td> </tr> <tr align="left"> <td width="100px">Password</td> <td width="200px"><input type="text" name=".$Password" value="<?php echo $arr_user->Password?>"></td> </tr> <tr align="left"> <td width="100px">Address</td> <td width="200px"><textarea name=".$Address"><?php echo $arr_user->Address?></textarea></td> </tr> <tr align="left"> <td width="100px">City</td> <td width="200px"><input type="text" name=".$City" value="<?php echo $arr_user->City?>"></td> </tr> <tr align="left"> <td width="100px">State</td> <td width="200px"><input type="text" name=".$State" value="<?php echo $arr_user->State?>"></td> </tr> <tr align="left"> <td width="100px">Zip</td> <td width="200px"><input type="text" name=".$Zip" value="<?php echo $arr_user->Zip?>"></td> </tr> <tr align="left"> <td width="100px">Home Phone</td> <td width="200px"><input type="text" name=".$HomePhone" value="<?php echo $arr_user->HomePhone?>"></td> </tr> <tr align="left"> <td width="100px">Cell Phone</td> <td width="200px"><input type="text" name=".$CellPhone" value="<?php echo $arr_user->CellPhone?>"></td> </tr> <tr align="left"> <td width="100px">Work Phone</td> <td width="200px"><input type="text" name=".$WorkPhone" value="<?php echo $arr_user->WorkPhone?>"></td> </tr> <tr align="left"> <td width="100px">Email</td> <td width="200px"><input type="text" name=".$Email" value="<?php echo $arr_user->Email?>"></td> </tr> <tr align="left"> <td width="100px">Contractor</td> <td width="200px"><input type="text" name=".$Contractor" value="<?php echo $arr_user->Contractor?>"></td> </tr> <tr align="left"> <td width="100px">Licence</td> <td width="200px"><input type="text" name=".$License" value="<?php echo $arr_user->License?>"></td> <tr align="right"><td height="57" colspan="2"><input type="submit" value="UPDATE"></td></tr> </table> </form> This is my update form called Updated.php <?php include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); $FirstName=$_REQUEST['FirstName']; $LastName=$_REQUEST['LastName']; $Email=$_REQUEST['Email']; $WorkPhone=$_REQUEST['WorkPhone']; $Address=$_REQUEST['Address']; $City=$_REQUEST['City']; $State=$_REQUEST['State']; $Zip=$_REQUEST['Zip']; $HomePhone=$_REQUEST['HomePhone']; $CellPhone=$_REQUEST['CellPhone']; $WorkPhone=$_REQUEST['WorkPhone']; $Contractor1=$_REQUEST['Contractor']; $License=$_REQUEST['License']; $query="UPDATE Login SET FirstName='.$FirstName', LastName='.$LastName', HomePhone='.$HomePhone', CellPhone='.$CellPhone', WorkPhone='.$WorkPhone', Email='.$Email', Address='.$Address', City='.$City', State='.$State', Zip='.$Zip', Password='.$Password', Contractor='.$Contractor', License='.$License' WHERE userID='.$userID'"; @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); echo "Record Updated"; mysql_close(); ?> It shows Record updated but then when i go back to look at it. Nothing Is updated it is all the same. I would apppreciate some help. Link to comment https://forums.phpfreaks.com/topic/196484-mysql-update-from-pre-populated-forms/ Share on other sites More sharing options...
o3d Posted March 25, 2010 Share Posted March 25, 2010 if (!mysql_query($query)) die('could not update row'); Link to comment https://forums.phpfreaks.com/topic/196484-mysql-update-from-pre-populated-forms/#findComment-1031919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.