jonoc33 Posted October 13, 2007 Share Posted October 13, 2007 Hey guys, i'm trying to find out how to get this to work. You type in a name of a record in the database and it removes it. In this case it's deleting the record that when you type in the name of the server it looks for it in the column "servername". You type in the servername and it will delete the whole record. deletionform.html <form method="POST" action="scrimdelete.php"> <label>Type name of server you wish to delete: <br /> <input name="textfield" type="text" id="textfield" size="40" /> </label> <input type="button" value="Submit" /> </form> scrimdelete.php <?php $con = mysql_connect("localhost","*****","******"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("******", $con); mysql_query("DELETE FROM **** WHERE servername='*****"); mysql_close($con); ?> Can anyone fix it up for me? Jono Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/ Share on other sites More sharing options...
kratsg Posted October 13, 2007 Share Posted October 13, 2007 .. what do you mean fix it up? Are you saying clean it up or there are errors? Cause I don't see a problem with the code on a first glance. Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368818 Share on other sites More sharing options...
jonoc33 Posted October 13, 2007 Author Share Posted October 13, 2007 Strangely enough it doesn't work... that's why i'm asking Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368819 Share on other sites More sharing options...
MasterACE14 Posted October 13, 2007 Share Posted October 13, 2007 I have noticed a minor problem in it, but this may not make any difference at all. try it anyway. change this line: <?php mysql_query("DELETE FROM **** WHERE servername='*****"); to this: <?php mysql_query("DELETE FROM **** WHERE servername='*****'"); you missed out the second ' after servername. see if that helps. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368820 Share on other sites More sharing options...
kratsg Posted October 13, 2007 Share Posted October 13, 2007 I was wondering that too ace, but then I thought he may have accidentally deleted the quotation mark when he was removing the values. Also, for the column and table names, use `table` around those as it is 'correct' syntax. Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368822 Share on other sites More sharing options...
jonoc33 Posted October 13, 2007 Author Share Posted October 13, 2007 Yeah, it was an accident. Still can't figure out how to work it. Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368829 Share on other sites More sharing options...
kratsg Posted October 13, 2007 Share Posted October 13, 2007 Add the following. Before all code at the top error_reporting(E_ALL); For all mysql queries, add the die(mysql_error()); at the end mysql_query($sql) or die(mysql_error()); Your code looks like this (changed a bit, no more if/else :-D <?php error_reporting(E_ALL); $con = mysql_connect("localhost","*****","******") or die('Could not connect: '.mysql_error()); mysql_select_db("******", $con); mysql_query("DELETE FROM **** WHERE servername='*****") or die(mysql_error()); mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368836 Share on other sites More sharing options...
jonoc33 Posted October 13, 2007 Author Share Posted October 13, 2007 Nope, that didn't do it. It's from a form, so basically it looks like this: <?php error_reporting(E_ALL); $con = mysql_connect("localhost","*****","******") or die('Could not connect: '.mysql_error()); mysql_select_db("******", $con); mysql_query("DELETE FROM alpha_scrims WHERE servername='"$_POST["servername"]"") or die(mysql_error()); mysql_close($con); ?> Is the $_POST bit correct? The text field on the previous page is called servername. Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368842 Share on other sites More sharing options...
kratsg Posted October 13, 2007 Share Posted October 13, 2007 Oh.. Now I see. It's your method of echoing the variables. mysql_query("DELETE FROM alpha_scrims WHERE servername='"$_POST["servername"]"") or die(mysql_error()); Change this to: mysql_query("DELETE FROM alpha_scrims WHERE servername='$_POST[servername]' ") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368847 Share on other sites More sharing options...
jonoc33 Posted October 13, 2007 Author Share Posted October 13, 2007 Didn't work, but this time it came up with this: I type in Jon into the box to delete the record that has servername Jon. Unknown column 'Jon' in 'where clause' i'm using this: <?php error_reporting(E_ALL); $con = mysql_connect("localhost","**","**") or die('Could not connect: '.mysql_error()); mysql_select_db("**", $con); mysql_query("DELETE FROM alpha_scrims WHERE servername=$_POST[servername]") or die(mysql_error()); mysql_close($con); echo "<center>Record Deleted."; echo "<center><a href=admin.php>Back</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368850 Share on other sites More sharing options...
kratsg Posted October 13, 2007 Share Posted October 13, 2007 Is this the code you're using for it? I just recently edited, not sure if you changed.. mysql_query("DELETE FROM alpha_scrims WHERE servername='$_POST[servername]' ") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368851 Share on other sites More sharing options...
jonoc33 Posted October 13, 2007 Author Share Posted October 13, 2007 EDIT: Perfect . Working now. Thankyou for all your help Quote Link to comment https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/#findComment-368853 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.