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:
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.
<?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.
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
<?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:
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: