dsjoes Posted July 21, 2010 Share Posted July 21, 2010 i have 3 php scripts to update the database but i cannot get them to display anything. the first script holds the login details, host and database name. this is the second script called update.php and it just displays a blank page. <? include("dbinfo.inc.php"); mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM News WHERE id='$id'"; $result=mysql_query($query); echo $sql; $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $News=mysql_result($result,$i,"Clan News"); ?> <form action="updated.php"> <input type="hidden" name="ud_id" value="<? echo "$id"; ?>"> News: <input type="text" name="ud_News" value="<? echo "$News"?>"><br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> this is the third script called updated.php i have not tryed this yet because it needs script 2 to work. <? include("dbinfo.inc.php"); mysql_connect($localhost,$username,$password); $query="UPDATE News SET News='$ud_News' WHERE id='$ud_id'"; @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); echo "Record Updated"; mysql_close(); ?> any help please thanks Link to comment https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/ Share on other sites More sharing options...
Pikachu2000 Posted July 21, 2010 Share Posted July 21, 2010 Where is $id defined? In the first script you pasted there, it would have no value, thus it would produce no results. Link to comment https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/#findComment-1089337 Share on other sites More sharing options...
dsjoes Posted July 21, 2010 Author Share Posted July 21, 2010 i had missed that off it is now in the dbinfo.inc.php and it shows the form now with the correct data. the problem now is that it won't update it does not add to the database. Link to comment https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/#findComment-1089353 Share on other sites More sharing options...
Pikachu2000 Posted July 22, 2010 Share Posted July 22, 2010 What is the exact field name you're retrieving from the database? Also, is the id field a primary key or other type of index? Link to comment https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/#findComment-1089360 Share on other sites More sharing options...
dsjoes Posted July 22, 2010 Author Share Posted July 22, 2010 the field i am trying to update is called News and the id is just an int Link to comment https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/#findComment-1089530 Share on other sites More sharing options...
Pikachu2000 Posted July 22, 2010 Share Posted July 22, 2010 You aren't assigning values to the variables before trying to use them. Also, you should replace all the short open <?tags with the full <?php tags in all of your scripts. <?php include("dbinfo.inc.php"); mysql_connect($localhost,$username,$password); $ud_id = (int)$_GET['ud_id']; $ud_news = mysql_real_escape_string($_GET['ud_news']); $query="UPDATE News SET News='$ud_News' WHERE id='$ud_id'"; mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); echo "Record Updated"; mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/#findComment-1089615 Share on other sites More sharing options...
dsjoes Posted July 22, 2010 Author Share Posted July 22, 2010 thankyou it works now Link to comment https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/#findComment-1089692 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.