#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    11
    Rep Power
    0
    I've made this script to query my database (done in MySql) via url:

    <?php
    $db = mysql_connect("localhost", "");
    mysql_select_db("archive",$db);
    $result = mysql_query("select * from mytable where ID= $ID",$db);
    if ($myrow = mysql_fetch_array($result)) {
    echo "<table border=1>n";
    echo "<tr><td>Name</td><td>Position</td></tr>n";
    do {
    printf("<tr><td>%s %s</td><td>%s</tr>n", $myrow["fieldone"], $myrow["fieldtwo"], $myrow["fieldthree"]);
    } while ($myrow = mysql_fetch_array($result));
    echo "</table>n";
    } else {
    echo "Sorry, no records were found!";
    }
    ?>

    The only working field is ID (Unique,Primary). All the other filelds generete a query error. http://www.mysite.com/test.php?ID=34 works http://www.mysite.com/test.php?fieldone=pippo doesn't work.

    Any help is appreciated!

    Thanks in advance!

    Abe
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Look at your query. You are querying the column ID with the value $ID. If you don't pass a value for $ID then the query won't work. If you want to specify a field and a value you need to pass like this:

    ?fieldname=fieldone&value=pippo
    or
    ?fieldname=ID&value=34
    etc

    and change your query to:

    $result=mysql_query("select * from mytable where $fieldname=$value");

    IOW, if you want to be able to search on any field you have to specify the field.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    11
    Rep Power
    0
    Thanks for your time. I tried it with the very same results, which you can see at http://millennio.it/prova.php?fieldn...min&value=rana
    Code is:
    $result = mysql_query("select * from users where $fieldname=$value",$db);
    The fact that is working only with the ID field makes me think that this kind of query can be done only with primary and/or unique fields. Could be that? If you're willing to help me out pleae tell me anything you need (my MySQL database structure, HTML code, etc.) and I'll provide. Thanks again for your time.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Sorry, my mistake. Since $value might contain non-numeric information it should have single quotes around it:

    $result=mysql_query("select * from mytable where $fieldname='$value'");
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    11
    Rep Power
    0
    Well, it definitely worked! Thanks again very much for your support!

Similar Threads

  1. Store part of URL in session variable?
    By Jonny5uk in forum ASP Programming
    Replies: 4
    Last Post: February 13th, 2004, 08:34 AM
  2. Session, URL or Form variable: Best Choice?
    By dent_moosely in forum PHP Development
    Replies: 2
    Last Post: February 10th, 2004, 07:24 AM
  3. Javascript variable added to 'src' url
    By polgateway in forum JavaScript Development
    Replies: 5
    Last Post: January 21st, 2004, 12:52 PM
  4. how to pass a text throught url
    By renato in forum PHP Development
    Replies: 4
    Last Post: January 15th, 2004, 04:11 PM
  5. Pass variable without PHP
    By boardhigh in forum PHP Development
    Replies: 2
    Last Post: December 17th, 2003, 01:40 PM

IMN logo majestic logo threadwatch logo seochat tools logo