dsjoes Posted February 3, 2011 Share Posted February 3, 2011 i have got the update script below it works but what i want to know is could i change the id text box into a drop down that lists all of the ids in the database and when one is selected it shows the other information in the other fields next to it so it is easier to edit the required field. update.php <?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $result=mysql_query("SELECT * FROM Testimonials where id") or die("ERROR:".mysql_error()); $row=mysql_fetch_array($result,MYSQL_ASSOC); print '<form method="POST" action="updated.php">'; print 'id:<input name="id" value="'.$row['id'].'">'; print '<br />'; print 'Name:<input type="text" name="Name" value="'.$row['Name'].'" />'; print '<br />'; print 'Message:<input type="text" name="Message" value="'.$row['Message'].'" />'; print '<br />'; print 'Download:<input type="text" name="Download" value="'.$row['Download'].'" />'; print '<br />'; print '<input type="submit" name="submit" value="Update">'; mysql_close($link); ?> updated.php <META HTTP-EQUIV="refresh" content="0;URL=index.php"><?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $id=$_POST['id']; $Name=$_POST['Name']; $Message=$_POST['Message']; $Download=$_POST['Download']; mysql_query("UPDATE Testimonials SET Name='$Name', Message='$Message', Download='$Download' where id='$id'") or die("ERROR:".mysql_error()); echo "thanks"; mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/226520-php-update-sql/ Share on other sites More sharing options...
AndyPSV Posted February 3, 2011 Share Posted February 3, 2011 Yes, it is possible, but better is to do it with URL, eg: http://youraddress.com/10 <-- which is id OR you must take all id's from db, by $q = mysql_query('SELECT id FROM table'); if(mysql_num_rows($q) == 0) die('no rows'); while($_f = mysql_fetch_row($q) $f[] = $_f; var_export($f); Link to comment https://forums.phpfreaks.com/topic/226520-php-update-sql/#findComment-1169213 Share on other sites More sharing options...
dsjoes Posted February 3, 2011 Author Share Posted February 3, 2011 thanks i will have a go now Link to comment https://forums.phpfreaks.com/topic/226520-php-update-sql/#findComment-1169450 Share on other sites More sharing options...
dsjoes Posted February 3, 2011 Author Share Posted February 3, 2011 i have done it the example.com/update.php?Update=7 way because i have used this method before but when the update page opens it shows the correct id but the other fields are wrong they are showing the first ids results. update.php <?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $result=mysql_query("SELECT * FROM Testimonials where id") or die("ERROR:".mysql_error()); $row=mysql_fetch_array($result,MYSQL_ASSOC); $file = $_GET["Update"]; print '<form method="POST" action="updated.php">'; print 'id:<input name="id" value="'.$file.'">'; print '<br />'; print 'Name:<input type="text" name="Name" value="'.$row['Name'].'" />'; print '<br />'; print 'Message:<input type="text" name="Message" value="'.$row['Message'].'" />'; print '<br />'; print 'Download:<input type="text" name="Download" value="'.$row['Download'].'" />'; print '<br />'; print '<input type="submit" name="submit" value="Update">'; mysql_close($link); ?> updated.php <META HTTP-EQUIV="refresh" content="0;URL=index.php"><?php include("dbinfo1.inc.php"); $link=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die("unable to connect"); $id=$_POST['id']; $Name=$_POST['Name']; $Message=$_POST['Message']; $Download=$_POST['Download']; mysql_query("UPDATE Testimonials SET Name='$Name', Message='$Message', Download='$Download' where id='$id'") or die("ERROR:".mysql_error()); echo "thanks"; mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/226520-php-update-sql/#findComment-1169597 Share on other sites More sharing options...
BlueSkyIS Posted February 3, 2011 Share Posted February 3, 2011 this query seems to be missing something.... "SELECT * FROM Testimonials where id" Link to comment https://forums.phpfreaks.com/topic/226520-php-update-sql/#findComment-1169600 Share on other sites More sharing options...
dsjoes Posted February 3, 2011 Author Share Posted February 3, 2011 thanks it was missing this "SELECT * FROM Testimonials where id='$file'" Link to comment https://forums.phpfreaks.com/topic/226520-php-update-sql/#findComment-1169605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.