Page 1 of 1

Deleting an id!

Posted: Sun Jun 09, 2002 11:56 am
by Aaron
RAR! :D This should work, but isnt!

index.php

Code: Select all

<form method="get" action="delete.php"> //file is the name of this file
<?
mysql_pconnect("localhost","unknownz","password"); //connect to the mySQL
mysql_select_db("unz"); //select the db
if(!$submit)//if submit has not already been pressed
&#123;
    $result = mysql_query("select * from news order by id"); //select all the news
    while($r=mysql_fetch_array($result)) //run the while loop
    &#123; 
        $title=$r&#1111;"title"];//take out the title
        $id=$r&#1111;"id"];//take out the id
        ?>
        <INPUT TYPE="RADIO" NAME="id" VALUE="<?php echo $id;?>"><br> //the radio button with the value of each id
        <?php echo $id;?><br> //output the id
        <?php echo $title?><br> //output the title
<?
    &#125;?> //end of the while loop
<input type="submit" value="submit" name="Submit"></form> //submit
<?
&#125;?>
delete.php

Code: Select all

<?
else
&#123;
    $sql = "DELETE FROM news WHERE id=$id";
    $result = mysql_query($sql);
    echo "Record deleted!";
&#125;?>

Posted: Sun Jun 09, 2002 12:32 pm
by twigletmac
Have you read this?

Do you get any error messages?

Mac

Posted: Sun Jun 09, 2002 12:57 pm
by Aaron
Its just a parse error on line 8 on index, and 2 on delete, and I'm running 4.0.0

Posted: Sun Jun 09, 2002 2:50 pm
by sam
<?php echo $title?> you have to add a ; to the end before closing the php tag.

Cheers Sam

Posted: Sun Jun 09, 2002 3:30 pm
by Aaron
parse

Mysterious parse errors

Posted: Sun Jun 09, 2002 5:58 pm
by BDKR
Well, on delete.php, it's really a logic issue. An else conditional must be preceeded by an if. When PHP runs, it will understand "if something, do something, else, do something else". However, "else, do something" is just going to confuse it. Try starting it out with...

Code: Select all

if(!empty($submit))
    &#123;
    # Do stuff
    &#125;
As for the first one, wherever that parse errror is, or if it even is a parse error. It's hard to say. However, you should check those db functions for success as opposed to just assuming that they ran correctly.

You may also want to consider adding your comments in a different fashion. It's a little difficult to see where a statement ends and the comment begins. This makes debuggin a little tough.

Later on,
Big Din K.R.