Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: parse error

  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    parse error

    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 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.
    Last edited by croix; 01-05-2006 at 11:34 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    The problem is this echo, you can't use double quotes (") in a double quoted string.
    PHP Code:
    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:
    PHP Code:
    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
    }

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/

  • #4
    New Coder
    Join Date
    Nov 2005
    Location
    Louisville, Kentucky
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    What was I thinking?
    Email Me

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd go for the way schleppel did it. It's the easiest and cleanest. Also in the beginning:

    PHP Code:
    <?php 
    include("dbconnection.php"); 
    ?> 
    <?php 
    if (isset($_POST['search'])) {
    This can be written as:

    PHP Code:
    <?php 
    include("dbconnection.php"); 

    if (isset(
    $_POST['search'])) {
    No need to open and close PHP tags when there's nothing between.
    "$question = ( to() ) ? be() : ~be();"

  • #6
    New Coder
    Join Date
    Jan 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by lanasa
    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?

  • #7
    New Coder
    Join Date
    Jan 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •