If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Edit Database through form

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-10, 12:08
Stephanie1986 Stephanie1986 is offline
Registered User
 
Join Date: May 2010
Posts: 1
Edit Database through form

Hi Guys,
I am new to all this so please bear with me.


I have created a database to house all our passwords for our department and the database has 3 columns. "System" "Password" and "Description". I am trying to make a webpage to be able to edit any row of the database but am getting stuck at the end. The web page lists everything in my database under the "system" column with a edit button as a link. Then once the link is choosen it populates a form at the bottom with the information inside it. Once i change anything on the form and click the submit form it should "echo Thank you! Information updated." but doesnt it doesnt update the database it just returns me to edit.php and nothing has changed

My script is listed below any help on getting it to actually update the database would be great thanks

Stephanie

<body>

<?
mysql_connect("localhost","root","mypassword");

mysql_select_db("BACSPINS2");

if(!isset($cmd))
{

$result = mysql_query("select * from password order by id");

while($r=mysql_fetch_array($result))
{
$System=$r["System"];
$id=$r["id"];

echo "<a href='edit.php?cmd=edit&id=$id'>$System - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM password WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>

<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">

System:<INPUT TYPE="TEXT" NAME="System" VALUE="<?php echo $myrow["System"] ?>" SIZE=100><br>
Password:<INPUT TYPE="TEXT" NAME="Password" VALUE="<?php echo $myrow["Password"] ?>" SIZE=97><br>
Description:<INPUT TYPE="TEXT" NAME="Description" VALUE="<?php echo $myrow["Description"] ?> SIZE=100><br>
<br>
<input type="hidden" name="cmd" value="edit">

<input type="submit" name="submit" value="submit">

</form>

<? } ?>
<?
if ($_POST["$submit"])
{
$System = $_POST["System"];
$Password = $_POST["Password"];
$Description = $_POST["Description"];

$sql = "UPDATE password SET System='$System' ,Password='$Password',Description='$Description' WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On