netpants Posted December 19, 2006 Share Posted December 19, 2006 hi all, I am trying to delete info that I have entered into my database from my webpage. Here is the site and the way ti looks http://www.freegamespot.net/dancefactory/display.php , and here is the code used for that page.[code]<? $username=""; $password=""; $database=""; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Winners"; $result=mysql_query($query); $num=mysql_numrows($result); ?><font color="#FFFFFF"><? if (isset($_POST['id'])){ $id = $_POST['id']; mysql_query("DELETE FROM Winners WHERE id = '$id'", $con); }else { echo "Nothin was deleted"; } ?> </font><html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Add Winner</title> </head> <body bgcolor="#000000"> <p align="left"> <img border="0" src="1392094530_m.jpg" width="170" height="119"> <font color="#FFFFFF"> <form action="insert.php" method="post"> Date: <input type="text" name="loggedDate"> <br> First Name: <input type="text" name="firstName"> <br> Last Name: <input type="text" name="lastName"><br> Birthdate: <input type="text" name="birth"><br> Phone Number: <input type="text" name="phone"><br> Street Number: <input type="text" name="streetNumber"> Street Name: <input type="text" name="streetName"> City: <input type="text" name="city"><br> State: <input type="text" name="state" size="2"> Zip Code: <input type="text" name="zip"> Prize: <input type="text" name="prize"><br> E-Mail: <input type="text" name="email"><br> <input type="Submit" value="Add Winner"> </form></font> </p> <table border="0" width="986"> <tr> <td width="200"><font color="#FFFFFF">Add Winner<p> <font color="#FFFFFF"><a href="display.php">Display Winner</a></font></td> <td width="863" rowspan="3" valign="top"> <table border="0" width="100%"> <tr> <td> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'id' ?>">ID</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Date</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'name' ?>">Name</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Birthday</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Number</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Name</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">City</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">State</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Zip</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Prize</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">E-Mail</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Edit</font></th> </tr> <? $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $date=mysql_result($result,$i,"loggedDate"); $first=mysql_result($result,$i,"firstName"); $last=mysql_result($result,$i,"lastName"); $birth=mysql_result($result,$i,"birth"); $phone=mysql_result($result,$i,"phone"); $streetnumber=mysql_result($result,$i,"streetNumber"); $streetname=mysql_result($result,$i,"streetName"); $city=mysql_result($result,$i,"city"); $state=mysql_result($result,$i,"state"); $zip=mysql_result($result,$i,"zip"); $prize=mysql_result($result,$i,"prize"); $email=mysql_result($result,$i,"email"); ?> <form method="POST" action=""> <tr> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$id"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$date"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$first $last"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$birth"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$phone"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetnumber"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetname"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$city"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$state"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$zip"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$prize"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$email"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><input type="submit" value="delete" name="delete"></font></td></tr> </form> <? ++$i; } ?> </table> </td> </tr> </table> <p> </body> <?mysql_close(); ?><a href="http://www.freegamespot.net/dancefactory/update.php?id=37">Click Here</a></html>[/code]The page will click like it did something but nothing gets deleted. It will show the echo response at the top after clicking one of the delete buttons. There has to be a little something I am missing in here. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/ Share on other sites More sharing options...
.josh Posted December 19, 2006 Share Posted December 19, 2006 so where is $_POST['id'] being passed from? Only thing I see here is update.php?id=37 at the bottom of your script, which would be passed as $_GET['id'] Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144660 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 You are not declaring $id before the query to delete records where the $id is matched!In the form script, add this before each of the submit buttons:<input type="hidden" name="id" value="<?php echo $id; ?>">That will ensure you have an id value posted from the specific form.Then in your query statement to delete the record, change to:DELETE FROM Winners WHERE id = $_POST['id'] Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144662 Share on other sites More sharing options...
m1rkd1rk Posted December 19, 2006 Share Posted December 19, 2006 I recommend using PHPMyAdmin to delete records in a table. If you are on a webhost, ask about it, if not download it and install it. Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144668 Share on other sites More sharing options...
.josh Posted December 19, 2006 Share Posted December 19, 2006 that's fine and dandy if you are the only one going to delete records. But what about giving delete permissions to other people, but you don't want to give them phpmyadmin access? Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144672 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 Chip, if I change the query, I dont think it will display the database at all since it wont be calling to select stuff from the database just deleting the information. Where shold I put this delete query? Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144683 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 Crayon,That Click here link is just for something else I am working on for updating the information in the page, not deleting. Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144684 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 Tried what you said Chip and am getting this error Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/freegames/domains/freegamespot.net/public_html/dancefactory/display.php on line 17This is the updated code[code]mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Winners"; $result=mysql_query($query); $num=mysql_numrows($result); ?><font color="#FFFFFF"><? if (isset($_POST['id'])){ $id = $_POST['id']; mysql_query("DELETE FROM Winners WHERE id = '$id'", $con); }else { echo "Nothin was deleted"; } ?> </font><html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Add Winner</title> </head> <body bgcolor="#000000"> <p align="left"> <img border="0" src="1392094530_m.jpg" width="170" height="119"> <font color="#FFFFFF"> <form action="insert.php" method="post"> Date: <input type="text" name="loggedDate"> <br> First Name: <input type="text" name="firstName"> <br> Last Name: <input type="text" name="lastName"><br> Birthdate: <input type="text" name="birth"><br> Phone Number: <input type="text" name="phone"><br> Street Number: <input type="text" name="streetNumber"> Street Name: <input type="text" name="streetName"> City: <input type="text" name="city"><br> State: <input type="text" name="state" size="2"> Zip Code: <input type="text" name="zip"> Prize: <input type="text" name="prize"><br> E-Mail: <input type="text" name="email"><br> <input type="Submit" value="Add Winner"> </form></font> </p> <table border="0" width="986"> <tr> <td width="200"><font color="#FFFFFF">Add Winner<p> <font color="#FFFFFF"><a href="display.php">Display Winner</a></font></td> <td width="863" rowspan="3" valign="top"> <table border="0" width="100%"> <tr> <td> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'id' ?>">ID</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Date</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'name' ?>">Name</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Birthday</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Number</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Name</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">City</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">State</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Zip</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Prize</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">E-Mail</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Edit</font></th> </tr> <? $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $date=mysql_result($result,$i,"loggedDate"); $first=mysql_result($result,$i,"firstName"); $last=mysql_result($result,$i,"lastName"); $birth=mysql_result($result,$i,"birth"); $phone=mysql_result($result,$i,"phone"); $streetnumber=mysql_result($result,$i,"streetNumber"); $streetname=mysql_result($result,$i,"streetName"); $city=mysql_result($result,$i,"city"); $state=mysql_result($result,$i,"state"); $zip=mysql_result($result,$i,"zip"); $prize=mysql_result($result,$i,"prize"); $email=mysql_result($result,$i,"email"); ?> <form method="POST" action=""> <tr> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$id"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$date"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$first $last"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$birth"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$phone"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetnumber"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetname"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$city"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$state"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$zip"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$prize"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$email"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><input type="hidden" name="id" value="<?php echo $id; ?>"><input type="submit" value="delete" name="delete"></font></td></tr> </form> <? ++$i; } ?> </table> </td> </tr> </table> <p> </body> <?mysql_close(); ?></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144689 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 Hold on, re writing! Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144690 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 Which is line 17? Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144691 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 Did that and get this..Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/freegames/domains/freegamespot.net/public_html/dancefactory/display.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144692 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 Try changing to this:[code]<?phpif (isset($_POST['id'])){mysql_query("DELETE FROM Winners WHERE id = ".$_POST['id'], $con); }else { echo "Nothin was deleted"; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144694 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 Did that, and when I hit the delete button i get this...Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/freegames/domains/freegamespot.net/public_html/dancefactory/display.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144697 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 Can you post your current full script please? Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144704 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 [code]<? $username=""; $password=""; $database=""; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Winners"; $result=mysql_query($query); $num=mysql_numrows($result); ?><font color="#FFFFFF"> <?phpif (isset($_POST['id'])){mysql_query("DELETE FROM Winners WHERE id = ".$_POST['id'], $con); }else { echo "Nothin was deleted"; } ?></font><html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Add Winner</title> </head> <body bgcolor="#000000"> <p align="left"> <img border="0" src="1392094530_m.jpg" width="170" height="119"> <font color="#FFFFFF"> <form action="insert.php" method="post"> Date: <input type="text" name="loggedDate"> <br> First Name: <input type="text" name="firstName"> <br> Last Name: <input type="text" name="lastName"><br> Birthdate: <input type="text" name="birth"><br> Phone Number: <input type="text" name="phone"><br> Street Number: <input type="text" name="streetNumber"> Street Name: <input type="text" name="streetName"> City: <input type="text" name="city"><br> State: <input type="text" name="state" size="2"> Zip Code: <input type="text" name="zip"> Prize: <input type="text" name="prize"><br> E-Mail: <input type="text" name="email"><br> <input type="Submit" value="Add Winner"> </form></font> </p> <table border="0" width="986"> <tr> <td width="200"><font color="#FFFFFF">Add Winner<p> <font color="#FFFFFF"><a href="display.php">Display Winner</a></font></td> <td width="863" rowspan="3" valign="top"> <table border="0" width="100%"> <tr> <td> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'id' ?>">ID</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Date</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'name' ?>">Name</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Birthday</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Number</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Name</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">City</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">State</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Zip</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Prize</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">E-Mail</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Edit</font></th> </tr> <? $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $date=mysql_result($result,$i,"loggedDate"); $first=mysql_result($result,$i,"firstName"); $last=mysql_result($result,$i,"lastName"); $birth=mysql_result($result,$i,"birth"); $phone=mysql_result($result,$i,"phone"); $streetnumber=mysql_result($result,$i,"streetNumber"); $streetname=mysql_result($result,$i,"streetName"); $city=mysql_result($result,$i,"city"); $state=mysql_result($result,$i,"state"); $zip=mysql_result($result,$i,"zip"); $prize=mysql_result($result,$i,"prize"); $email=mysql_result($result,$i,"email"); ?> <form method="POST" action=""> <tr> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$id"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$date"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$first $last"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$birth"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$phone"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetnumber"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetname"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$city"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$state"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$zip"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$prize"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$email"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><input type="hidden" name="id" value="<?php echo $id; ?>"><input type="submit" value="delete" name="delete"></font></td></tr> </form> <? ++$i; } ?> </table> </td> </tr> </table> <p> </body> <?mysql_close(); ?><a href="http://www.freegamespot.net/dancefactory/update.php?id=37">Click Here</a></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144706 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 Try changing:mysql_query("DELETE FROM Winners WHERE id = ".$_POST['id'], $con); to:mysql_query("DELETE FROM Winners WHERE id = ".$_POST['id']); Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144712 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 by geroge you did it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!You have done what 15 other people couldnt do :)Thank you so much!!Here is the final code for those who are interested.[code]<? $username=""; $password=""; $database=""; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Winners"; $result=mysql_query($query); $num=mysql_numrows($result); ?><font color="#FFFFFF"> <?phpif (isset($_POST['id'])){mysql_query("DELETE FROM Winners WHERE id = ".$_POST['id']); }else { echo "Nothin was deleted"; } ?></font><html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Add Winner</title> </head> <body bgcolor="#000000"> <p align="left"> <img border="0" src="1392094530_m.jpg" width="170" height="119"> <font color="#FFFFFF"> <form action="insert.php" method="post"> Date: <input type="text" name="loggedDate"> <br> First Name: <input type="text" name="firstName"> <br> Last Name: <input type="text" name="lastName"><br> Birthdate: <input type="text" name="birth"><br> Phone Number: <input type="text" name="phone"><br> Street Number: <input type="text" name="streetNumber"> Street Name: <input type="text" name="streetName"> City: <input type="text" name="city"><br> State: <input type="text" name="state" size="2"> Zip Code: <input type="text" name="zip"> Prize: <input type="text" name="prize"><br> E-Mail: <input type="text" name="email"><br> <input type="Submit" value="Add Winner"> </form></font> </p> <table border="0" width="986"> <tr> <td width="200"><font color="#FFFFFF">Add Winner<p> <font color="#FFFFFF"><a href="display.php">Display Winner</a></font></td> <td width="863" rowspan="3" valign="top"> <table border="0" width="100%"> <tr> <td> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'id' ?>">ID</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Date</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><a href="<? $orderby = 'name' ?>">Name</a></font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Birthday</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Number</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Street Name</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">City</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">State</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Zip</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Prize</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">E-Mail</font></th> <th><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Edit</font></th> </tr> <? $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $date=mysql_result($result,$i,"loggedDate"); $first=mysql_result($result,$i,"firstName"); $last=mysql_result($result,$i,"lastName"); $birth=mysql_result($result,$i,"birth"); $phone=mysql_result($result,$i,"phone"); $streetnumber=mysql_result($result,$i,"streetNumber"); $streetname=mysql_result($result,$i,"streetName"); $city=mysql_result($result,$i,"city"); $state=mysql_result($result,$i,"state"); $zip=mysql_result($result,$i,"zip"); $prize=mysql_result($result,$i,"prize"); $email=mysql_result($result,$i,"email"); ?> <form method="POST" action=""> <tr> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$id"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$date"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$first $last"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$birth"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$phone"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetnumber"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$streetname"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$city"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$state"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$zip"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$prize"; ?></font></td> <td bgcolor="#202020"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><? echo "$email"; ?></font></td> <td bgcolor="#333333"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2"><input type="hidden" name="id" value="<?php echo $id; ?>"><input type="submit" value="delete" name="delete"></font></td></tr> </form> <? ++$i; } ?> </table> </td> </tr> </table> <p> </body> <?mysql_close(); ?><a href="http://www.freegamespot.net/dancefactory/update.php?id=37">Click Here</a></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144717 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 For future reference, when using mysql_query($query, $con), you only use $con when you are specifying a particular databse connection to use. If you do not specify a connection and just use mysql_query($query), it will automatically use the last database connection. In your case you are specifying a connection stored in a variable $con, but this has not been declared. Normally this would be declared using something like:$con = mysql_connect(localhost,$username,$password); then you could use:mysql_query("DELETE FROM Winners WHERE id = ".$_POST['id'],$con); Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144725 Share on other sites More sharing options...
netpants Posted December 19, 2006 Author Share Posted December 19, 2006 I understand. Thank You. ;D Quote Link to comment https://forums.phpfreaks.com/topic/31264-solved-deleting-information-stored-in-a-database/#findComment-144727 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.