Lee-Bartlett Posted October 4, 2008 Share Posted October 4, 2008 Ok i wanna delete a row in a db where the id and the name match, this code works if i wanna either delete by name or id, but if i put both in there it fails. Ofc if 2 people have same name, that will pose a problem, so id + name is best way to delete it. Here is my code, where am i going wrong, I have tried AND where the comma is to <?php require_once("includes/db_connection.php"); ?> <?php $id = $_POST['id']; $name = $_POST['name']; ?> <?php $delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id', name='$name'"); $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<form action=\"\" method=\"post\">"; echo "<select name=\"name\">"; while($row = mysql_fetch_array($res)){ echo "<option>". $row['id'], $row['name']; echo "</option>"; $name = $row['name']; $email = $row['email']; $location = $row['location']; $buissnes_name = $row['buissnes_name']; $type = $row['type']; $id = $row['id']; } echo "</select><br>"; echo "<input type=submit value=\"Delete Record\">"; echo "</form>"; ?> Link to comment https://forums.phpfreaks.com/topic/127039-delete-help/ Share on other sites More sharing options...
BlueSkyIS Posted October 4, 2008 Share Posted October 4, 2008 every record should have a unique id, so you shouldn't need to use name also to identify a unique record. but if that's the way you want to go, replace the comma in your SQL with an AND DELETE FROM tblbasicform WHERE id='$id' AND name='$name' Link to comment https://forums.phpfreaks.com/topic/127039-delete-help/#findComment-657145 Share on other sites More sharing options...
Lee-Bartlett Posted October 4, 2008 Author Share Posted October 4, 2008 tried, and, i click delete button, it like refreshes page, Ok ill take the $name out of the sql, ur right it shouldnt be done like that, but i should be ok to leave it in option Link to comment https://forums.phpfreaks.com/topic/127039-delete-help/#findComment-657146 Share on other sites More sharing options...
Lee-Bartlett Posted October 4, 2008 Author Share Posted October 4, 2008 Hmm strange, there my be somthing wrong with my <option> I can call to collums in 1, i have to either have ID or name Link to comment https://forums.phpfreaks.com/topic/127039-delete-help/#findComment-657149 Share on other sites More sharing options...
BlueSkyIS Posted October 4, 2008 Share Posted October 4, 2008 you haven't set values in your <option>s. <select name='name'> <option value='1'>Some string</option> <option value='2'>Another string</option> <option value='3'>Yet another string</option> </select> Link to comment https://forums.phpfreaks.com/topic/127039-delete-help/#findComment-657150 Share on other sites More sharing options...
Lee-Bartlett Posted October 4, 2008 Author Share Posted October 4, 2008 Thats confused me a little sky, i am new to this, wot do u mean, i googled it came up with loads random html stuff. Link to comment https://forums.phpfreaks.com/topic/127039-delete-help/#findComment-657157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.