Current location: Hot Scripts Forums » Programming Languages » PHP » problem with deleting data from mysql using php


problem with deleting data from mysql using php

Reply
  #1 (permalink)  
Old 07-08-06, 05:53 AM
maxat maxat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Question problem with deleting data from mysql using php

Hi, I have problem with deleting data from mysql using php my script does work with firefox but not with IE.
Code:
<form action="main.php?id=user/delete" method="post">
<td width="10%"><input type="image" src="../images/delete.gif" width="20" height="20" value="<?php echo ($row["id"]) ?>" name="delete" onclick="return confirm('Delete customer from the database?');"></td>
</form>
it is part of a table, inside the table I have few image buttons such as full user info, user ordered products and delete user. For each <td> I made a form, not sure whether it is correct or not, but it does work with firefox.

and delete.php
PHP Code:

<?php


if(isset($_POST['delete'])) {
$query " DELETE FROM user WHERE id = '{$_POST['delete']}' ";

$result mysql_query($query) or die(mysql_error());
if(
mysql_affected_rows() > 0)
echo 
'User deleted';
}
?>
Can you help me to make it work with IE?

Last edited by nico_swd; 07-08-06 at 06:56 AM. Reason: [php] wrappers
Reply With Quote
  #2 (permalink)  
Old 07-08-06, 06:50 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I guess the problem is in the form. Try this instead

Code:
 <form action="main.php?id=user/delete" method="post">
<td width="10%"><input type="image" src="../images/delete.gif" width="20" height="20" name="submit" onclick="return confirm('Delete customer from the database?');">
<input type="hidden" value="<?php echo ($row["id"]) ?>" name="delete" /></td>
</form>
Reply With Quote
  #3 (permalink)  
Old 07-08-06, 06:59 AM
maxat maxat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
still doesn't delete and no errors just blank page
Reply With Quote
  #4 (permalink)  
Old 07-08-06, 08:00 AM
maxat maxat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
This script calls default page to the body of main.php
It is inside of main.php

PHP Code:

$id='';

if(isset($_GET['id']))
{
$id = strip_tags($_GET['id']);
}

$inc = 'user/index.php';

if($id != '')
{
$inc =   ''.$id.'.php';
}
?>

this is body part of main.php

<div id="content">
   
<?php include($inc); ?>
 
</div>
inside user/index.php i have list of users with delete button and view info. When i select "delete" delete.php will be displayed in the body part of main.php with confirmation. To make it possible I wrote link like
<form action="main.php?id=user/delete" method="post"> and it works with Firefox.

Last edited by nico_swd; 07-08-06 at 08:03 AM. Reason: [php] wrappers.
Reply With Quote
  #5 (permalink)  
Old 08-25-09, 11:08 AM
kalapandit kalapandit is offline
New Member
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Dear Senior memeber I have problem in the delete code. the following code is working well at my localhost but when i upload it to the servier it gives the error.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/domainname.com/admin/cds.php on line 92

i am pasting the code :

<html>
<head>
<title>cds</title>
<link href="xampp.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style3 {
color: #FFFFFF;
font-weight: bold;
font-size: 18px;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style4 {color: #FF0000}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body>

<?
if(!mysql_connect("localhost","root",""))
{
echo "<h2>".$TEXT['cds-error']."</h2>";
die();
}
mysql_select_db("trythebest");
?>
<?=$TEXT['cds-head1']?>
<strong>Hello and Welcome Dear Admin of the Website.
<br>
You are at the Administration page of your website. Here you can delete the registerd doctors<br>
at your website. ONE <span class="style4">CLICKING ON DELETE YOU CAN NOT RECOVER DATA</span><br><br> </strong>
<table border=0 cellpadding=0 cellspacing=0>
<tr bgcolor=#f87820>
<td><img src=img/blank.gif width=10 height=25></td>
<td class=tabhead><table width="149" border="0">
<tr>
<td><span class="style1">Name</span></td>
</tr>
</table> <br>
<b><?=$TEXT['cds-attrib1']?></b></td>
<td class=tabhead><table width="149" border="0">
<tr>
<td><span class="style1">E-mail</span></td>
</tr>
</table> <br>
<b><?=$TEXT['cds-attrib2']?></b></td>
<td class=tabhead><table width="149" border="0">
<tr>
<td><span class="style1">Contact Address </span></td>
</tr>
</table> <br>
<b><?=$TEXT['cds-attrib3']?></b></td>
<td class=tabhead><table width="149" border="0">
<tr>
<td><span class="style1">Contact No. </span></td>
</tr>
</table> <br>
<b><?=$TEXT['cds-attrib4']?></b></td>
<td valign="top"><table width="54" border="0">
<tr>
<td><span class="style3">Delete</span></td>
</tr>
</table></td>
</tr>


<?
if($_REQUEST['action']=="del") {
mysql_query("DELETE FROM products WHERE id={$_REQUEST['id']};"); }
$result=mysql_query("SELECT id,titel,item_name,jahr,item_email,
item_address,item_contact FROM products ORDER BY item_name;");

$i=0;
while( $row=mysql_fetch_array($result) )
{
if($i>0)
{
echo "<tr valign=bottom>";
echo "<td bgcolor=#ffffff background='img/strichel.gif' colspan=6><img src=img/blank.gif width=1 height=1></td>";
echo "</tr>";
}
echo "<tr valign=center>";
echo "<td class=tabval><img src=img/blank.gif width=10 height=20></td>";
echo "<td class=tabval><b>".$row['item_name']."</b></td>";
echo "<td class=tabval>".$row['item_email']."&nbsp;</td>";
echo "<td class=tabval>".$row['item_address']."&nbsp;</td>";
echo "<td class=tabval>".$row['item_contact']."&nbsp;</td>";
echo "<td class=tabval><a onclick=\"return confirm('".$TEXT['cds-sure']."');\"
href=cds.php?action=del&id=".$row['id']."><span class=red>[".$TEXT['cds-button1']."]</span></a></td>";
echo "<td class=tabval></td>";
echo "</tr>";
$i++;

}

echo "<tr valign=bottom>";
echo "<td bgcolor=#fb7922 colspan=6><img src=img/blank.gif width=1 height=8></td>";
echo "</tr>";


?>

</table>

<h2><?=$TEXT['cds-head2']?></h2>

<form action=cds.php method=get>
<table border=0 cellpadding=0 cellspacing=0>

<? include ("footer.php");?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP or Mysql problem?? weilies PHP 1 08-01-05 12:29 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
php mysql updating problem kevinb PHP 2 11-06-04 03:15 PM
php and mysql problem AccelEric PHP 1 10-20-04 07:37 PM
another php search mysql problem sumogray PHP 6 06-28-04 08:03 AM


All times are GMT -5. The time now is 07:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.