Hi I am having a problem with code i have created to delete a customer from my database, would be grateful if someone could tel me where i have gone wrong

include ('db.php');
print $cid;
$str="delete from customer CustomerName='$cname',CustomerAddress='$cusadd1',CustomerAddress1='$cusadd2',CustomerAddress2='$cusadd3',County='$ccounty',CustomerPostCode='$custpc',CustomerTelNo='$custele',CustomerEmail='$cusemail' where customerid=$cid ";
print $str;
include ('db.php');
$str="delete * from customer where  customerid=$cid ";
print $str;
//print $str;
	print "<form name ='RegisterForm' method='POST' action='delCustomer.php' onSubmit='return validateEditCustomerSubmit(this)'>";
	print '<table>';
	print "<tr><td>Customer Name</td><td><input  name='cname'type='text' size=30 value='$myArray[1] '></input></td></tr>";
	print "<tr><td>Address Line 1</td><td><input name ='caddress' type='text' size=30 value='$myArray[2] '></input></td></tr>";
	print "<tr><td>Address Line 2</td><td><input name='caddress1' type='text' size=30 value='$myArray[3] '></input></td></tr>";
	print "<tr><td>Address Line 3</td><td><input name='caddress2' type='text' size=30 value='$myArray[4] '></input></td></tr>";
	print "<tr><td> County</td><td><input name='county' type='text' size=30 value='$myArray[5] '></input></td></tr>";
	print "<tr><td>Postcode</td><td><input name='cpostcode' type='text' size=30 value='$myArray[6] '></input></td></tr>";
	print "<tr><td> Telephone Number</td><td><input name='ctelephone' type='text' size=30 value='$myArray[7] '></input></td></tr>";
	print "<tr><td>Email</td><td><input name='cemail' type='text' size=30 value='$myArray[8] '></input></td></tr>";	
	print "<tr style='display:none'><td>Email</td><td><input name='cid' type='text' size=30 value='$myArray[0] ' ></input></td></tr>";		
    print "</table>";
	print "<input type='submit' value='Delete'/> <br />";
	print '</form>';
function getDeleteCustomer($id){
	$sql=mysql_query("delete * from customer where customerid ='".$id."'");
	return $row; 

Recommended Answers

You need to create a connection first. Look at this link and see that the perform a mysql_connect(...) before the mysql_query.


Jump to Post

All 3 Replies

thanks svilla but i have created a connection already as i can insert and update customers just not delete them..

Sorry, I guess you are doing that in the db.php. I looked again and can't believe that I missed it the first time. I guess I thought it was part of the where clause.

The syntax for the SQL Delete is:

DELETE FROM table_name
WHERE some_column=some_value

Take CustomerName='$cname',CustomerAddress='$cusadd1',CustomerAddress1='$cusadd2',CustomerAddress2='$cusadd3',County='$ccounty',CustomerPostCode='$custpc',CustomerTelNo='$custele',CustomerEmail='$cusemail' out of the statement it should be

$str="delete from customer where customerid=$cid ";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.