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 02-22-2009, 07:46 PM   #1
shazzi2k
 
Join Date: Feb 2009
Posts: 9
Default Deleting data :S

Hi, bit stuck on this for a while now, cannot seem to figure out what is wrong. When i try to delete data with the button nothing seems to happen, just the refresh. But the record stays.

I have been trying to find fault in these areas.

////////////////////////
$data2 = $_POST[ 'data2' ] ;
$data3 = $_POST[ 'data3' ] ;
$data4 = $_POST[ 'data4' ] ;
$Submit = $_POST[ 'Submit'] ;
$Delete = $_GET [ 'Delete' ] ;
////////////////////////

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

<input type="button" name="Submit2" value="Delete" onclick= "document.location.href='shazcorp.php?Delete= <?php echo $row ['field1_id'] ?> '"/>
</td>
</tr>
<?php }while ($row = mysql_fetch_array($result)); ?>
shazzi2k is offline   Reply With Quote
Old 02-22-2009, 07:55 PM   #2
shazzi2k
 
Join Date: Feb 2009
Posts: 9
Default

This is it all
<?php
require_once("../Connections/connection.php"); //database connection script//



////////////////////////
$data2 = $_POST[ 'data2' ] ;
$data3 = $_POST[ 'data3' ] ;
$data4 = $_POST[ 'data4' ] ;
$Submit = $_POST[ 'Submit'] ;
$Delete = $_GET [ 'Delete' ] ;
////////////////////////

if ($Delete) {
////////////////////////
$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 "A required field is empty!" ;

}

////////////////////////
$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>ShazCorp Insert data</title>
</head>

<body>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action="<?php $_SERVER [ 'PHP_SELF'] ; ?>">
<table width="437" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="146" height="28"><div align="center">data2</div></td>
<td width="145"><div align="center">data3</div></td>
<td width="146"><div align="center">data4</div></td>
</tr>
<tr>
<td height="36"><label>
<input name="data2" type="text" id="data2" />
</label></td>
<td><input name="data3" type="text" id="data3" /></td>
<td><input name="data4" type="text" id="data4" /></td>
</tr>
<tr>
<td height="47" colspan="3"><label>
<div align="center">
<input type="submit" name="Submit" value="Submit" />
<input name="Submit" type="hidden" id="Submit" value="1" />
</div>
</label></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<table width="603" border="1" cellspacing="1" cellpadding="1">
<tr>
<td width="99" height="27">ID1</td>
<td width="135">data2</td>
<td width="135">data3</td>
<td width="135">data4</td>
<td width="71">&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td height="30"><?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="Submit2" value="Delete" onclick= "document.location.href='shazcorp.php?Delete= <?php echo $row ['field1_id'] ?> '"/>
</td>
</tr>
<?php }while ($row = mysql_fetch_array($result)); ?>
</table>
<label></label>
</body>
</html>
shazzi2k is offline   Reply With Quote
Old 02-22-2009, 10:14 PM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

where you have this

PHP Code:
$query sprintf ("DELETE FROM table1 where field1_id='del' "); 
how do you know what record to delete when your not passing a numerical ID

unless you have a record which has a reference called del
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj 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 05:55 AM.


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