junk4u Posted September 22, 2011 Share Posted September 22, 2011 Okay, I am new to PHP and Mysql so there are a bunch of mistakes. Besides I used turingturnip scrip to generate the PHP and Mysql files and I will list where I am having problems. I am running everything local using WAMPSERVER to test the script. Here my problem: When running the script to add to the data base everything works fine. The data is stored in the database, but when I request to update the data it calls it the data fine and shows up on the screen properly. When I change the information and tell it to update it, it runs through the process and tells me the data was updated, but when review the data was not updated on show the original data not the updated data. I have attached the script to this post. The update does not work, yet it say is did update. can anyone help with this? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted September 22, 2011 Share Posted September 22, 2011 Most people won't download an attached file. Post them each within a set of . . . tags instead. Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/#findComment-1271812 Share on other sites More sharing options...
raptor30506090 Posted September 22, 2011 Share Posted September 22, 2011 hello i have not downloaded your file but i can give you the right symtex to how it works if thats any help. UPDATE `testdb`.`orders` SET `p_id` = '1' WHERE `orders`.`o_id` =2; Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/#findComment-1271814 Share on other sites More sharing options...
junk4u Posted September 22, 2011 Author Share Posted September 22, 2011 My bad posting the script: Update: <?php /// In order to use this script freely /// you must leave the following copyright /// information in this file: /// Copyright 2006 [url=http://www.turningturnip.co.uk]www.turningturnip.co.uk[/url] /// All rights reserved. include("connect.php"); $id = $_GET['id']; $qP = "SELECT * FROM test WHERE id = '$id' "; $rsP = mysql_query($qP); $row = mysql_fetch_array($rsP); extract($row); $cityperfecture = trim($cityperfecture); $firstname = trim($firstname); mysql_close(); ?> <form id="FormName" action="updated.php" method="post" name="FormName"> <table width="448" border="0" cellspacing="2" cellpadding="0"> <tr><td width="150"><div align="right"> <label for="cityperfecture">cityperfecture</label></div> </td> <td> <input type="cityperfecture" name="cityperfecture" type="text" size="25" value="<?php echo $cityperfecture ?>" maxlength="10"></td> </tr> <tr><td width="150"><div align="right"> <label for="firstname">firstname</label></div> </td> <td> <input id="firstname" name="firstname" type="text" size="25" value="<?php echo $firstname ?>" maxlength="10"></td> </tr> <tr> <td width="150"></td> <td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?=$id?>"></td> </tr> </table> </form> Updated: <a href="index.php">Back to List</a><br> <br> <?php /// In order to use this script freely /// you must leave the following copyright /// information in this file: /// Copyright 2006 [url=http://www.turningturnip.co.uk]www.turningturnip.co.uk[/url] /// All rights reserved. include("connect.php"); $id = $_POST['id']; $cityperfecture = trim($_POST['cityperfecture']); $firstname = trim($_POST['firstname']); $update = "UPDATE test SET cityperfecture = '$cityperfecture', firstname = '$firstname' WHERE id = '$id' "; $rsUpdate = mysql_query($update); if ($rsUpdate) { echo "Update successful."; } mysql_close(); ?> Connect: <?php /// For the following details, /// please contact your server vendor $hostname='LOCALHOST'; //// specify host, i.e. 'localhost' $user='root'; //// specify username $pass=''; //// specify password $dbase='test'; //// specify database name $connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL"); $db = mysql_select_db($dbase , $connection) or die ("Can't select database."); ?> MOD EDIT: tags changed to tags. Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/#findComment-1271819 Share on other sites More sharing options...
raptor30506090 Posted September 22, 2011 Share Posted September 22, 2011 Ok try this at the top to stop error include("connect.php"); if(isset($_GET['id'])){ $id = $_GET['id']; } $qP = "SELECT * FROM test WHERE id= '$id' "; $rsP = mysql_query($qP); $row = mysql_fetch_array($rsP); extract($row); $cityperfecture = trim($cityperfecture); $firstname = trim($firstname); mysql_close(); Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/#findComment-1271826 Share on other sites More sharing options...
junk4u Posted September 22, 2011 Author Share Posted September 22, 2011 Ok try this at the top to stop error include("connect.php"); if(isset($_GET['id'])){ $id = $_GET['id']; } $qP = "SELECT * FROM test WHERE id= '$id' "; $rsP = mysql_query($qP); $row = mysql_fetch_array($rsP); extract($row); $cityperfecture = trim($cityperfecture); $firstname = trim($firstname); mysql_close(); Tried it nothing happen no errors or database update... Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/#findComment-1271859 Share on other sites More sharing options...
mikosiko Posted September 22, 2011 Share Posted September 22, 2011 in you update.php file look for this line: <td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?=$id?>"></td> change the short tags for long one as in the rest of your scripts. and after that... in your updated.php echo $update before execute the mysql_query to validate it Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/#findComment-1271875 Share on other sites More sharing options...
junk4u Posted September 23, 2011 Author Share Posted September 23, 2011 in you update.php file look for this line: <td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?=$id?>"></td> change the short tags for long one as in the rest of your scripts. and after that... in your updated.php echo $update before execute the mysql_query to validate it Wow worked like a charm. I missed that. Thanks for everyone's help. Quote Link to comment https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/#findComment-1271893 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.