Jump to content

php inside a php echo


Darkmatter5

Recommended Posts

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!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.