Jump to content

PHP Fill a Form from a Database: Newbie question please help


newbiehacker

Recommended Posts

heres a simple editing datascript! just replace the wrong info and add remve boxes... Edit: MAde extremely basic

[color=red][b]EDIT:2 added a } before the form[/b][/color]
[code]<?PHP
session_start();
$user=$_SESSION['user'];
$username="**********";
$password="*******";
$database="************";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query2="SELECT * FROM listings WHERE id='$id'";

$result2 = mysql_query($query2) or die ("Error in query: $query2. ".mysql_error());
while($row = mysql_fetch_row($result2)){

//All the field you want to show in text boxes
$title=$row[1];
$price=$row[2];
$des=$row[3];
}
//the form
echo "<form method=POST enctype='multipart/form-data'>Title<input type=text name=title value=$title><br><br>Price<input type=test name=price value=$price><br><br>$pic Description<br><textarea name=des>$des</textarea><br><input type=submit name=submit value=Update!></form>";


//the acculy editing of database
if(isset($_POST['submit'])){
$tit=$_POST['title'];
$pri=$_POST['price'];
$desc=$_POST['des'];

//the rows in the databse are case sensitive!

$query="UPDATE listings SET title='$tit', price='$pri', description='$desc' WHERE id='$lid'";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
echo "<p><b>Listing Successfully Updated!</b></p>";
}
?>[/code]
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.