Page 1 of 1
Help with parse error
Posted: Mon Apr 26, 2010 8:10 am
by steven.cottom
Can anyone help me with this code?
Code: Select all
print '<td width="11%" align="center"><input type="checkbox" name=check[<?print $row['id'];?>]> </td>';
I'm getting a parse error:
Parse error: parse error in C:\wamp\www\new enquiry\search.php on line 69
line 69 is the line in question.
Is it because i am using a print within print?
Any help would be appreciated. As you can probably tell i am a noob to PHP.
Thanks
Re: Help with parse error
Posted: Mon Apr 26, 2010 9:19 am
by greyhoundcode
How about
Code: Select all
print '<td width="11%" align="center"><input type="checkbox" name="check[' . $row['id'] . ']"> </td>';
Re: Help with parse error
Posted: Mon Apr 26, 2010 10:34 am
by steven.cottom
Thanks thats worked!
I'm still having a little trouble with the next bit.
I have a search field that searches a small database and returns the results in a table:
Code: Select all
<?php
mysql_connect ("localhost", "MyUsername", "MyPassword") or die (mysql_error());
mysql_select_db ("enquiries");
$search1 = $_POST['search1'];
$sql = mysql_query("select * FROM enquiry WHERE surname LIKE '%$search1%'");
echo "Your search for '<u><strong>$search1</strong></u>' returned the following results:<br />";
echo "<br />";
print ('<table style="border-width: thin; border-style: solid; border-color: grey; cellpadding=1; border-width: 2px;">');
print '<tr bgcolor="grey">';
print '<td width="3%"><t><strong>ID</strong></t></td>';
print '<td width="9%"><t><strong>ENTRY DATE</strong></t></td>';
print '<td width="4%"><t><strong>TITLE</strong></t></td>';
print '<td width="9%"><t><strong>FIRST NAME</strong></t></td>';
print '<td width="8%"><t><strong>SURNAME</strong></t></td>';
print '<td width="8%"><t><strong>DOB</strong></t></td>';
print '<td width="10%"><t><strong>ADDRESS 1</t></strong></td>';
print '<td width="10%"><t><strong>ADDRESS 2</t><strong></td>';
print '<td width="10%"><t><strong>ADDRESS 3</t></strong></td>';
print '<td width="10%"><t><strong>POST CODE</t></strong></td>';
print '<td width="20%"><t><strong>EMAIL</t></strong></td>';
print '<td width="11%"><t><strong>SELECT</t></strong></td>';
print '</tr>';
print '<form action="update.php" method="post">';
while ($row = mysql_fetch_array( $sql ))
{
print '<tr bgcolor="lightgrey">';
print '<td width="3%"><t>'.$row['id'].'</t></td>';
print '<td width="9%"><t>'.$row['date'].'</t></td>';
print '<td width="4%"><t>'.$row['title'].'</t></td>';
print '<td width="9%"><t>'.$row['firstname'].'</t></td>';
print '<td width="8%"><t>'.$row['surname'].'</t></td>';
print '<td width="8%"><t>'.$row['dob'].'</t></td>';
print '<td width="10%"><t>'.$row['address1'].'</t></td>';
print '<td width="10%"><t>'.$row['address2'].'</t></td>';
print '<td width="10%"><t>'.$row['address3'].'</t></td>';
print '<td width="10%"><t>'.$row['postcode'].'</t></td>';
print '<td width="20%"><t>'.$row['email'].'</t></td>';
print '<td width="11%" align="center"><input type="checkbox" name="check[' . $row['id'] . ']"> </td>';
}
print '</table><br />';
print '<input name="edit" type="submit" value="Edit" />';
print '<input name="letter" type="submit" value="Create Letter" /></form>';
?>
In the results table i have a check box on the end column. I want to be able to tick one checkbox from the results, click a button called "update" which will then take me to another page where the row that i have just checked will be shown on its own.
My code so far is this:
Code: Select all
<?php
mysql_connect ("localhost", "MyUsername", "MyPassword") or die (mysql_error());
mysql_select_db ("enquiries") or die (mysql_error());
foreach($_POST['check'] as $chk) echo $chk;
?>
But i just get the letters "on" echo'd to the screen.
Can you point me in the right direction please?

Re: Help with parse error
Posted: Mon Apr 26, 2010 12:51 pm
by Jonah Bron
How about just make the header of each column a link that goes somewhere like samepage.php?query=^insert search terms here^&column=^insert column to show here^
So, if somebody searched for "johnson", the DOB column link would look like
samepage.php?query=johnson&column=dob
Then you can use an if statement to check if $_GET['column'] is set, and if so, only display that column.
* samepage.php would be the name of the page you gave above