PDA

View Full Version : Deleting Data With Php


gandalfthegrey
04-22-2007, 11: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:

<?php
require_once("connectionscript.php");
$data1 = $_POST['data1'];
$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
$submit = $_POST['submit'];
$delete = $_GET['delete'];

if($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());

}elseif($submit){
echo "please complete all the field";
}

$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
/*do{
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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form5" name="form5" method="post" action="">
<table width="495" border="1">
<tr>
<td width="129">data1</td>
<td width="121">data2</td>
<td width="223">data3</td>
</tr>
<tr>
<td><?php $_SERVER['PHP_SELF']; ?>
<input name="data1" type="text" id="data1" />
</td>
<td><input name="data2" type="text" id="data2" />
</td>
<td><input name="data3" type="text" id="data3" />
</td>
</tr>
<tr>
<td colspan="3"><input type="submit" name="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
</td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<table width="494" border="1">
<tr>
<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>
</tr>

<?php do{ ?>
<tr>
<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'] ?>'" />
</form>
</td>
</tr>

<?php }while($row = mysql_fetch_array($result)); ?>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>


i'm getting stressed :confused:

davidj
04-22-2007, 12:38 PM
where your delete button is located

your onclick is missing an =

davidj
04-22-2007, 12:41 PM
also

what you trying to do here...


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

gandalfthegrey
04-22-2007, 01: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?

davidj
04-22-2007, 01: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)

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