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

<?php
include ('db.php');
 
 
$cid=$_POST["cid"];
$cname=$_POST["cname"];
$cusadd1=$_POST["caddress"];
$cusadd2=$_POST["caddress1"];
$cusadd3=$_POST["caddress2"];
$ccounty=$_POST["county"];
$custpc=$_POST["cpostcode"];
$custele=$_POST["ctelephone"];
$cusemail=$_POST["cemail"];
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;
mysql_query($str);
 
 
 
 
?>
<?php
include ('db.php');
 
 
$cid=$_POST["cid"];
$str="delete * from customer where  customerid=$cid ";
 
print $str;
mysql_query($str);
 
 
 
//print $str;
 
?>
<?php
include('functions.php');
 
	$id=$_POST['id'];
    $myArray=array();
    $myArray=getDeleteCustomer($id);
 
 
 
 
 
 
	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."'");
	$row=mysql_fetch_array($sql);
	return $row; 
}

Recommended Answers

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.