mysql trouble

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
darin
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 8:29 am

mysql trouble

Post by darin »

Excuse me for the silly (I guess) topic, but I'm stuck. I'm trying to pull some data from a table with the following code and it keeps telling me "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in W:\www\elis\includes\userrights.php on line 8". PLEASE help!

Code: Select all

$fieldid = array(1,2,3,4,7);
$userid = 1;
foreach($fieldid as $id){
  $query  ="SELECT right ";
  $query .="FROM userrights ";
  $query .="WHERE (userid = '{$userid}') AND (fieldid = '{$id}')";
  $queryresult = mysql_query($query, $connection);
  $j = mysql_fetch_array($queryresult);
  $right[$id] = $j['right'];
}
My table userrights looks like this:

userrightid userid fieldid right
1 1 1 1
2 1 2 1
3 1 3 1
4 1 4 1
5 1 5 1
6 1 6 1
7 1 7 1


Once again I apologise for being such a newbie...
Darin
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: mysql trouble

Post by pickle »

Welcome to the boards, but...
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
Thread moved.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: mysql trouble

Post by AbraCadaver »

mysql_connect() mysql_select_db() ???
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
darin
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 8:29 am

Re: mysql trouble

Post by darin »

Sorry for the wrong place pickle :oops:

AbraCadaver thisi is not it. Please find bellow the whole code, the trouble is that the first select works, but not the second :(

Code: Select all

<?php
  function readrights($userid, $screenid){
    global $connection;
    $query1  ="SELECT fieldid ";
    $query1 .="FROM fields ";
    $query1 .="WHERE screenid = '{$screenid}'";
    $quryresult1 = mysql_query($query1, $connection);
    $i = 0;
    while($field = mysql_fetch_array($quryresult1)){
      $fieldid[$i] = $field['fieldid'];
      $i = $i+1;
    }
    foreach($fieldid as $id){
      $query  ="SELECT right ";
      $query .="FROM userrights ";
      $query .="WHERE (userid = '{$userid}') AND (fieldid = '{$id}')";
      $queryresult = mysql_query($query, $connection);
      $j = mysql_fetch_array($queryresult);
      $right[$id] = $j['right'];
    }
    return $right;
  }
?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: mysql trouble

Post by AbraCadaver »

Code: Select all

$queryresult = mysql_query($query, $connection) or die(mysql_error());
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
darin
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 8:29 am

Re: mysql trouble

Post by darin »

AbraCadaver wrote:

Code: Select all

$queryresult = mysql_query($query, $connection) or die(mysql_error());
Thanks for the support, here is what i get:
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 'FROM userrights WHERE (userid = '1') AND (fieldid = '1')' at line 1

The names of the DB fields and table are ten times checked :( ....
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: mysql trouble

Post by AbraCadaver »

I should have looked more closely: http://dev.mysql.com/doc/refman/5.1/en/ ... words.html

Code: Select all

$query  = "SELECT `right` ";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
darin
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 8:29 am

Re: mysql trouble

Post by darin »

Yes! That did solve my problem, thank you verry much, but how in the world the first select works :?: ?

Kind regards :) ,
Darin

oops you gave a link, i'll read it....
Post Reply