SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Search Script - Help, I'm New

    Made this script to search my database by city. But before I even click search, it says:

    "Here are all the profiles in our database that match your search:"

    "Error performing query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '= Profiles.City' at line 1"

    Also, I believe that even after that is fixed, it won't work. There's nothing in the code that says to search after the form is submit? Or am I wrong? Please help.

    PHP Code:
    <form action="<?=$PHP_SELF?>" method="post">
    City: <input type="text" name="city" />
    <input type="submit" name="submitsearch" value="SEARCH" />
    </form>
     
    <?php
     
    $dbcnx 
    = @mysql_connect("localhost""******""******");
     
    if (!
    $dbcnx) {
    echo( 
    "<p>Unable to connect to the database server at this time.</p>" );
    exit();
    }
     
    if (! @
    mysql_select_db("swiftglo_buddypic") ) {
    echo( 
    "<p>Unable to locate the profiles database at this time.</p>" );
    exit();
    }
     
    echo (
    "<p> Here are all the profiles in our database that match your search:</p>");
     
    $result = @mysql_query("SELECT ID, Username FROM Profiles WHERE $city = Profiles.City");
     
    if (!
    $result) {
    echo(
    "<p>Error performing query: " mysql_error() . "</p>");
    exit();
    }
     
    while ( 
    $row mysql_fetch_array($result) ) {
    $username $row["Username"];
    echo(
    "<p>$username</p>");
    }
     
    ?>

  2. #2
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <form action="<? $PHP_SELF?>" method="post">
    City: <input type="text" name="city">
    <input type="submit" name="submit" value="SEARCH">
    </form>

    <?php

    $city 
    $_POST['city'];

    $link mysql_connect("localhost""name""pass") or die(mysql_error());
    mysql_select_db("databasename"$link) or die(mysql_error());

    if(
    $city == "") {

    echo(
    "The City Field Was left Empty Try Again");

    }
    else{

    $query "SELECT id, username FROM profiles WHERE city='$city'";
    $result mysql_query($query);
    $numofrows mysql_num_rows($result);

    while(
    $row mysql_fetch_array($result)) {

    echo
    "<tr><td>'.$row['id'].'</td><td>'.$row['username'].'</td></tr>";

    }

    ?>

    TRY THAT

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That doesn't work, gives many errors.

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How 'bout them apples?
    PHP Code:
    if (isset($_POST['submitsearch']))
    {
        if (empty(
    $_POST['city']))
        {
            exit(
    'You must enter a city! Go back and try again.');
        }

        
    $dbcnx = @mysql_connect('localhost''******''******'
            or die(
    '<p>Unable to connect to the database server at this time.</p>');

        @
    mysql_select_db('swiftglo_buddypic'$dbcnx
            or die(
    '<p>Unable to locate the profiles database at this time.</p>');

        
    $city mysql_escape_string($_POST['city']);
        
    $query "SELECT ID, Username FROM Profiles WHERE Profiles.City LIKE '%$city%'";
        
    $result = @mysql_query($query$dbcnx) or die(mysql_error());

        echo 
    '<p> Here are all the profiles in our database that match your search:</p>';

        while (
    $row mysql_fetch_array($result))
        {
            echo 
    "<p>$row[Username]</p>";
        }
    }
    else
    {
        echo <<<EOF
    <form action="$_SERVER[PHP_SELF]" method="post">
      City: <input type="text" name="city" />
      <input type="submit" name="submitsearch" value="SEARCH" />
    </form>
    EOF;


  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error, expecting `','' or `';'' in /home/swiftglo/public_html/temp/search.php on line 37

  6. #6
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm...I didn't get any errors when I executed that code. Then again, I have been looking at code for most of today. Does your entire script consist of the code that I posted above, or is there other stuff that could be causing problems?


Bookmarks

Posting Permissions

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