Leo Frost Leo Frost - 1 year ago 121
PHP Question

Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';'

I am having trouble getting this to work. I have been able to call data from a dropdown menu and place it into a table and have it actively update without reloading the page. I am now trying to get the database information that is called to appear within a text input field or another drop down menu.

So basically I have a drop down menu that will call up user information, I am trying to get that information that is called to appear within another form so I can update it. Here is the code I am working with;


function showUser(str) {
if (str=="") {
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) {

<form method="post" action="localhost/table7.php">
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
// 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>";
<div id="txtDisp"><b>Person info will be listed here.</b></div>



$q = intval($_GET['q']);
// 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'>
<th>Info 1</th>

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>";


Within the getuser2.php code if you strip out the form input section and replace it with a call for uname using the format directly below for email and info it will display the data called from the database in standard text format.

However, I am encountering this error:

Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';' in C:\wamp\www\getuser2.php on line 25

Answer Source

The problem is the following:

echo "<td><input type="text" name="info1" value=" . $row1['uname'] . "></td>";

You have double quotes inside a double-quoted string. PHP doesn't know where the string ends.

An easy fix (since you're not using variables inside the string anyway) is to change the double quotes to single quotes:

echo '<td><input type="text" name="info1" value="' . $row1['uname'] . '"></td>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download