logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 05-19-2007, 09:06 PM   #1
Mark_W
 
Join Date: May 2007
Location: South London
Posts: 136
Default Part 10 - Deleting data problem

Hi, first of all I would like to say thank you for the effort you have been putting in with these video tutorials, they have helped me to understand php a bit more.

Anyway, I am currently on Part 10 of 'A Beginners Guide' and I am having a problem.

When I click on the delete button instead of the file being deleted I receive a page which just shows the table and the contents of the database.

Below is my code, I have gone over it a dozen times now and I cannot see where the problem lies, thank you for your help.

PHP Code:
<?php
require_once("Connections/connection.php"); //database connection //

/////////////////////////////////////////
$data2        =    $_POST['data2'];
$data3        =    $_POST['data3'];
$data4        =    $_POST['data4'];
$submit        =    $_POST['submit'];
$del        =    $_GET['del'];
////////////////////////////////////////

if ($del){
//////////////
$query        sprintf("DELETE FROM table1 where field1_id='$del'");
            
mysql_query($query) or die (mysql_error());
//////////////
}


if (
$submit && $data2 && $data3 && $data4) {

//////////////
$query        sprintf("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', '$data4')");
            
mysql_query($query) or die (mysql_error());
//////////////

}elseif($submit){

echo 
"One of your fields is empty!";

}
///////////////////////////////
$query        =sprintf("SELECT * FROM table1"); // * means all, so 'select all data from table 1 //
$result        =@mysql_query($query);
$row        =mysql_fetch_array($result);
////////////////////////////

//do {
//    echo $row['field2']."<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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<br />
<br />
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; //SUBMITS TO THE SAME PAGE, INSTEAD OF SENDING TO ANOTHER PAGE// ?>">
  <table width="200" border="1">
    <tr>
      <td>data2</td>
      <td>data3</td>
      <td>data4</td>
    </tr>
    <tr>
      <td><label>
        <input type="text" name="data2" id="data2" />
      </label></td>
      <td><label>
        <input type="text" name="data3" id="data3" />
      </label></td>
      <td><label>
        <input type="text" name="data4" id="data4" />
      </label></td>
    </tr>
    <tr>
      <td colspan="3" align="center"><label>
        <input type="submit" name="Submit" id="Submit" value="Submit" />
        <input name="submit" type="hidden" id="submit" value="1" />
      </label></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<table width="424" height="56" border="1">
  <tr>
    <td>ID</td>
    <td>data2</td>
    <td>data3</td>
    <td>data4</td>
    <td>&nbsp;</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> 
    <input type="button" name="button" value="Delete" onClick="document.location.href='dwc.php?del=<?php echo $row['field1_id']?>'" />
 </td>
  </tr>
  <?php }while ($row mysql_fetch_array($result)); ?>    
</table>
<p>&nbsp;</p>
</body>
</html>

Last edited by Mark_W; 05-19-2007 at 09:18 PM..
Mark_W is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:12 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com