Darkmatter5 Posted May 16, 2008 Share Posted May 16, 2008 I have this code that is giving me the following error "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/byrndb/library/getClient.php on line 38" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $clientid=$_GET["r1"]; include 'dbconfig.php'; include 'opendb.php'; $query="SELECT ClientID, FirstName, LastName, CompanyName, ContactTitle, Address, City, State, ZipCode, HomePhone, WorkPhone, WorkPhoneExtension, FaxPhone, Email FROM byrnjobdb.clients WHERE ClientID=$clientid"; $result=mysql_query($query) OR die (mysql_error()); echo "<br>"; echo "<form method='post'><table width='720' border='0'>"; echo "<tr>"; echo "<td width='120'><div align='center'></div></td>"; echo "<td width='250'><div align='center'>Current record data</div></td>"; echo "<td width='150'><div align='center'>Data to update</div></td>"; echo "<td width='200'><div align='center'>Function status</div></td>"; echo "</tr>"; while($row=mysql_fetch_array($result)) { echo "<tr><td><strong>ClientID:</strong></td> <td>" . $row['ClientID'] . "</td></tr>"; echo "<tr><td><strong>First name:</strong></td> <td>" . $row['FirstName'] . "</td> <td><input name='FirstName' type='text' id='FirstName'/> <td rowspan='13' bgcolor='#006699'><div align='center'> <?php if(isset($_POST['editclient'])) { include 'library/dbconfig.php'; include 'library/opendb.php'; $FirstName=$_POST['FirstName']; $LastName=$_POST['LastName']; $CompanyName=$_POST['CompanyName']; $ContactTitle=$_POST['ContactTitle']; $Address=$_POST['Address']; $City=$_POST['City']; $State=$_POST['State']; $ZipCode=$_POST['ZipCode']; $HomePhone=$_POST['HomePhone']; $WorkPhone=$_POST['WorkPhone']; $WorkPhoneExtension=$_POST['WorkPhoneExtension']; $FaxPhone=$_POST['FaxPhone']; $Email=$_POST['Email']; //put new client data from form into the clients table foreach (array('FirstName', 'LastName', 'CompanyName', 'ContactTitle', 'Address', 'City', 'State', 'ZipCode', 'HomePhone', 'WorkPhone', 'WorkPhoneExtension', 'FaxPhone', 'Email') as $field) { if ($_POST[$field]) { $field_name[]=$field; $field_value[]="'{$_POST[$field]}'"; } } $fields=join(', ', $field_name); $values=join(', ', $field_value); $insertdata='INSERT INTO byrnjobdb.clients ($fields) VALUES ($values)'; mysql_query($insertdata) or dir('Error, insert query failed'); echo 'NEW CLIENT ADDED...<br>'; include 'library/closedb.php'; } else { ?></div></td></tr>"; echo "<tr><td><strong>Last name:</strong></td> <td>" . $row['LastName'] . "</td> <td><input name='LastName' type='text' id='LastName'/></td></tr>"; echo "<tr><td><strong>Company name:</strong></td> <td>" . $row['CompanyName'] . "</td> <td><input name='CompanyName' type='text' id='CompanyName'/></td></tr>"; echo "<tr><td><strong>Contact Title:</strong></td> <td>" . $row['ContactTitle'] . "</td> <td><input name='ContactTitle' type='text' id='ContactTitle'/></td></tr>"; echo "<tr><td><strong>Address:</strong></td> <td>" . $row['Address'] . "</td> <td><input name='Address' type='text' id='Address'/></td></tr>"; echo "<tr><td><strong>City:</strong></td> <td>" . $row['City'] . "</td> <td><input name='City' type='text' id='City'/></td></tr>"; echo "<tr><td><strong>State:</strong></td> <td>" . $row['State'] . "</td> <td><input name='State' type='text' id='State'/></td></tr>"; echo "<tr><td><strong>Zip code:</strong></td> <td>" . $row['ZipCode'] . "</td> <td><input name='ZipCode' type='text' id='ZipCode'/></td></tr>"; echo "<tr><td><strong>Home phone:</strong></td> <td>" . $row['HomePhone'] . "</td> <td><input name='HomePhone' type='text' id='HomePhone'/></td></tr>"; echo "<tr><td><strong>Work phone:</strong></td> <td>" . $row['WorkPhone'] . "</td> <td><input name='WorkPhone' type='text' id='WorkPhone'/></td></tr>"; echo "<tr><td><strong>Extension:</strong></td> <td>" . $row['WorkPhoneExtension'] . "</td> <td><input name='WorkPhoneExtension' type='text' id='WorkPhoneExtension'/></td></tr>"; echo "<tr><td><strong>Fax phone:</strong></td> <td>" . $row['FaxPhone'] . "</td> <td><input name='FaxPhone' type='text' id='FaxPhone'/></td></tr>"; echo "<tr><td><strong>Email:</strong></td> <td>" . $row['Email'] . "</td> <td><input name='Email' type='text' id='Email'/></td></tr>"; echo "<tr><td colspan='4'><div align='center'><input name='editclient' type='submit' id='editclient' value='Store new client data' /></div></td></tr>"; } echo "</table></form>"; include 'closedb.php'; ?> </body> </html> Help please! Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/ Share on other sites More sharing options...
DeanWhitehouse Posted May 16, 2008 Share Posted May 16, 2008 remove the second . <td>" . $row['FirstName'] "</td> Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542940 Share on other sites More sharing options...
947740 Posted May 16, 2008 Share Posted May 16, 2008 Are you allowed to perform php inside an echo statment? If you are, that would make my life a lot easier... Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542941 Share on other sites More sharing options...
DeanWhitehouse Posted May 16, 2008 Share Posted May 16, 2008 none of this is in <?php tags ?></div></td></tr><?php echo "<tr><td><strong>Last name:</strong></td> <td>" . $row['LastName'] . "</td> <td><input name='LastName' type='text' id='LastName'/></td></tr>"; echo "<tr><td><strong>Company name:</strong></td> <td>" . $row['CompanyName'] . "</td> <td><input name='CompanyName' type='text' id='CompanyName'/></td></tr>"; echo "<tr><td><strong>Contact Title:</strong></td> <td>" . $row['ContactTitle'] . "</td> <td><input name='ContactTitle' type='text' id='ContactTitle'/></td></tr>"; echo "<tr><td><strong>Address:</strong></td> <td>" . $row['Address'] . "</td> <td><input name='Address' type='text' id='Address'/></td></tr>"; echo "<tr><td><strong>City:</strong></td> <td>" . $row['City'] . "</td> <td><input name='City' type='text' id='City'/></td></tr>"; echo "<tr><td><strong>State:</strong></td> <td>" . $row['State'] . "</td> <td><input name='State' type='text' id='State'/></td></tr>"; echo "<tr><td><strong>Zip code:</strong></td> <td>" . $row['ZipCode'] . "</td> <td><input name='ZipCode' type='text' id='ZipCode'/></td></tr>"; echo "<tr><td><strong>Home phone:</strong></td> <td>" . $row['HomePhone'] . "</td> <td><input name='HomePhone' type='text' id='HomePhone'/></td></tr>"; echo "<tr><td><strong>Work phone:</strong></td> <td>" . $row['WorkPhone'] . "</td> <td><input name='WorkPhone' type='text' id='WorkPhone'/></td></tr>"; echo "<tr><td><strong>Extension:</strong></td> <td>" . $row['WorkPhoneExtension'] . "</td> <td><input name='WorkPhoneExtension' type='text' id='WorkPhoneExtension'/></td></tr>"; echo "<tr><td><strong>Fax phone:</strong></td> <td>" . $row['FaxPhone'] . "</td> <td><input name='FaxPhone' type='text' id='FaxPhone'/></td></tr>"; echo "<tr><td><strong>Email:</strong></td> <td>" . $row['Email'] . "</td> <td><input name='Email' type='text' id='Email'/></td></tr>"; echo "<tr><td colspan='4'><div align='center'><input name='editclient' type='submit' id='editclient' value='Store new client data' /></div></td></tr>"; } echo "</table></form>"; include 'closedb.php'; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542943 Share on other sites More sharing options...
soycharliente Posted May 16, 2008 Share Posted May 16, 2008 You're missing a closing quote and semicolon right before this. <?php if(isset($_POST['editclient'])) { Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542948 Share on other sites More sharing options...
Darkmatter5 Posted May 16, 2008 Author Share Posted May 16, 2008 947740: I don't see why you can't create php code from an echo. It's basically just creating more code. Blade280891: That portion of the code as far as I can tell is encapsulated within the <?php tag at the top of the code under the <body> tag. there are basically two PHP segments in this code, the original then one that is created and echoed if the editclient button is clicked. Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542950 Share on other sites More sharing options...
Darkmatter5 Posted May 16, 2008 Author Share Posted May 16, 2008 Okay here's another question, in the code echo "<tr><td><strong>ClientID:</strong></td> <td>" . $row['ClientID'] . "</td></tr>"; What do the .'s on either side of $row['ClientID'] do? I go this code from a tutorial somewhere and I can't remember where so I can't go back to it and read up on what it does. So can someone explain? Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542952 Share on other sites More sharing options...
947740 Posted May 16, 2008 Share Posted May 16, 2008 I am thinking that charlieholder agrees with me, because he pointed out that you forgot a "; I just did not think you could have if statements, etc. in an echo statement. The . before and after $row['ClientID'] concatenate (sp?) the string. Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542954 Share on other sites More sharing options...
soycharliente Posted May 16, 2008 Share Posted May 16, 2008 The . operation appends the two things together. It's like adding them, but + is reserved for more mathematical computations. So: <?php $foo = "char"; $bar = "lie"; echo $foo . $bar; // output = charlie ?> Quote Link to comment https://forums.phpfreaks.com/topic/105946-php-inside-a-php-echo/#findComment-542992 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.