ipodman Posted April 12, 2009 Share Posted April 12, 2009 Hey guys, Well I have been trying to sort this for the past hour and I have been searching for the solution but if I missed it, it because I am tired. I am trying to update a record in mysql but when I click submit and it goes to update.php it states it has been updated when it has now. here is the form that calls that items from the database <? if (isset($_GET['pro_id'])) $pro_id = $_GET['pro_id']; $db= mysql_connect("localhost", "root"); mysql_select_db("site",$db); $sql = "SELECT pro_id, name, sale_price, cat_id, description, stock_level FROM stock WHERE pro_id = $pro_id"; $result = mysql_query($sql) or die(mysql_error()); $onlyRecord = mysql_fetch_array($result); $name = $onlyRecord['name']; $sale = $onlyRecord['sale_price']; $cat = $onlyRecord['cat_id']; $id = $onlyRecord['description']; $level = $onlyRecord['stock_level']; ?> <html> <head><title>Edit Record</title></head> <body> <form action="update.php" method="POST"> <input type="hidden" value="<? echo $pro_id; ?>"> <table> <tr><td>ID</td><td><input type="text" name="sitename" value="<? echo $pro_id; ?>"></td></tr> <tr><td>Name</td><td><input type="text" name="sitename" value="<? echo $name; ?>"></td></tr> <tr><td>Sale Price</td><td><input type="text" name="sitename" value="<? echo $sale; ?>"></td></tr> <tr><td>Category ID</td><td><input type="text" name="sitename" value="<? echo $cat; ?>"></td></tr> <tr><td>description</td><td><input type="text" name="sitename" value="<? echo $id; ?>"></td></tr> <tr><td>Stock Level</td><td><input type="text" name="sitename" value="<? echo $level; ?>"></td></tr> </table> <br /> <input type="submit" value="Update"> </form> <a href="viewedit.php" target="_self">Go back without saving any changes</a> </body> </html> And now the update.php which updates the database <?php $db= mysql_connect("localhost", "root", ""); mysql_select_db("site"); if (isset($_GET['pro_id'])) $pro_id = $_GET['pro_id']; $name = $_GET['name']; $sale = $_GET['sale']; $cat = $_GET['cat']; $id = $_GET['id']; $level = $_GET['level']; $sql= ("UPDATE stock SET name='$name', sale_price='$sale', description='$id', stock_level='$level' WHERE pro_id='$pro_id'"); mysql_query($sql) or die(mysql_error()); echo "Record submitted successfully."; mysql_close(); ?> <meta http-equiv="Refresh" content="1; url=viewedit.php"><title>Remove Item</title> Any help would be good, thanks Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/ Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 What error are you getting? And what, does it just not update it? Does it wipe the record? Little more info would be cool... Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807808 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 Hey, It states that the update has happened but does not update, no changes are made to the record Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807813 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 mysql_select_db("site",$db); What's going on with that? I'm pretty sure mysql_select_db() only accepts one database. Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807815 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 mysql_select_db("site",$db); What's going on with that? I'm pretty sure mysql_select_db() only accepts one database. I have just edited my first post to show new changes to the code [2nd code] but still have the same error of it saying it has been updated when its not. Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807816 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 <?php $db = mysql_connect("localhost", "root", ""); mysql_select_db("site,$db"); if (isset($_GET['pro_id'])) $pro_id = $_GET['pro_id']; $name = $_GET['name']; $sale = $_GET['sale']; $cat = $_GET['cat']; $id = $_GET['id']; $level = $_GET['level']; $sql= ("UPDATE `stock` SET name = '$name', sale_price = '$sale', description = '$id', stock_level = '$level' WHERE pro_id = '$pro_id'") or die(mysql_error()); mysql_query($sql) or die(mysql_error()); echo "Record submitted successfully."; mysql_close(); ?> <meta http-equiv="Refresh" content="1; url=viewedit.php"><title>Remove Item</title> Try that ^^ and tell me what you get ? Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807829 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 You should check for a mysql_error() after everything though - connections, selecting databases. I don't know how many times I've said this over the last couple of days... Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807830 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 <?php $db = mysql_connect("localhost", "root", ""); mysql_select_db("site,$db"); if (isset($_GET['pro_id'])) $pro_id = $_GET['pro_id']; $name = $_GET['name']; $sale = $_GET['sale']; $cat = $_GET['cat']; $id = $_GET['id']; $level = $_GET['level']; $sql= ("UPDATE `stock` SET name = '$name', sale_price = '$sale', description = '$id', stock_level = '$level' WHERE pro_id = '$pro_id'") or die(mysql_error()); mysql_query($sql) or die(mysql_error()); echo "Record submitted successfully."; mysql_close(); ?> <meta http-equiv="Refresh" content="1; url=viewedit.php"><title>Remove Item</title> Try that ^^ and tell me what you get ? Using the code you said i get the error of no database so i change the database code to:- $db = mysql_connect("localhost", "root", ""); mysql_select_db("site"); then i go to change a record an dget told it has been changed when it still has not Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807833 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 ok its the top code you posted, let me have a butchers and ill see what i can do. Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807834 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 just a question, on your Edit Record form does it actually put the mysql records in the value of the text fields ? Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807835 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Jesus christ... Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807836 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 just a question, on your Edit Record form does it actually put the mysql records in the value of the text fields ? Yes, it shows the correct data taken from the database Also jackpf I added th emysql error code and nothing came up Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807838 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 just a question, on your Edit Record form does it actually put the mysql records in the value of the text fields ? Yes, it shows the correct data taken from the database Also jackpf I added th emysql error code and nothing came up ok no problem try this form for your Edit Record page <?php if (isset($_GET['pro_id'])) $pro_id = mysql_real_escape_string($_GET['pro_id']); $db= mysql_connect("localhost", "root"); mysql_select_db("site"); $sql = "SELECT `pro_id`, `name`, `sale_price`, `cat_id`, `description`, `stock_level` FROM stock WHERE pro_id = '$pro_id'" or die(mysql_error()); $result = mysql_query($sql) or die(mysql_error()); $onlyRecord = mysql_fetch_array($result); $name = $onlyRecord['name']; $sale = $onlyRecord['sale_price']; $cat = $onlyRecord['cat_id']; $id = $onlyRecord['description']; $level = $onlyRecord['stock_level']; ?> <html> <head><title>Edit Record</title></head> <body> <form action="update.php" method="POST"> <input type="hidden" value="<?php print $pro_id; ?>"> <table> <tr><td>ID</td><td><input type="text" name="sitename" value="<?php print $pro_id; ?>"></td></tr> <tr><td>Name</td><td><input type="text" name="sitename" value="<?php print $name; ?>"></td></tr> <tr><td>Sale Price</td><td><input type="text" name="sitename" value="<?php print $sale; ?>"></td></tr> <tr><td>Category ID</td><td><input type="text" name="sitename" value="<?php print $cat; ?>"></td></tr> <tr><td>description</td><td><input type="text" name="sitename" value="<?php print $id; ?>"></td></tr> <tr><td>Stock Level</td><td><input type="text" name="sitename" value="<?php print $level; ?>"></td></tr> </table> <br /> <input type="submit" name="submit" value="Update"> </form> <a href="viewedit.php" target="_self">Go back without saving any changes</a> </body> </html> Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807839 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 $db= mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("site") or die(mysql_error()); That gave no errors? You obviously have not done as I told you. Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807841 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 $db= mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("site") or die(mysql_error()); That gave no errors? You obviously have not done as I told you. Like i said, No errors which using your code, but I also added the password to ("localhost, "root", "") to ensure access to the database. Also tried the script just suggested above. Still the same problem Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807843 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 $db= mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("site") or die(mysql_error()); That gave no errors? You obviously have not done as I told you. Like i said, No errors which using your code, but I also added the password to ("localhost, "root", "") to ensure access to the database here mate instead of using connection on each page just save this and include it in each page. <?php $connection = mysql_connect("DB_SERVER","DB_USER","DB_PASS") or die ("Couldn't connect to server."); $db = mysql_select_db("DB_NAME", $connection) or die("Couldn't select database."); if(!get_magic_quotes_gpc()) { $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } else { $_GET = array_map('stripslashes', $_GET); $_POST = array_map('stripslashes', $_POST); $_COOKIE = array_map('stripslashes', $_COOKIE); $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } ?> Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807847 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 $db= mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("site") or die(mysql_error()); That gave no errors? You obviously have not done as I told you. Like i said, No errors which using your code, but I also added the password to ("localhost, "root", "") to ensure access to the database here mate instead of using connection on each page just save this and include it in each page. <?php $connection = mysql_connect("DB_SERVER","DB_USER","DB_PASS") or die ("Couldn't connect to server."); $db = mysql_select_db("DB_NAME", $connection) or die("Couldn't select database."); if(!get_magic_quotes_gpc()) { $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } else { $_GET = array_map('stripslashes', $_GET); $_POST = array_map('stripslashes', $_POST); $_COOKIE = array_map('stripslashes', $_COOKIE); $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } ?> Hey, Thats the way I was going to do it, to call it from config file. But still the problem remains, I have tried doing it with another table and it still doe snot change even when it says it has. And no errors are showing Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807852 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 $db= mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("site") or die(mysql_error()); That gave no errors? You obviously have not done as I told you. Like i said, No errors which using your code, but I also added the password to ("localhost, "root", "") to ensure access to the database here mate instead of using connection on each page just save this and include it in each page. <?php $connection = mysql_connect("DB_SERVER","DB_USER","DB_PASS") or die ("Couldn't connect to server."); $db = mysql_select_db("DB_NAME", $connection) or die("Couldn't select database."); if(!get_magic_quotes_gpc()) { $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } else { $_GET = array_map('stripslashes', $_GET); $_POST = array_map('stripslashes', $_POST); $_COOKIE = array_map('stripslashes', $_COOKIE); $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } ?> Hey, Thats the way I was going to do it, to call it from config file. But still the problem remains, I have tried doing it with another table and it still doe snot change even when it says it has. And no errors are showing ok put this at the top of your page... ini_set('display_errors', 1); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807853 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 $db= mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("site") or die(mysql_error()); That gave no errors? You obviously have not done as I told you. Like i said, No errors which using your code, but I also added the password to ("localhost, "root", "") to ensure access to the database here mate instead of using connection on each page just save this and include it in each page. <?php $connection = mysql_connect("DB_SERVER","DB_USER","DB_PASS") or die ("Couldn't connect to server."); $db = mysql_select_db("DB_NAME", $connection) or die("Couldn't select database."); if(!get_magic_quotes_gpc()) { $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } else { $_GET = array_map('stripslashes', $_GET); $_POST = array_map('stripslashes', $_POST); $_COOKIE = array_map('stripslashes', $_COOKIE); $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } ?> Hey, Thats the way I was going to do it, to call it from config file. But still the problem remains, I have tried doing it with another table and it still doe snot change even when it says it has. And no errors are showing ok put this at the top of your page... ini_set('display_errors', 1); error_reporting(E_ALL); Hey, Now I get errors:- on update.php Notice: Undefined index: name in C:\xampplite\htdocs\shop\admin\update.php on line 11 Notice: Undefined index: sale in C:\xampplite\htdocs\shop\admin\update.php on line 12 Notice: Undefined index: cat in C:\xampplite\htdocs\shop\admin\update.php on line 13 But no errors on edit.php Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807854 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 ok this means they have no value, can i just ask are the $_GET 's getting the info from your edit.php ? Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807861 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 replace all the $_GET 's you have on update.php to. . . if (isset($_POST['pro_id'])) $pro_id = mysql_real_escape_string($_POST['pro_id']); $name = mysql_real_escape_string($_POST['name']); $sale = mysql_real_escape_string($_POST['sale']); $cat = mysql_real_escape_string($_POST['cat']); $id = mysql_real_escape_string($_POST['id']); $level = mysql_real_escape_string($_POST['level']); Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807863 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 replace all the $_GET 's you have on update.php to. . . if (isset($_POST['pro_id'])) $pro_id = mysql_real_escape_string($_POST['pro_id']); $name = mysql_real_escape_string($_POST['name']); $sale = mysql_real_escape_string($_POST['sale']); $cat = mysql_real_escape_string($_POST['cat']); $id = mysql_real_escape_string($_POST['id']); $level = mysql_real_escape_string($_POST['level']); With the code you have given above the problem is solved! Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807866 Share on other sites More sharing options...
jamesxg1 Posted April 12, 2009 Share Posted April 12, 2009 replace all the $_GET 's you have on update.php to. . . if (isset($_POST['pro_id'])) $pro_id = mysql_real_escape_string($_POST['pro_id']); $name = mysql_real_escape_string($_POST['name']); $sale = mysql_real_escape_string($_POST['sale']); $cat = mysql_real_escape_string($_POST['cat']); $id = mysql_real_escape_string($_POST['id']); $level = mysql_real_escape_string($_POST['level']); With the code you have given above the problem is solved! so its done yes ? Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807867 Share on other sites More sharing options...
ipodman Posted April 12, 2009 Author Share Posted April 12, 2009 replace all the $_GET 's you have on update.php to. . . if (isset($_POST['pro_id'])) $pro_id = mysql_real_escape_string($_POST['pro_id']); $name = mysql_real_escape_string($_POST['name']); $sale = mysql_real_escape_string($_POST['sale']); $cat = mysql_real_escape_string($_POST['cat']); $id = mysql_real_escape_string($_POST['id']); $level = mysql_real_escape_string($_POST['level']); With the code you have given above the problem is solved! so its done yes ? Yes done, Thank you very much!!!! Link to comment https://forums.phpfreaks.com/topic/153722-updating-a-mysql-record-error/#findComment-807868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.