syntax error on php code!!

Discussion in 'PHP' started by ninio, Feb 15, 2010.

  1. #1
    hi everyone,
    I've got error on this code.. any one can help me to identify the syntax error.
    thanks


    
    
    <body bgcolor="#CCCCFF"><?php 
    $textfield=$_POST['textfield'];
    $textfield2=$_POST['textfield2'];
    $textfield3=$_POST['textfield3'];
    
    
    mysql_connect("localhost","root","") or die('Error' .mysql_error());
    mysql_select_db("test1");
    $query="INSERT INTO testtable(name,password,comments) VALUES ('".$textfield."', '".$textfield2."','".$textfield3."')";
    $query2=mysql_query (" select * from testtable");
    
    
    
    mysql_query($query)or die ('Error updating database');
    
    echo "The user: " .$textfield.", inserted The following comments: ".$textfield3 ;
    
    
    //while( $row = mysql_fetch_array($query2)){
    	//echo "<br/> username:" .$row['name']. "<br/> comments:" .$row['comments']. "<br/>"  ;}
    	
    	// Retrieve data from database
    $sql="SELECT * FROM testtable";
    $result=mysql_query($sql);
    
    // Start looping rows in mysql database.
    while($rows=mysql_fetch_array($result)){
    ?>
    <table width="400" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td width="10%"><? echo $rows['name']; ?></td>
    <td width="30%"><? echo $rows['comments']; ?></td>
    </tr>
    </table>
    
    <?
    // close while loop
    }
    
    // close connection
    mysql_close();
    ?>
    PHP:
     
    ninio, Feb 15, 2010 IP
  2. bugcoder

    bugcoder Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    without running code it seems as such no syntax error is in code. what error you get?
     
    bugcoder, Feb 15, 2010 IP
  3. Uruviel

    Uruviel Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The only odd thing I see is on the following line:
    $query2=mysql_query (" select * from testtable");
    PHP:
    And that's the space before the select

    Never mind, you don't use that query.
    I don't get any syntax error running this script.
     
    Last edited: Feb 15, 2010
    Uruviel, Feb 15, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    <?php
    error_reporting(E_ALL);
    ?>
    <body bgcolor="#CCCCFF"><?php
      $textfield = $_POST['textfield'];
      $textfield2 = $_POST['textfield2'];
      $textfield3 = $_POST['textfield3'];
      
      
      mysql_connect("localhost", "root", "") or die('Error' . mysql_error());
      mysql_select_db("test1");
      
      $query = "INSERT INTO testtable(name,password,comments) VALUES ('" . $textfield . "', '" . $textfield2 . "','" . $textfield3 . "')";
      
      $query2 = mysql_query(" select * from testtable");
      
      
      mysql_query($query) or die('Error updating database');
      
      echo "The user: " . $textfield . ", inserted The following comments: " . $textfield3;
      
      
      //while( $row = mysql_fetch_array($query2)){
      //echo "<br/> username:" .$row['name']. "<br/> comments:" .$row['comments']. "<br/>"  ;}
      
      // Retrieve data from database
      $sql = "SELECT * FROM testtable";
      $result = mysql_query($sql) or die('Error' . mysql_error());
      
      // Start looping rows in mysql database.
      while ($rows = mysql_fetch_array($result)) {
    ?>
    <table width="400" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td width="10%"><?php
          echo $rows['name'];
    ?></td>
    <td width="30%"><?php
          echo $rows['comments'];
    ?></td>
    </tr>
    </table>
    
    <?php
          // close while loop
      }
      
      // close connection
      mysql_close();
    ?>
    PHP:
    Reply back with error you may get.
     
    danx10, Feb 15, 2010 IP
  5. ninio

    ninio Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi guise

    sorry for late... I've got this error on my browser

    Parse error: syntax error, unexpected $end in C:\xampp\htdocs\test\update2.php on line 44
     
    ninio, Feb 15, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    <?php
    error_reporting(E_ALL);
    ?>
    <body bgcolor="#CCCCFF"><?php
      $textfield = $_POST['textfield'];
      $textfield2 = $_POST['textfield2'];
      $textfield3 = $_POST['textfield3'];
      
      
      mysql_connect("localhost", "root", "") or die('Error' . mysql_error());
      mysql_select_db("test1");
      
      $query = "INSERT INTO testtable(name,password,comments) VALUES ('" . $textfield . "', '" . $textfield2 . "','" . $textfield3 . "')";
      
      $query2 = mysql_query(" select * from testtable");
      
      
      mysql_query($query) or die('Error updating database');
      
      echo "The user: " . $textfield . ", inserted The following comments: " . $textfield3;
      
      /*
      while($row = mysql_fetch_array($query2)){
      echo "<br/> username:" .$row['name']. "<br/> comments:" .$row['comments']. "<br/>"  ;
      }
      */
      
      // Retrieve data from database
      $sql = "SELECT * FROM testtable";
      $result = mysql_query($sql) or die('Error' . mysql_error());
      
      // Start looping rows in mysql database.
      while ($rows = mysql_fetch_array($result)) {
    ?>
    <table width="400" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td width="10%"><?php
          echo $rows['name'];
    ?></td>
    <td width="30%"><?php
          echo $rows['comments'];
    ?></td>
    
    <?php
    
    }
    
    ?>
    PHP:
     
    danx10, Feb 15, 2010 IP
  7. ninio

    ninio Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    hi danx10,
    sorry for the inconveniences..but tested this code again and it's work fine..
    can i ask u what was the error on my first code?

    Thanks a lot



    <?php
    error_reporting(E_ALL);
    ?>
    <body bgcolor="#CCCCFF"><?php
      $textfield = $_POST['textfield'];
      $textfield2 = $_POST['textfield2'];
      $textfield3 = $_POST['textfield3'];
     
     
      mysql_connect("localhost", "root", "") or die('Error' . mysql_error());
      mysql_select_db("test1");
     
      $query = "INSERT INTO testtable(name,password,comments) VALUES ('" . $textfield . "', '" . $textfield2 . "','" . $textfield3 . "')";
     
      $query2 = mysql_query(" select * from testtable");
     
     
      mysql_query($query) or die('Error updating database');
     
      echo "The user: " . $textfield . ", inserted The following comments: " . $textfield3;
     
     
      //while( $row = mysql_fetch_array($query2)){
      //echo "<br/> username:" .$row['name']. "<br/> comments:" .$row['comments']. "<br/>"  ;}
     
      // Retrieve data from database
      $sql = "SELECT * FROM testtable";
      $result = mysql_query($sql) or die('Error' . mysql_error());
     
      // Start looping rows in mysql database.
      while ($rows = mysql_fetch_array($result)) {
    ?>
    <table width="400" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td width="10%"><?php
          echo $rows['name'];
    ?></td>
    <td width="30%"><?php
          echo $rows['comments'];
    ?></td>
    </tr>
    </table>
    
    <?php
          // close while loop
      }
     
      // close connection
      mysql_close();
    ?>
    PHP:
     
    ninio, Feb 15, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    You forgot to close the while loop with the curly bracket.
     
    danx10, Feb 15, 2010 IP