newbie sql error - wrong syntax in select query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cassbiz
    New Member
    • Oct 2006
    • 202

    newbie sql error - wrong syntax in select query

    I am having a problem getting a simple form to work. I keep getting an error in the select statement.

    Error performing query: Unknown column '$zip' in 'where clause'

    below is my code and it is driving me nuts. What am I doing wrong?

    Read the Posting Guidelines before you post anything!!
    Edited for eadability reasons.
    [php]
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>Please type in your billing Zip Code:<br />
    <input type="text" name="zip" />
    </label><br />
    <input type="submit" value="Submit" />
    </form>

    <?

    $zip = $_POST['zip'];

    echo '<p>Zip Code:</p>';

    // Request Zip Code Information
    $result = @mysql_query('S ELECT zip, city, state FROM zip WHERE zip=$zip');
    if (!$result) {
    exit('<p>Error performing query: ' .
    mysql_error() . '</p>');
    }

    // Display the text of zip in a paragraph
    while ($row = mysql_fetch_arr ay($result)) {
    echo '<p>' . $row['zip'], $row['city'], $row['state']. '</p>';
    }

    ?>
    [/php]

    In the select statement, if I type in the value directly it works fine.


    Thanks in advance
    Frank Casser
  • cassbiz
    New Member
    • Oct 2006
    • 202

    #2
    The 'zip' field is an INT field and is also the primary key.

    I see what I did wrong and now the script is working. I used a ' instead of a " and that threw everything off.

    One more question if I may.

    Code:
    echo '<p>' . $row['zip'], $row['city'], $row['state']. '</p>';
    is there a way to write the output into straight HTML ?

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      But your output line generates straight HTML or do you mean something else?

      Ronald :cool:

      Comment

      • cassbiz
        New Member
        • Oct 2006
        • 202

        #4
        Originally posted by ronverdonk
        But your output line generates straight HTML or do you mean something else?

        Ronald :cool:

        In regards to formatting the string, I would like to add spacing and change the font.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          You can do that either by
          1. having a CSS class defined before and using that class in your echo:
          [php]echo "<p class='xyz'>{$r ow['zip']}, {$row['city']}, {$row['state']}'</p>";[/php]

          2. Defining the CSS characteristics directly in a style attribute of the <p> tag:
          [php]echo "<p style='font-family:verdana, arial,sans serif; font-size:12px;font-weight:bold;'>{ $row['zip']}, {$row['city']}, {$row['state']}'</p>";[/php]

          Ronald :cool:

          Comment

          • cassbiz
            New Member
            • Oct 2006
            • 202

            #6
            Thanks Ron,

            It just appeared that I was using too many single quotes. I appreciate the help.

            Comment

            Working...