Jump to content

Question about: unexpected ';'


mattyd

Recommended Posts

Upon running my code online I receive the following error:

 

Parse error: syntax error, unexpected ';' in /home/a4542527/public_html/create.php on line 13

 

indicating that the semicolon (to the right of or die(mysql_error())) in the following code is in error:

 

create.php

<?php

     include 'connection.php';

     $name= $_Post['inputName'];
     $descrip= $_Post['inputDesc'];

     if(!$_Post['submit']){
     echo "Please fill out the review";
     header('Location: index.php');
     } else{
       mysql_query("INSERT INTO people (`id`,`name`,`descrip`)
                    VALUES(NULL, '$name', '$descrip')" or die(mysql_error());
     echo "Your review has been added";
     header('Location: index.php');
     
     }
?>

 

If I remove this semicolon and run the code, I receive this error:

Parse error: syntax error, unexpected T_ECHO in /home/a4542527/public_html/create.php on line 14

 

I'm not sure what I'm doing wrong.  :shrug:

 

(When this script runs it allows for two text boxes to be displayed.  After text is entered and submitted, the said text will be displayed on the screen. Below are the two other associated files that I'm using.)

 

index.php

<?php
   
      include 'connection.php';
   
      $query = "SELECT * FROM people";
   
      $result = mysql_query($query) or die(mysql_error());
   
      while ($person = mysql_fetch_array($result)){
   
      echo $person ['name'];
  
      echo $person ['descrip'];
  
      }
  
      ?>

 

connection.php

<?php
    $dbhost = 'mysql7.000webhost.com';
    $dbuser = 'a4542527_root';
    $dbpass = '*******';
    
    $db = 'a4542527_test1';
    $conn = mysql_connect($dbhost,$dbuser,$dbpass);
    mysql_select_db($db);

?>

 

Thank-you in advance for any help or pointer in the right direction.

~Matty

 

 

Link to comment
Share on other sites

This is actually one of the reasons I always separate the query string from the query execution. It makes finding these types of errors much easier, and allows you to echo the query string easily when something craters.

 

$query = "SELECT `field` FROM `table`";

$result = mysql_query($query) or die('<br>Query string: ' . $query . '<br>Produced error: ' . mysql_error() . '<br>');

 

Note however, that echoing all that information shouldn't be done on a live site, only during development.

Link to comment
Share on other sites

I have adjusted the code now to where the noted error messages do not appear when running the code; The two text boxes appear.  I am able to enter text and select the submit button without error.  But, now, the problem is the overall functionality: The entered data should be added to the DB and also displayed on the screen. (I am following a tutorial for this and have done everything correctly I believe).  Now I just have to figure out why it is not writing to the database and why it is not displaying (*Thank-you for your patience, I am a newbie to PHP/MYSQL)

 

~Matty

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.