Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parse Error with ELSE statement

    I am getting a
    Parse error: parse error, unexpected T_ELSE in C:\Sambar Server\docs\clanxssx\news\edit.php on line 34
    with This
    PHP Code:
    <html>
    <head>
    <title>Edit News</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head> 
    <body>
    <?
    if(!isset($a))
    $link = @mysql_connect(localhostclanxssxmysql);
    if(!
    $link){
       echo(
    'Error connecting to the database: ' $mysql_error());
       exit();

    $db = @mysql_selectdb('clanxssx');
    if(!
    $db){
       echo(
    'Error selecting database: ' $mysql_error());
       exit();
    }
    $query "SELECT id, headline, timestamp FROM news ORDER BY timestamp DESC";
    $result = @mysql_query($query);
    if(!
    $result){
       echo(
    'Error selecting news: ' $mysql_error());
       exit();
    }
    if (
    mysql_num_rows($result) > 0){
        while(
    $row mysql_fetch_object($result))
        {
        
    ?>
       <font size="-1"><b><? echo $row->headling?></b> <i><? echo formatDate($row->timestamp); ?></i></font>
       <br>
       <font size="-2"><a href="edit.php?a=edit&id=<? echo $row->id?>">edit</a> | 
       <a href="edit.php?a=delete&id=<? echo $row->id?>">delete</a></font>
        <?
    }else{
       print(
    '<font size="-2">No news in the database</font>/n')
    }
       
    mysql_close($link);
    }elseif(
    $a == 'edit'){
    if(!isset(
    $update)){
    $link = @mysql_connect(localhostclanxssxmysql);
    if(!
    $link){
       echo(
    'Error connecting to the database: ' $mysql_error());
       exit();
    }
    $db = @mysql_selectdb('clanxssx');
    if(!
    $db){
       echo(
    'Error selecting database: ' $mysql_error());
       exit();
    }
    $query "SELECT name, email, headline, story FROM news WHERE id = '$id'";
    $result = @mysql_query($query);
    if(!
    $result){
       echo(
    'Error selecting news item: ' $mysql_error());
       exit();
    }
    mysql_fetch_object($result);
    ?>
    <form name="form1" method="post" action="edit.php?a=edit&id=<? echo($id?>&update=1">
      <table width="50%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="50%">Name</td>
          <td><input name="name" type="text" id="name" value="<? echo($row->name?>"></td>
        </tr>
        <tr> 
          <td>Email</td>
          <td><input name="email" type="text" id="email" value="<? echo($row->email?>"></td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>Headline</td>
          <td><input name="headline" type="text" id="headline" value="<? echo($row->headline?>"></td>
        </tr>
        <tr> 
          <td>News Story</td>
          <td><textarea name="story" id="story" value="<? echo($row->story?>"></textarea></td>
        </tr>
        <tr> 
          <td colspan="2"><div align="center">
              <input name="hiddenField" type="hidden" value="update">
              <input name="add" type="submit" id="add" value="Update">
            </div></td>
        </tr>
      </table>
      </form>
    <?
    }else{
    $query "UPDATE news SET name = '$name, email = '$email', headline = '$headline', story = '$story', timestamp = NOW() WHERE id = '$id';
    $result = @mysql_query($query);
    if(!$result){
       echo('Error updating news item: ' . $mysql_error());
       exit();
    }else{
       mysql_close($link);
       echo('Update successful!');
     }
    }elseif($a == 'delete'){
    $link = @mysql_connect(localhost, clanxssx, mysql);
    if(!$link){
       echo('Error connecting to the database: ' . $mysql_error());
       exit();
    }
    $db = @mysql_selectdb('clanxssx');
    if(!$db){
       echo('Error selecting database: ' . $mysql_error());
       exit();
    }
    $query = "
    DELETE FROM news WHERE id '$id'";
    $result = @mysql_query($query);
    if(!$result){
       echo('Error deleteing news item: ' . $mysql_error());
       exit();
    }
    mysql_close($link);
    echo('News item deleted.');
    } ?>
    </body>
    </html>
    I cant seem to find out how to fix it

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    looks like you need one more } ahead of that else to cover the WHILE loop ending.

    }} else {

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You're missing a quote on this line
    PHP Code:
    $query "UPDATE news SET name = '$name, email = '$email', headline = '$headline', story = '$story', timestamp = NOW() WHERE id = '$id'; 
    after id = '$id' add "

    PHP Code:
    $query "UPDATE news SET name = '$name, email = '$email', headline = '$headline', story = '$story', timestamp = NOW() WHERE id = '$id'"

  • #4
    New Coder
    Join Date
    Mar 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Parse error: parse error, unexpected T_ELSEIF in C:\Sambar Server\docs\clanxssx\news\edit.php on line 39

    This is now the error that i am getting!

  • #5
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    also you need the closing quote around $name

    PHP Code:
    $query "UPDATE news SET name = '$name', email = '$email', headline = '$headline', story = '$story', timestamp = NOW() WHERE id = '$id'"

  • #6
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you missed an { at if (!(isset($a)) ... (first line) {

    i think that's about it... that should fix it..
    (if $a is not set.. then get from teh database.. otherwise if $a is "edit" then display in a form ... otherwise... ... update the database.. (that's about it right?)

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You don't need to use the {}

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    doesn't hurt tho, makes it much easier to follow the condition trees.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •