june_c21 Posted May 2, 2008 Share Posted May 2, 2008 can someone tell me what wrong with my wrong code? i get this error "Parse error: syntax error, unexpected T_VARIABLE line 2" <? php $host = 'localhost'; $user = 'root'; $password = 'admin'; $dbase = 'claim'; $dblink = mysql_connect($host,$user,$password); mysql_select_db($dbase,$dblink); echo "<table border=3 align=center width=90%>"; echo "<tr><td>ID</td>"; echo "<td>Month</td>"; echo "<td>Start Date </td>"; echo "<td>End Date</td>"; echo "<td>Name</td>"; echo "<td>Staff No</td>"; echo "<td>Details</td>"; echo "<td>Amount</td>"; echo "<td>GL code</td>"; echo "<td>Bank </td>"; echo "<td>Account No. </td><tr>"; $name = $_GET['name']; $query = "SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no,details,amount,gl_code,user.bank,user.acc_no FROM user,report1 WHERE user.name = "$name"; $result = mysql_query($query, $dblink); while($myrow = mysql_fetch_row($result)) { echo "<tr><td>" . $myrow[0] . "</td>"; echo "<td>" . $myrow[1] . "</td>"; echo "<td>" . $myrow[2] . "</td>"; echo "<td>" . $myrow[3] . "</td>"; echo "<td>" . $myrow[4] . "</td>"; echo "<td>" . $myrow[5] . "</td>"; echo "<td>" . $myrow[6] . "</td>"; echo "<td>" . $myrow[7] . "</td>"; echo "<td>" . $myrow[8] . "</td>"; echo "<td>" . $myrow[9] . "</td>"; echo "<td>" . $myrow[10] . "</td></tr>"; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/ Share on other sites More sharing options...
Rohan Shenoy Posted May 2, 2008 Share Posted May 2, 2008 In the first line should it be <?php instead of <? php Try removing the space there. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531597 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 Rohan, now you want to help with the script I posted!? Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531601 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 thanks rohan but now the parse error: syntax error, unexpected T_VARIABLE is at line 26 which is this line $query = "SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no,details,amount,gl_code,user.bank,user.acc_no FROM user,report1 WHERE user.name = "$name""; Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531603 Share on other sites More sharing options...
conker87 Posted May 2, 2008 Share Posted May 2, 2008 $query = "SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no,details,amount,gl_code,user.bank,user.acc_no FROM user,report1 WHERE user.name = '$name'"; Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531604 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 $query = "SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no, details, amount, gl_code, user.bank, user.acc_no FROM user, report1 WHERE user.name = '$name'"; That should work. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531607 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 now there is no error. thanks for all the help . but why when i wrote $name = $_POST['name']; $query = "SELECT report1.id,month,start_date,end_date,user.name,report1.staff_no,details,amount,gl_code,user.bank,user.acc_no FROM user,report1 WHERE report1.staff_no = '$name' "; $result = mysql_query($query, $dblink); while($myrow = mysql_fetch_row($result)) { echo "<tr><td>" . $myrow[0] . "</td>"; echo "<td>" . $myrow[1] . "</td>"; echo "<td>" . $myrow[2] . "</td>"; echo "<td>" . $myrow[3] . "</td>"; echo "<td>" . $myrow[4] . "</td>"; echo "<td>" . $myrow[5] . "</td>"; echo "<td>" . $myrow[6] . "</td>"; echo "<td>" . $myrow[7] . "</td>"; echo "<td>" . $myrow[8] . "</td>"; echo "<td>" . $myrow[9] . "</td>"; echo "<td>" . $myrow[10] . "</td></tr>"; } it came out all the data instead of where the staff_no = $name only? Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531609 Share on other sites More sharing options...
conker87 Posted May 2, 2008 Share Posted May 2, 2008 Try mysql_fetch_array instead. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531610 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 it still the same. all the data will come out instead of match report1.staff_no = '$name' only. why? Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531612 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 $name = $_POST['name']; $query = "SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no, details, amount, gl_code, user.bank, user.acc_no FROM user, report1 WHERE report1.staff_no = '$name'"; $result = mysql_query($query, $dblink); while($myrow = mysql_fetch_array($result)) { echo "<tr><td>" . $myrow[0] . "</td>"; echo "<td>" . $myrow[1] . "</td>"; echo "<td>" . $myrow[2] . "</td>"; echo "<td>" . $myrow[3] . "</td>"; echo "<td>" . $myrow[4] . "</td>"; echo "<td>" . $myrow[5] . "</td>"; echo "<td>" . $myrow[6] . "</td>"; echo "<td>" . $myrow[7] . "</td>"; echo "<td>" . $myrow[8] . "</td>"; echo "<td>" . $myrow[9] . "</td>"; echo "<td>" . $myrow[10] . "</td></tr>"; } Try that. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531613 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 Brian, the result still the same. all data came out when i click on submit button. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531616 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 So state again what exactly it is that your wanting the page to do when you click the submit button. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531617 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 ok, first this is my html coding where user can chose the staff_no and click on submit. once submit, it will find in the database the same staff_no that match the one user select. if it is yes, it will display the records base on the staff_no . <html> <head> <script src="selectuser.js"></script> </head> <body><form id="form1" name="form1" method="post" action="checking.php"> <p><strong>KEV Claim</strong></p> <table width="497" border="0"> <tr> <td width="284">Claim</td> <td width="203"><select name="name" id="name" onChange="showUser(this.value)"> <?php $host = 'localhost'; $user = 'root'; $password = 'admin'; $dbase = 'claim'; $dblink = mysql_connect($host,$user,$password); mysql_select_db($dbase,$dblink); $query = "SELECT staff_no, name from user order by name "; $result = mysql_query($query); while($myrow = mysql_fetch_row($result)) { echo "<OPTION VALUE=\"" . $myrow[0] . "\">" . $myrow[1]."</OPTION>"; } ?> </select></td> </tr> </table> <p> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form></body> </html> <?php $host = "localhost"; $user = "root"; $password = "admin"; $dbase = "claim"; $dblink = mysql_connect($host,$user,$password); mysql_select_db($dbase,$dblink); echo "<table border=3 align=center width=90%>"; echo "<tr><td>ID</td>"; echo "<td>Month</td>"; echo "<td>Start Date </td>"; echo "<td>End Date</td>"; echo "<td>Name</td>"; echo "<td>Staff No</td>"; echo "<td>Details</td>"; echo "<td>Amount</td>"; echo "<td>GL code</td>"; echo "<td>Bank </td>"; echo "<td>Account No. </td><tr>"; $name = $_POST['name']; $query = "SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no, details, amount, gl_code, user.bank, user.acc_no FROM user, report1 WHERE report1.staff_no = '$name'"; $result = mysql_query($query, $dblink); while($myrow = mysql_fetch_array($result)) { echo "<tr><td>" . $myrow[0] . "</td>"; echo "<td>" . $myrow[1] . "</td>"; echo "<td>" . $myrow[2] . "</td>"; echo "<td>" . $myrow[3] . "</td>"; echo "<td>" . $myrow[4] . "</td>"; echo "<td>" . $myrow[5] . "</td>"; echo "<td>" . $myrow[6] . "</td>"; echo "<td>" . $myrow[7] . "</td>"; echo "<td>" . $myrow[8] . "</td>"; echo "<td>" . $myrow[9] . "</td>"; echo "<td>" . $myrow[10] . "</td></tr>"; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531620 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 <html> <head> <script src="selectuser.js"></script> </head> <body> <form id="form1" name="form1" method="post" action="checking.php"> <p><strong>KEV Claim</strong></p> <table width="497" border="0"> <tr> <td width="284">Claim</td> <td width="203"><select name="name" id="name" onChange="showUser(this.value)"> <?php $host = 'localhost'; $user = 'root'; $password = 'admin'; $dbase = 'claim'; $dblink = mysql_connect($host, $user, $password); mysql_select_db($dbase, $dblink); $query = "SELECT staff_no, name FROM user ORDER BY name"; $result = mysql_query($query); while($myrow = mysql_fetch_row($result)) { echo "<option value=\"" . $myrow[0] . "\">" . $myrow[1]."</option>"; } ?> </select></td> </tr> </table> <p> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html> <?php $host = 'localhost'; $user = 'root'; $password = 'admin'; $dbase = 'claim'; $dblink = mysql_connect($host, $user, $password); mysql_select_db($dbase, $dblink); echo "<table border=3 align=center width=90%>"; echo "<tr><td>ID</td>"; echo "<td>Month</td>"; echo "<td>Start Date </td>"; echo "<td>End Date</td>"; echo "<td>Name</td>"; echo "<td>Staff No</td>"; echo "<td>Details</td>"; echo "<td>Amount</td>"; echo "<td>GL code</td>"; echo "<td>Bank </td>"; echo "<td>Account No. </td><tr>"; $name = $_POST['name']; $query = "SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no, details, amount, gl_code, user.bank, user.acc_no FROM user, report1 WHERE report1.staff_no = '$name'"; $result = mysql_query($query, $dblink); while($myrow = mysql_fetch_array($result)) { echo "<tr><td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td>"; echo "<td>" . $myrow . "</td></tr>"; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531621 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 brian, did u changed anything in the code? Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531644 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 Yes, what are the results? Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531646 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 the result still the same.... can someone please help me..... brian, thanks for your code... but it doesn't work.. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531648 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 Yes, what were the results? Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531649 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 it came out all the username from database and changed their stuff_no into same staff_no. (250 records) Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531650 Share on other sites More sharing options...
beansandsausages Posted May 2, 2008 Share Posted May 2, 2008 If you only want one result, Limit it to just one result. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531651 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 how to do so? Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531657 Share on other sites More sharing options...
beansandsausages Posted May 2, 2008 Share Posted May 2, 2008 $query = "SELECT staff_no, name FROM user ORDER BY name LIMIT 0,1 "; sumit like that, Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531684 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 but that haven't solve my problem. i need to output the user that have the same staff no not all the user. i wrote SELECT report1.id, month, start_date, end_date, user.name, report1.staff_no, details, amount, gl_code, user.bank, user.acc_no FROM user, report1 WHERE report1.staff_no = '$name' but it output all the staff. Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531768 Share on other sites More sharing options...
beansandsausages Posted May 2, 2008 Share Posted May 2, 2008 try sumit like : select * from `users` WHERE `report1.staff_no`='{$name}' see if that works Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531774 Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 no .. it still doesnt work. please help and guide me more. i am new. thanks in advances Link to comment https://forums.phpfreaks.com/topic/103849-parse-error-syntax-error-unexpected-t_variable/#findComment-531776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.