GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP experts .. please help!! (https://gfy.com/showthread.php?t=133631)

Gasper 05-13-2003 02:42 PM

PHP experts .. please help!!
 
I'm trying to make a script to delete a row from a mysql table ......

Can someone tell me what's wrong ??!?

Please take a look on the last 7 lines .. without them it works (but the script is not complete)


PHP Code:


<form method="get" action="update.php"> 
<?
mysql_pconnect("localhost","username","password"); 
mysql_select_db("databasename"); 
if(!$submit)
{
    $result = mysql_query("select * from poly_links order by id"); 
    while($r=mysql_fetch_array($result)) 
    { 
        
        $id=$r["id"];        
        $songname=$r["songname"];
        $author=$r["author"];

                ?>
        <INPUT TYPE="RADIO" NAME="id" VALUE="<?php echo $id;?>"><br> 
        <?php echo $id;?> 
        <?php echo $songname;?>
        <?php echo $author;?><br> 
<?
    }?>
<input type="submit" value="submit" name="Submit"></form> 
<?
}?> 

<?
else
{
    $sql = "DELETE FROM poly_links WHERE id=$id";
    $result = mysql_query($sql);
    echo "News Deleted.";
}?>


grumpy 05-13-2003 02:52 PM

$sql = "DELETE FROM poly_links WHERE id='$id';";
$result = mysql_query($sql);


Try this

grumpy 05-13-2003 02:55 PM

Does have $id a vaule??

Just put on top

print "id value :$id<br>\n";

then you know it has a value..otherwise there is nothing to delete

twitchkat 05-13-2003 03:01 PM

Code:

{

    $sql = "DELETE FROM poly_links WHERE id=$id";

    $result = mysql_query($sql);

    echo "News Deleted.";

}

I bet $id hasn't been defined when you set $sql.

You can verify this by putting:

Code:

die("SQL QUERY: " . $sql);
after the $sql assignment. If it resolves to:

DELETE FROM poly_links WHERE id=

then that's not valid SQL.

Grumpy's quoting suggestion is good practice.

apscripts 05-13-2003 03:13 PM

The quoting isn't necessary for numeric characters, if the field id is in fact numeric. You should write a function to convert all your empty numeric values to NULL and to quote all your strings. A lot of people call these clean up functions, etc. Also mysql_query does not return anything on DELETE or INSERT. So there is no sense in setting $result to nothing :)

I don't know what error you're getting, but chances are you have no value in $id as suggested previously.

Also - I am *guessing* that I cannot see your entire script - but if that *is* the whole script, you need register_globals on...which is a very, very bad thing to do. register_globals if for pretend environments.


All times are GMT -7. The time now is 02:31 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123