deleting an entry? what am i doign wrong?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

deleting an entry? what am i doign wrong?

Post by lizlazloz »

Code: Select all

<?php
$sql1="delete from crews where name ='". $crew ."'";
?>
$name is a valid name for one of the entrys... but it does not delete it? why not?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

I guess that your then passing the $sql1 variable to mysql_query() and everything is ok in that area? As your syntax seems ok.
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Post by lizlazloz »

yes. i get no errors or anything, the entry just doesnt disappear...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If you echo $sql1; and use mysql_query($sql1) or die(mysql_error()); .. what do you get?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Try echoing out the query to see if it looks how you want it to:

Code: Select all

<?php
$sql1 = "DELETE FROM crews WHERE name ='". $crew ."'";
echo $sql1;
?>
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Post by lizlazloz »

will do
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Post by lizlazloz »

i get nothing. well, i edited $crew at an earlier time, before the $sql, and i got the correct value, so i guess that is working...

i get this error though:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/tekwar/public_html/disband.php on line 34

after the page does nothing for 30 seconds...

heres the code:

Code: Select all

<?php
include("checklogin.php");
include("connect.php");


$sql="select crew from game where name ='". $_COOKIE[access] ."'";
$rs=mysql_query($sql,$conn)
or die("could not execute query1");
$row= mysql_fetch_array($rs);
$crew=$row[crew];
echo($crew);
$sql="select leader,r1,r2,r3,r4 from crews where name ='". $crew ."'";
$rs=mysql_query($sql,$conn)
or die("could not execute query2");


$row= mysql_fetch_array($rs);
$r1=$row[r1];
$r2=$row[r2];
$r3=$row[r3];
$r4=$row[r4];
$leader=$row[leader];
if ( $leader == $_COOKIE[access] )
{
if ($_POST[choice] == "yes")
{
$sql1="update game set crew = '' where name ='". $_COOKIE[access] ."'";
$rs1=mysql_query($sql1,$conn)
or die("could not execute query");

$r1 = explode(",", $r1);
$size1 = count($r1);
$ri = 1;
while( $i < $size1 )
{
$sql1="update game set crew = '' where name ='". $r1[$i] ."'";
$rs1=mysql_query($sql1,$conn)
or die("could not execute query");
}

$r2 = explode(",", $r2);
$size2 = count($r2);
$i = 1;
while( $i < $size2 )
{
$sql1="update game set crew = '' where name ='". $r2[$i] ."'";
$rs1=mysql_query($sql1,$conn)
or die("could not execute query");
}

$r3 = explode(",", $r3);
$size3 = count($r3);
$i = 1;
while( $i < $size3 )
{
$sql1="update game set crew = '' where name ='". $r3[$i] ."'";
$rs1=mysql_query($sql1,$conn)
or die("could not execute query");
}

$r4 = explode(",", $r4);
$size4 = count($r4);
$i = 1;
while( $i < $size4 )
{
$sql1="update game set crew = '' where name ='". $r4[$i] ."'";
$rs1=mysql_query($sql1,$conn)
or die("could not execute query");
}

$sql1="delete from crews where name ='". $crew ."'";
echo($sql);
$rs1=mysql_query($sql1,$conn)
or die("could not execute query");
$result="Crew disbanded";
}
}
else
{
$result="Only the leader can disband!";
}

?>
all the rest of the querys are executed, but not the last one...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

while( $i < $size1 ) <-- infinite loop

I don't see where you set $i (or increment it?)
Maybe you want a foreach($size1 as $whatever){ ... } ?
The same applies for those other while() loops

Edit..Looked again and saw $ri = 1;
that should be $i=1; methinks. But the loops are still missing a $i++
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Post by lizlazloz »

ARGH! i'm so stupid... thanks.
Post Reply