Deleting an id!

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
Aaron
Forum Commoner
Posts: 82
Joined: Sun May 12, 2002 2:51 pm

Deleting an id!

Post 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;?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you read this?

Do you get any error messages?

Mac
Aaron
Forum Commoner
Posts: 82
Joined: Sun May 12, 2002 2:51 pm

Post by Aaron »

Its just a parse error on line 8 on index, and 2 on delete, and I'm running 4.0.0
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

<?php echo $title?> you have to add a ; to the end before closing the php tag.

Cheers Sam
Last edited by sam on Sun Jun 09, 2002 8:52 pm, edited 1 time in total.
Aaron
Forum Commoner
Posts: 82
Joined: Sun May 12, 2002 2:51 pm

Post by Aaron »

parse
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Mysterious parse errors

Post 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.
Post Reply