dreamkiller23 Posted April 20, 2008 Share Posted April 20, 2008 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 More sharing options...
dreamkiller23 Posted April 20, 2008 Author Share Posted April 20, 2008 Obviously, the problem is that, although I click submit, when i get back into the php console and display columns from department, the record doesn't update... Driving me nuts. Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522127 Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 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 Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522128 Share on other sites More sharing options...
dreamkiller23 Posted April 20, 2008 Author Share Posted April 20, 2008 With that change made, still nothing... Pulling my hair out now. Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522130 Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 <form action="step3hw.php?iz=ip&dn=dp\" method="GET"> try removing the \ and just having <form action="step3hw.php?iz=ip&dn=dp" method="GET"> that may be screwing with SQL Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522135 Share on other sites More sharing options...
dreamkiller23 Posted April 20, 2008 Author Share Posted April 20, 2008 You're great, but still nothing.. :/ I'm using wamp server btw. Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522141 Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 That shouldn't change anything... Make sure error reporting is on... is it? Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522142 Share on other sites More sharing options...
dreamkiller23 Posted April 20, 2008 Author Share Posted April 20, 2008 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='' Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522143 Share on other sites More sharing options...
dreamkiller23 Posted April 20, 2008 Author Share Posted April 20, 2008 I got it! Cool, thanks alot for your help sir!!! Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522147 Share on other sites More sharing options...
dreamkiller23 Posted April 20, 2008 Author Share Posted April 20, 2008 I haz a typo: $x=$_GET["id"]; should have been $x=$_GET["ip"]; Link to comment https://forums.phpfreaks.com/topic/102025-updating-a-db-with-a-form/#findComment-522148 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.