Jump to content

Updating a DB with a form


dreamkiller23

Recommended Posts

Please be advised that I have scoured the forums, and have learned a great many things, but I still can't figure this badboy out.

 

i've broke it down into three steps:

 

Step 1: (file1.php)

<body>
<table border="1">
<tr><th>Dept ID</th><th>Dept Name</th><th>Modify</th></tr>
<?php
$conn=mysql_connect("localhost", "root", "");

mysql_select_db("department");
$result=mysql_query("SELECT deptID, deptName from department");

while ($row=mysql_fetch_array($result)){
$strURL="<a href=\"step2hw.php?id=$row[0]&dn=$row[1]\">Edit</a>";
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$strURL</td></tr>\n";
}


mysql_free_result($result);
mysql_close($conn);
?>
</table>
</body>

 

Step 2: (file2.php)

<html>
<?php
$conn=mysql_connect("localhost", "root", "");
mysql_select_db("department");
$x=$_GET["id"];
$y=$_GET["dn"];
echo "department id is: $x <br/>";
?>

<body>
<form action="step3hw.php?iz=ip&dn=dp\" method="GET">
<input name="ip" type="text" readonly="true" value="<?php echo $_GET["id"];?>"/><br/>
<input name="dp" type="text"                 value="<?php echo $_GET["dn"];?>"/><br/><br/>
<input name="sub" type="submit" value="Submit" /><br/>
</form>
</body>
</html>

 

Step 3: (file3.php)

<body>
<?php
$conn=mysql_connect("localhost", "root", "");
mysql_select_db("department");
$x=$_GET["id"];
$y=$_GET["dp"];

echo "$x <br/>";
echo "$y <br/>";
$res="UPDATE department SET deptName='$y' WHERE deptID='x'";
echo "$res";
echo "<br/>";
$result=mysql_query("UPDATE department SET deptName='y' WHERE deptID='$x'");
?>
</body>

 

Where am I going wrong? I just don't get it! Please help :/

Link to comment
https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/
Share on other sites

Step 3: (file3.php)

Code:

 

<body>
<?php
$conn=mysql_connect("localhost", "root", "");
mysql_select_db("department");
$x=$_GET["id"];
$y=$_GET["dp"];

echo "$x <br/>";
echo "$y <br/>";
$res="UPDATE department SET deptName='$y' WHERE deptID='x'";
echo "$res";
echo "<br/>";
$result=mysql_query("UPDATE department SET deptName='y' WHERE deptID='$x'");
?>
</body>

 

deptName='y' should be deptName='$y'

 

also, try not to use root to run commands via scripts

It's been on, I get no sort of errors. I just can figure it out.

However, lets say I do make a change to let's fugure Computer Science

We'll change that too:Computer Sciences

 

 

when I hit submit: this is the output.

 

Computer Sciences

UPDATE department SET deptName='Computer Sciences' WHERE deptID=''

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.