barryflood22 Posted April 10, 2007 Share Posted April 10, 2007 New problem, iv got the database adding new records, and now I want it to display all of the records that are there buy name and id number, then i want u to be able to type in the id number of the customer u wish to delete and it shoudl delete it, sounds good buts its not actually deleting the record. it says it does, but its not doing it. customer-modify.php ------------------------ <a href="index.php">< back</a> <br /><br /> <?php // This file contains the database access information. This file also establishes a connection to MySQL and selects the database. // Set the database access information as constants. $DBhost = "localhost"; $DBuser = "root"; $DBpass = ""; $DBName = "bf-customer"; $table = "customer"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); ?> <?php //This file do the actual insert in the database after the connection is established. $query="SELECT * FROM customer"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<br />"; echo "<b><u>Enter ID of customer to delete</u></b>"; echo "<br /><br />"; $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $name=mysql_result($result,$i,"name"); $address=mysql_result($result,$i,"address"); $postcode=mysql_result($result,$i,"postcode"); $telephone=mysql_result($result,$i,"TelephoneNumber"); $emailaddress=mysql_result($result,$i,"EmailAddress"); $type=mysql_result($result,$i,"Type"); $Appointment=mysql_result($result,$i,"Appointment"); echo "ID: $id, "; echo "$name<br>"; echo "<br />"; $i++; } echo "<br />"; ?> <form action="customer-modify-process.php" method="post"> ID: <input type="text" name="id" value=""><br> <input type="Submit" value="Delete"> </form> customer-modify-process.php ------------------------------------ <a href="index.php">< back</a> <br /><br /> <?php // Set the database access information as constants. $DBhost = "localhost"; $DBuser = "root"; $DBpass = ""; $DBName = "bf-customer"; $table = "customer"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); // the 'insert' that will insert the data as a new row into the table under the respective columns. mysql_query("DELETE FROM customer where id = '$id'") or die(mysql_error()); echo "<br />"; echo "Data Deleted!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/ Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226027 Share on other sites More sharing options...
clown[NOR] Posted April 10, 2007 Share Posted April 10, 2007 u sure you're entering the right ID? i had the same issue today... then i suddenly found out that the ID's wasnt what I thought they were =) go into your table and take a look at what the ID's are... but then again... i havent even worked with MySQL for half a week yet =) Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226035 Share on other sites More sharing options...
yzerman Posted April 10, 2007 Share Posted April 10, 2007 change: <form action="customer-modify-process.php" method="post"> to <form action="customer-modify-process.php?id="<?php echo $_POST['id']; ?>"" method="post"> Then add to customer-modify-process.php: $id = $_GET['id'] The problem is you are not sending an id to the second page. You have 2 ways to solve this - hidden inputs (best option) or via the URL (less secure) Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226048 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 now im getting the following whenever i hit the delete button : Parse error: syntax error, unexpected T_STRING in C:\wamp\www\hoff_godd\customer-modify-process.php on line 20 line 20 is mysql_query("DELETE FROM customer where id = '$id'") <a href="index.php"><- back</a> <br /> <br /> <?php $DBhost = "localhost"; $DBuser = "root"; $DBpass = ""; $DBName = "customer"; $table = "customer"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $id = $_GET['id'] mysql_query("DELETE FROM customer where id = '$id'") or die(mysql_error()); echo "<br />"; echo "Data Deleted!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226214 Share on other sites More sharing options...
JSHINER Posted April 10, 2007 Share Posted April 10, 2007 Not 100% sure but change "where" to WHERE ... Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226217 Share on other sites More sharing options...
JSHINER Posted April 10, 2007 Share Posted April 10, 2007 Well that isn't the solution - but it's good coding practice Looks like you're missing a ; at the end of line 20. Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226218 Share on other sites More sharing options...
sasa Posted April 10, 2007 Share Posted April 10, 2007 <a href="index.php">< back</a> <br /><br /> <?php // Set the database access information as constants. $DBhost = "localhost"; $DBuser = "root"; $DBpass = ""; $DBName = "bf-customer"; $table = "customer"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $id = $_POST['id']; //add this line // the 'insert' that will insert the data as a new row into the table under the respective columns. mysql_query("DELETE FROM customer where id = '$id'") or die(mysql_error()); echo "<br />"; echo "Data Deleted!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226220 Share on other sites More sharing options...
barryflood22 Posted April 10, 2007 Author Share Posted April 10, 2007 thanks :-) Quote Link to comment https://forums.phpfreaks.com/topic/46457-solved-delete-records/#findComment-226223 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.