Jump to content

php update sql


dsjoes

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.