...

View Full Version : parse error



croix
01-05-2006, 10:29 PM
im missing a ; somewhere, but i dont see where. Im kinda just making this all up as I go anyway, pulling examples and tutorials where i can find them.
im trying to allow the user to search a DB for certain fields to match teh submitted info, and to display part of each record that matches.
heres the code:



<?php
include("dbconnection.php");
?>
<?php
if (isset($_POST['search'])) {
$search = $_POST['search'];
$date = $_POST['date'];
$query = "SELECT firstname,lastname,city,state,email FROM customers WHERE firstname OR lastname OR city OR state OR email = '$search' AND date >= '$date' ORDER BY date asc";
} else {
$result = odbc_exec($cnx, $query);
}
while ($row = odbc_exec($result)) {
echo "
<center>
<TABLE CELLPADDING=0 CELLSPACING=0 width="80%"><tr align=center bgcolor=lightsteelblue>
<th><font face="Tahoma" size="1"><b>First Name:</b></font></th>
<th><font face="Tahoma" size="1">Last Name:</font></th>
<th><font face="Tahoma" size="1">City:</font></th>
<th><font face="Tahoma" size="1">State:</font></th>
<th><font face="Tahoma" size="1">Email:</font></th>
</tr><br>
<tr align=center bgcolor=gainsboro>
<td><font face="Tahoma" size="1">$row[firstname]</font></td>
<td><font face="Tahoma" size="1">$row[lastname]</font></td>
<td><font face="Tahoma" size="1">$row[city]</font></td>
<td><font face="Tahoma" size="1">$row[state]</font></td>
<td><font face="Tahoma" size="1">$row[email]</font></td>
</tr>
</table>
</center> ";

}
?>


i know i prolly made a stupid mistake somewhere in here, but i cant find a good reference for PHP ODBC stuff anywhere. yes, I used google. I can find some stuff, but i need something that shows the ODBC equivalent to MYSQL functions.

schleppel
01-05-2006, 10:42 PM
The problem is this echo, you can't use double quotes (") in a double quoted string.

while ($row = odbc_exec($result)) {
echo "
<center>
<TABLE CELLPADDING=0 CELLSPACING=0 width="80%"><tr align=center bgcolor=lightsteelblue>
<th><font face="Tahoma" size="1"><b>First Name:</b></font></th>
<th><font face="Tahoma" size="1">Last Name:</font></th>
<th><font face="Tahoma" size="1">City:</font></th>
<th><font face="Tahoma" size="1">State:</font></th>
<th><font face="Tahoma" size="1">Email:</font></th>
</tr><br>
<tr align=center bgcolor=gainsboro>
<td><font face="Tahoma" size="1">$row[firstname]</font></td>
<td><font face="Tahoma" size="1">$row[lastname]</font></td>
<td><font face="Tahoma" size="1">$row[city]</font></td>
<td><font face="Tahoma" size="1">$row[state]</font></td>
<td><font face="Tahoma" size="1">$row[email]</font></td>
</tr>
</table>
</center> ";

}

I'd do it like this:

while ($row = odbc_exec($result)) {
?>
<center>
<TABLE CELLPADDING=0 CELLSPACING=0 width="80%"><tr align=center bgcolor=lightsteelblue>
<th><font face="Tahoma" size="1"><b>First Name:</b></font></th>
<th><font face="Tahoma" size="1">Last Name:</font></th>
<th><font face="Tahoma" size="1">City:</font></th>
<th><font face="Tahoma" size="1">State:</font></th>
<th><font face="Tahoma" size="1">Email:</font></th>
</tr><br>
<tr align=center bgcolor=gainsboro>
<td><font face="Tahoma" size="1"><?php echo $row['firstname']; ?></font></td>
<td><font face="Tahoma" size="1"><?php echo $row['lastname']; ?></font></td>
<td><font face="Tahoma" size="1"><?php echo $row['city']; ?></font></td>
<td><font face="Tahoma" size="1"><?php echo $row['state']; ?></font></td>
<td><font face="Tahoma" size="1"><?php echo $row['email']; ?></font></td>
</tr>
</table>
</center>
<?php
}

lanasa
01-05-2006, 10:43 PM
Try re-writing your query as:

SELECT firstname,lastname,city,state,email FROM customers WHERE firstname = '$search' OR lastname = '$search" OR city = '$search" OR state = '$search" OR email = '$search' AND date >= '$date' ORDER BY date asc


http://www.php-help.org/

Ramesiv
01-05-2006, 11:33 PM
What you could do is put a blackslash (\) before every other double quote in your script eg:

<font face=\"Tahoma\" size=\"1\">...</font>

or try single quotes

<font face='Tahoma' size='1'>...</font>

btw, its not recommended to use the <font> tag any longer, instead, use <span>

Velox Letum
01-06-2006, 12:57 AM
I'd go for the way schleppel did it. It's the easiest and cleanest. Also in the beginning:


<?php
include("dbconnection.php");
?>
<?php
if (isset($_POST['search'])) {

This can be written as:


<?php
include("dbconnection.php");

if (isset($_POST['search'])) {

No need to open and close PHP tags when there's nothing between.

croix
01-06-2006, 08:07 PM
Try re-writing your query as:

SELECT firstname,lastname,city,state,email FROM customers WHERE firstname = '$search' OR lastname = '$search" OR city = '$search" OR state = '$search" OR email = '$search' AND date >= '$date' ORDER BY date asc


http://www.php-help.org/

ok, i escaped out of my quotes, and the parse error is gone. however, my sql request only refreshes the pages when i submit.

i changed my query to what you have above, but the page will not load with that line changed. i copied and pasted straight in, and it does not work. any ideas why not?

croix
01-06-2006, 08:09 PM
scratch that, i changed the query to this

"SELECT firstname,lastname,city,state,email FROM customers WHERE firstname = '$search' OR lastname = '$search' OR city = '$search' OR state = '$search' OR email = '$search' AND date >= '$date' ORDER BY date asc"

and the page loads now, but still does not return anything on submit.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum