Lee-Bartlett Posted October 3, 2008 Share Posted October 3, 2008 Ok so i want to try minipulate my update code and im not completly sure where i might be going wrong, This code makes a drop down boxs, and pulls the names from my database. So i made a include file which didnt work but am i going down the right track to do this? Wanna do a simple, click on drop down, get name, click go and it deletes that row. codes are <?php require_once("includes/db_connection.php"); $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['name']; echo "</option>"; $name = $row['name']; $email = $row['email']; $location = $row['location']; $buissnes_name = $row['buissnes_name']; $type = $row['type']; } echo "</select><br>"; echo "<input type=submit value=\"go\">"; echo "</form>"; include("delete.php"); ?> delete.php now <?php if($_GET["name"]=="delete") { $sql = "DELETE FROM news WHERE name=$name"; $res = mysql_query($sql); echo "Row deleted!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/ Share on other sites More sharing options...
unrelenting Posted October 4, 2008 Share Posted October 4, 2008 Are you getting an error? BTW, you don't need the include. Just add the if statement after the require once at the top. Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656719 Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 Quite a few issues. First, you're using the POST method in your form, but trying to use GET in your delete.php. Second, you're not assigning values to your <option> tags (like <option value='somevalue'>). Third, you are checking to see if $_GET['name'] (should be $_POST) is set, but then assuming that $name will be equal to $_GET (this can work if the server is set up properly). Finally, you're checking if your submitted value is equal to "delete," which it will not be. Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656720 Share on other sites More sharing options...
Lee-Bartlett Posted October 4, 2008 Author Share Posted October 4, 2008 hehe quite few problems then Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656721 Share on other sites More sharing options...
DarkWater Posted October 4, 2008 Share Posted October 4, 2008 Also, you don't have '' around your string in MySQL, nor do you do any error checking on the query. Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656723 Share on other sites More sharing options...
Lee-Bartlett Posted October 4, 2008 Author Share Posted October 4, 2008 Hmm seems to be getting bit advance for me, is there a way to dumb this down a little, to somthing much simpler? Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656727 Share on other sites More sharing options...
F1Fan Posted October 4, 2008 Share Posted October 4, 2008 This is relatively simple stuff. I would suggest going through a tutorial like this one: http://w3schools.com/php/php_mysql_intro.asp Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656731 Share on other sites More sharing options...
Lee-Bartlett Posted October 4, 2008 Author Share Posted October 4, 2008 Ye i always tend to over think stuff, i can do the mysql string to work by its self, but atm i struggle to intergrate it with a form or a drop down, somthing like that. Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656740 Share on other sites More sharing options...
Lee-Bartlett Posted October 4, 2008 Author Share Posted October 4, 2008 Hmm that was reltivly simple, cool Quote Link to comment https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/#findComment-656746 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.