query mysql db with form variable

I have a four column table and a simple form to query one column and return the records found.
THe form works and the variable called tested good in a simple echo test.
the error I get is:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pbmain/public_html/tracking/trackingQuery.php on line 23

I tried mysql_fetch_object but got the same error.

THis is the fourth or fifth script found on line that I've attempted to put into use, and every one has failed in one way or another. THis error here is the most common error of any, and I appreciate input on how to troubleshoot.

thank you
amy

<h3>Search  Tracking Info Details</h3>
          <p>Please enter your Purchase order number</p>
          <form  method="post" action="trackingQuery.php?go"  id="searchform">
            Search for PO number: <input  type="text" name="searchPO">
            <input  type="submit" name="submit" value="Search">
          </form>
      
<?php
      mysql_connect ("localhost", "user", "password") or die ("no connection made");
      mysql_select_db("db");
      
      $searchPO = $_POST['searchPO'];
      $sql = mysql_query("select * from trackingData where Customer PO like '%$searchPO%'");
      
      while ($row = mysql_fetch_array($sql)){
      echo 'PO: '.$row[ 'Customer PO'];
      echo '<br/> Tracking Info: '.$row['Tracking Info'];
      echo '<br/> Invoice No: '.$row[ 'Invoice'];
      }
yamyaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lukasz ChmielewskiCommented:
Customer PO

Does this field really contain a space ?
0
yamyaAuthor Commented:
yes it really does have a space.
did i create my own problem with that?
0
Lukasz ChmielewskiCommented:
Try to do this like

 $sql = mysql_query("select * from trackingData where `Customer PO` like '%$searchPO%'");
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Lukasz ChmielewskiCommented:
It could be the problem, "the argument supplied ..." meand that the query has wrong syntax
you have to point out the field name as one.
0
yamyaAuthor Commented:
Dear Roads,
I added single quotes around the field name as suggested.
I also modified field names to eliminate spaces (just in case!)
The objective is to see the blank form, enter one number, and see the appropriate record set on display.

Now the page displays the empty form AND below the form is displayed ALL the records in the db.
Entering data into the form makes no changes to the display.
there are no error messages displayed,.

http://permabond.com/tracking/trackingQuery.php

thanks for the help.

amy
0
Lukasz ChmielewskiCommented:
Try this:(if you changed the column name to customerPO - without space)

<h3>Search  Tracking Info Details</h3> 
          <p>Please enter your Purchase order number</p> 
          <form  method="post" action="trackingQuery.php?go"  id="searchform"> 
            Search for PO number: <input  type="text" name="searchPO"> 
            <input  type="submit" name="submit" value="Search"> 
          </form> 
       
<?php
     if(!empty($_POST)){

      mysql_connect ("localhost", "user", "password") or die ("no connection made");
      mysql_select_db("db");
      
      $searchPO = $_POST['searchPO'];
      $sql = mysql_query("select * from trackingData where CustomerPO like '%$searchPO%'");
      
      while ($row = mysql_fetch_array($sql)){
      echo 'PO: '.$row[ 'CustomerPO'];
      echo '<br/> Tracking Info: '.$row['Tracking Info'];
      echo '<br/> Invoice No: '.$row[ 'Invoice'];
      }
   }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yamyaAuthor Commented:
Thank you!, I'll examine the original and the final in order to learn what I didn't know.

this worked perfectly, thanks again!
0
Lukasz ChmielewskiCommented:
The problem was that you shoul check if the form was submitted and then - if so - display the fields.
0
Lukasz ChmielewskiCommented:
The problem was that you shoul check if the form was submitted and then - if so - display the fields.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.