View Full Version : Deleting Data With Php

04-22-2007, 10:53 AM
Hello everyone,
i've been trying to do the deleting video tut but once i preview in browser, i just cant delete, i've checked the code and cant find any problem, but maybe another pair of eyes will see my mistake:

$data1 = $_POST['data1'];
$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
$submit = $_POST['submit'];
$delete = $_GET['delete'];

$query = sprintf("DELETE FROM table1 where field1_id = '$delete'");
mysql_query($query)or die(mysql_error());
if ($submit << $data1<< data2<< data3) {
$query = sprintf("INSERT into table1(field2, field3, field4) values('$data1', '$data2', '$data3')");
mysql_query($query)or die(mysql_error());

echo "please complete all the field";

$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['field3']."<br>";
}while($row = mysql_fetch_array($result));

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<form id="form5" name="form5" method="post" action="">
<table width="495" border="1">
<td width="129">data1</td>
<td width="121">data2</td>
<td width="223">data3</td>
<td><?php $_SERVER['PHP_SELF']; ?>
<input name="data1" type="text" id="data1" />
<td><input name="data2" type="text" id="data2" />
<td><input name="data3" type="text" id="data3" />
<td colspan="3"><input type="submit" name="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
<table width="494" border="1">
<td width="66">ID </td>
<td width="65">data1</td>
<td width="76">data2</td>
<td width="118">data3</td>
<td width="135">data4</td>

<?php do{ ?>
<td><?php echo $row['field1_id']; ?></td>
<td><?php echo $row['field2'];?></td>
<td><?php echo $row['field3'] ;?></td>
<td><?php echo $row['field4'] ;?></td>
<td><form id="form1" name="form1" method="post" action="">
<input type="button" name="Submit2" value="Delete"
onClick"document.location.href='dwc.php?delete=<?php echo $row['field1_id'] ?>'" />

<?php }while($row = mysql_fetch_array($result)); ?>

i'm getting stressed :confused:

04-22-2007, 11:38 AM
where your delete button is located

your onclick is missing an =

04-22-2007, 11:41 AM

what you trying to do here...

if ($submit << $data1<< data2<< data3)

04-22-2007, 12:38 PM
I couldn't make out the characters in the tut and so this was the closest i could get to it, but it seems to work fine- what characters should there actually be?

04-22-2007, 12:48 PM
the object of the tutorials is to learn so if your unsure about any aspect then post straight away...

this should be ...

if ($submit && $data1 && $data2 && $data3)

04-22-2007, 01:00 PM
Thanks i'll seek help in future.
And you're right the = was the thorn in my side.