php my sql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitsmooth
Forum Newbie
Posts: 13
Joined: Thu May 22, 2008 6:50 am

php my sql

Post by nitsmooth »

somehow my code is not displaying the records ...it is showing error on line 12...

Error :
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\php\view_student.php on line 12

My code is:-
------------------------------------------------------------------------------------------
1 <?php
2 echo "here";
3 $con = mysql_connect("localhost","root","");
4 if (!$con)
5 {
6 die('Could not connect: ' . mysql_error());
7 }

8 mysql_select_db("users", $con);
9 $result = mysql_query("SELECT * FROM user WHERE id = '$_POST [userid]' );

10 while($row = mysql_fetch_array($result))
11 {
12 echo $row['id'] . $row['username'] . $row['Address'];
13 echo "<br />";
14 }
15 mysql_close($con);

16 ?>
------------------------------------------------------------------------------------------
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: php my sql

Post by Maugrim_The_Reaper »

9 $result = mysql_query("SELECT * FROM user WHERE id = '$_POST [userid]' );
try

Code: Select all

$result = mysql_query("SELECT * FROM user WHERE id = " . mysql_real_escape_string($_POST['userid']));
1. There is whitespace between $_POST, and the opening square bracket.
2. You missed a closing double-quote.
3. You never escaped the value entering the SQL statement.

The first error, 1, is probably what caused the fatal error - it's the first problem the parser would have found in that line.
nitsmooth
Forum Newbie
Posts: 13
Joined: Thu May 22, 2008 6:50 am

Re: php my sql

Post by nitsmooth »

Thanks very much man
Post Reply