Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';'
本问题已经有最佳答案,请猛点这里访问。
我很难让这个工作。我可以从下拉菜单调用数据,并将其放入表中,并在不重新加载页面的情况下使其主动更新。我现在正在尝试获取调用后出现在文本输入字段或其他下拉菜单中的数据库信息。
所以基本上我有一个下拉菜单,可以调用用户信息,我正在尝试获取被调用的信息显示在另一个表单中,这样我就可以更新它了。这是我正在处理的代码;
表7.PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | <html> <head> function showUser(str) { if (str=="") { document.getElementById("txtDisp").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtDisp").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser2.php?q="+str,true); xmlhttp.send(); } </head> <body> <form method="post" action="localhost/table7.php"> <select name="users" onchange="showUser(this.value)"> <option value="">Select a person:</option> <?php $con=mysqli_connect("localhost","user","password","database"); // Check connection if (mysqli_connect_errno()) { echo"Failed to connect to MySQL:" . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM users"); while($row = mysqli_fetch_array($result)) { echo"<option value='" . $row['id'] ."'>" . $row['uname'] ."</option>"; mysqli_close($con); } ?> </select> </form> Person info will be listed here. </body> </html> |
GETUSER 2.PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <?php $q = intval($_GET['q']); $con=mysqli_connect("localhost","user","password","database"); // Check connection if (mysqli_connect_errno()) { echo"Failed to connect to MySQL:" . mysqli_connect_error(); } $sql="SELECT * FROM users WHERE id = '".$q."'"; $result1 = mysqli_query($con,$sql); echo"<table border='1'> <tr> <th>Username</th> <th>E-Mail</th> <th>Info 1</th> </tr>"; echo"<form action="getuser2.php" method="post">"; while($row1 = mysqli_fetch_array($result1)) { echo"<tr>"; echo"<td><input type="text" name="info1" value=" . $row1['uname'] ."></td>"; echo"<td>" . $row1['email'] ."</td>"; echo"<td>" . $row1['info1'] ."</td>"; echo"</tr>"; } echo"</form>"; echo"</table>"; mysqli_close($con); ?> |
在getuser2.php代码中,如果去掉表单输入部分并用下面直接用于电子邮件和信息格式的uname调用替换它,它将以标准文本格式显示从数据库调用的数据。
但是,我遇到了这个错误:
Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';' in C:\wamp\www\getuser2.php on line 25