473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Delete MySql Rows Problem

imarkdesigns
Hello everyone.. a newbie programmer here wants to ask why is my codes for deleting rows from my databse won't work.... seems that this codes spread to the net and no one refuse to correct it...

can someone correct this...

#-------

<!-- Editable Area -->
<?php

include ("../dbconnection/connect.php");

$tbl_name="schedule"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>

<?php
while($rows=mysql_fetch_array($result)){
?>
<form name="form1" action="" method="post" enctype="multipart/form-data">
<table id="alter_rows" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="admincheckbox"> <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"> </td>
<td class="admindate"> <? echo $rows['date']; ?> </td>
<td class="admintime"> <? echo $rows['id']; ?> </td>
<td class="adminevents"> <? echo $rows['events']; ?> </td>
<td class="adminvenue"> <? echo $rows['venue']; ?> </td>
<td class="adminlocations"> <? echo $rows['locations']; ?> </td>
</tr>

</table>
<?php
}
?>
<!-- Editable Area -->
<table cellpadding="0" cellspacing="0">
<tr>
<td><input name="delete" id="delete" type="submit" value="Delete Schedule" /></td>
</tr>
</table>
<?
// Check if delete button active, start this

//$delete = $_REQUEST['delete'];
//
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM schedule WHERE id='$del_id' LIMIT 1";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=deleterow.php\">";
}
}
mysql_close();
?>
</form>


------#

when a DELETE button hits nothing happens...
Jul 25 '07 #1
6 2855
r035198x
13,262 8TB
Hello everyone.. a newbie programmer here wants to ask why is my codes for deleting rows from my databse won't work.... seems that this codes spread to the net and no one refuse to correct it...

can someone correct this...

#-------

<!-- Editable Area -->
<?php

include ("../dbconnection/connect.php");

$tbl_name="schedule"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>

<?php
while($rows=mysql_fetch_array($result)){
?>
<form name="form1" action="" method="post" enctype="multipart/form-data">
<table id="alter_rows" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="admincheckbox"> <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"> </td>
<td class="admindate"> <? echo $rows['date']; ?> </td>
<td class="admintime"> <? echo $rows['id']; ?> </td>
<td class="adminevents"> <? echo $rows['events']; ?> </td>
<td class="adminvenue"> <? echo $rows['venue']; ?> </td>
<td class="adminlocations"> <? echo $rows['locations']; ?> </td>
</tr>

</table>
<?php
}
?>
<!-- Editable Area -->
<table cellpadding="0" cellspacing="0">
<tr>
<td><input name="delete" id="delete" type="submit" value="Delete Schedule" /></td>
</tr>
</table>
<?
// Check if delete button active, start this

//$delete = $_REQUEST['delete'];
//
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM schedule WHERE id='$del_id' LIMIT 1";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=deleterow.php\">";
}
}
mysql_close();
?>
</form>


------#

when a DELETE button hits nothing happens...
I'm going to have to copy this to the PHP forum as well.
Jul 25 '07 #2
dafodil
392 256MB
Please check if this variable exists in the file you included:
$db_name

I suggest you to use this after you delete instead of detecting $result.
Expand|Select|Wrap|Line Numbers
  1.  
  2. if((mysql_affected_rows()!=0)&&(mysql_affected_rows()!=-1)){
  3. //your statements goes here
  4. echo "delete successful!"
  5.  
  6. }
  7.  
Jul 25 '07 #3
Please check if this variable exists in the file you included:
$db_name

I suggest you to use this after you delete instead of detecting $result.
Expand|Select|Wrap|Line Numbers
  1.  
  2. if((mysql_affected_rows()!=0)&&(mysql_affected_rows()!=-1)){
  3. //your statements goes here
  4. echo "delete successful!"
  5.  
  6. }
  7.  

looks working on the live site... but not in localhost...??

um, is there any problem in my localhost or something?
[i need more rice to eat before i totally understand this LOL!]

.. and yes i include the db_name...
Jul 25 '07 #4
mwasif
802 Expert 512MB
You have 2 problems with the code
  1. Wrong positioning of <form> tag. It should be outside while() and should not contain enctype="multipart/form-data" if you not uploading a file e.g.
    [PHP]<form name="form1" action="" method="post">
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <table id="alter_rows" align="center" cellpadding="0" cellspacing="0">[/PHP]
  2. Change [PHP]if($delete)[/PHP] to [PHP]if(isset($_POST["delete"]))[/PHP]. I am sure live server has register_globals on.
Jul 25 '07 #5
yeah i guess...

but in the live site it is working... and in my local server where i use xampp, its not working...

well, it seems ok in the live other than local server... thanks for the help guys! you rock all !!
Jul 26 '07 #6
dafodil
392 256MB
yeah i guess...

but in the live site it is working... and in my local server where i use xampp, its not working...

well, it seems ok in the live other than local server... thanks for the help guys! you rock all !!
I think you need to configure something in your local server.
Post again if you have problems.
Jul 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: NotGiven | last post by:
I'd like to delete a record and all its children records at one time. How do I do that? Can you, in one SQL statement, delete from table 1 where id = 3 delete from table 2 where id = 12...
4
by: Chris | last post by:
Hi, sorry to post OT but i cant find the MySQL newsgroup, however i am hoping to pick up on some expert advice from php/mysql gurus here. I'm having some trouble performing a delete across two...
0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
0
by: Vikram Vaswani | last post by:
Hi all, I have the following two tables: mysql> SELECT * FROM clients; +-----+-----------------------------+ | cid | cname | +-----+-----------------------------+ |...
2
by: michael | last post by:
Gotta post because this is driving me nuts. Trying to DELETE orphans. I can successfully: SELECT GroupID FROM Groups LEFT JOIN Users ON UsersID = UserID WHERE UsersID IS NULL; but when I...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
2
by: skidvd | last post by:
Hello: I have just recently converted to using the InnoDB table type so that I can enforce FOREIGN key constraints. I have been using MyISAM tables (accessed via JDBC) successfully for some...
3
by: Richard Marsden | last post by:
Here's another strange error I'm getting when using ODBC to access MySQL. This time ODBC is being more informative, although all the documentation I've looked at, claims that the function in...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
4
imarkdesigns
by: imarkdesigns | last post by:
Hello everyone.. a newbie programmer here wants to ask why is my codes for deleting rows from my databse won't work.... seems that this codes spread to the net and no one refuse to correct it... ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.