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>"; ?> Quote Link to comment 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. Quote Link to comment 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!? Quote Link to comment 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""; Quote Link to comment 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'"; Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
conker87 Posted May 2, 2008 Share Posted May 2, 2008 Try mysql_fetch_array instead. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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>"; ?> Quote Link to comment 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>"; ?> Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 Yes, what are the results? Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 2, 2008 Share Posted May 2, 2008 Yes, what were the results? Quote Link to comment 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) Quote Link to comment Share on other sites More sharing options...
burnside Posted May 2, 2008 Share Posted May 2, 2008 If you only want one result, Limit it to just one result. Quote Link to comment Share on other sites More sharing options...
june_c21 Posted May 2, 2008 Author Share Posted May 2, 2008 how to do so? Quote Link to comment Share on other sites More sharing options...
burnside 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, Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
burnside Posted May 2, 2008 Share Posted May 2, 2008 try sumit like : select * from `users` WHERE `report1.staff_no`='{$name}' see if that works Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.