1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Mysql problem

Discussion in 'HTML, Graphics & Programming' started by yhack, 3 Feb 2006.

  1. yhack

    Mobster

    Joined: 6 Jan 2005

    Posts: 3,636

    Location: Cambridge

    Hi, I'm having problems with PHP and Mysql

    PHP:
    $dbname "***";
    $dbpassword "***";
    $dbserver "localhost";
    $db "***";
    mysql_connect($dbserver,$dbname,$dbpassword);
    mysql_select_db($db);
    $query mysql_query("SELECT * FROM `$t` WHERE `id`='$id'");
    while(
    $output mysql_fetch_array($query)) {
    **do 
    stuff
    }
    I get this message

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in *** on line 95

    I've used mysql_fetch_array() before and its worked

    Does anyone know the problem?

    Thanks
     
  2. sloth

    Hitman

    Joined: 20 Apr 2003

    Posts: 947

    What is stored in the variables $t and $id? Do the name of the table in $t actually exist?

    Code:
    $query = mysql_query("SELECT * FROM `$t` WHERE `id`='$id'"); 
    To display the message returned by the MySQL Server, change the line to:

    Code:
    $query = mysql_query("SELECT * FROM `$t` WHERE `id`='$id'") or die(mysql_error());
     
  3. yhack

    Mobster

    Joined: 6 Jan 2005

    Posts: 3,636

    Location: Cambridge

    yeah $t and $id are variables, can i use variables with this?

    edit: read it wrong sorry, on the link it is URL/page.php?t=php?id=1

    maybe this is wrong?
     
    Last edited: 3 Feb 2006
  4. Pine

    Hitman

    Joined: 5 Jun 2004

    Posts: 515

    Location: Cambridge

    You need to use $_GET['t'] and $_GET['id'] in this case. Also you really need to look into validating and/or cleaning the data entered by the user. Also consider whether it would be more sensible to hard code the table name.
     
    Last edited: 3 Feb 2006
  5. lookitsjonno

    Mobster

    Joined: 10 Sep 2003

    Posts: 4,317

    Location: Midlands

  6. yhack

    Mobster

    Joined: 6 Jan 2005

    Posts: 3,636

    Location: Cambridge

    Thanks all,

    I found out that $t was in capitals and the table wasn't

    lol ;)