mastercjb Posted November 8, 2009 Share Posted November 8, 2009 I am trying to add something to my site however I keep getting this error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/blt3/public_html/race.php on line 16 I dont understand what this line of code is trying to do, can you help me. The code (line 16,17) is posted below. $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); I dont get what (u.*,us.*) is. "users" is a table in MYSQL and "userstats" is another. Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/ Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 FROM users u LEFT JOIN userstats us is equal to FROM users AS u LEFT JOIN userstats AS us and this in turn is giving aliases to your tables (consider them shorter names, that are used within query) So, SELECT u.*,us.* means SELECT users.*,userstats.* (which in this case is equal to SELECT * ) That should answer second part of your question. Getting back to first: Is that the only error message you get? The code you have, should also display a MySQL error message if query fails. Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953586 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 Ok I get it, and yes that is the only error. Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953768 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 Can you show us how you connect to the database? Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953776 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 Here is the first few lines of that page, it just includes my config to connect: <?php session_start(); require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "config.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $fm=money_formatter($ir['money']); $cm=money_formatter($ir['crystals'],''); $lv=date('F j, Y, g:i a',$ir['laston']); $h->userdata($ir,$lv,$fm,$cm); $h->menuarea(); Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953780 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 can you tell what var_dump($c); says? Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953792 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 I dont really have any idea. Its not on that page, but If I take $c out of that line it tells me it cant connect to the MYSQL using password NO. So do you think it could be connected to my config.php file some how? Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953807 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 Please, just insert var_dump($c); somewhere before global $c; and also after it, and say what it displays. Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953813 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 I put it before and after and got this: NULL NULL Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/blt3/public_html/race.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953814 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 Ok... so evidently $c is supposed to be a MySQL connection handle, but it is not. You should try to find if it is defined in your config.php, or perhaps headers.php. Search for mysql_connect Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953815 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 I found this in my globals.php: $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953818 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 Ok.. Put var_dump($c); after $c=$db->connection_id; and tell what it says. Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953820 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 At the top of my globals.php I get this: resource(5) of type (mysql link) Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953821 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 That's good. Now we have to find out, why it is not visible in your race.php. Is the line you have $c=$db->connection_id; inside a function? Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953824 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 Sorry I'm not good with terms, I just write. Here is my global.php file. Maybe you can see if it is in a function. <?php session_start(); ob_start(); if(get_magic_quotes_gpc() == 0) { foreach($_POST as $k => $v) { $_POST[$k]=addslashes($v); } foreach($_GET as $k => $v) { $_GET[$k]=addslashes($v); } } require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; include "config.php"; global $_CONFIG; define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; $set=array(); $settq=$db->query("SELECT * FROM settings"); while($r=$db->fetch_row($settq)) { $set[$r['conf_name']]=$r['conf_value']; } $domain=$_SERVER['HTTP_HOST']; global $jobquery, $housequery; if($jobquery) { $is=$db->query("SELECT u.*,us.*,j.*,jr.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN jobs j ON j.jID=u.job LEFT JOIN jobranks jr ON jr.jrID=u.jobrank WHERE u.userid=$userid"); } else if($housequery) { $is=$db->query("SELECT u.*,us.*,h.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN houses h ON h.hWILL=u.maxwill WHERE u.userid=$userid"); } else { $is=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid"); } $ir=$db->fetch_row($is); if($ir['force_logout']) { $db->query("UPDATE users SET force_logout=0 WHERE userid=$userid"); session_unset(); session_destroy(); header("Location: login.php"); exit; } global $macropage; if($macropage && !$ir['verified'] && $set['validate_on']==1) { header("Location: macro1.php?refer=$macropage"); exit; } check_level(); $h = new headers; $h->startheaders(); $fm=money_formatter($ir['money']); $cm=money_formatter($ir['crystals'],''); $lv=date('F j, Y, g:i a',$ir['laston']); global $menuhide; global $atkpage; if($atkpage) { $h->userdata($ir,$lv,$fm,$cm,0); } else { $h->userdata($ir,$lv,$fm,$cm); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953826 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 It seems like you should include this file into your script. Try adding $require('config.php'); at top of your race.php Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953829 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 I put it in and got an error. Also I already have include "config.php"; in my race.php Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953830 Share on other sites More sharing options...
Mchl Posted November 8, 2009 Share Posted November 8, 2009 Sorry, I meant $require('global.php'); Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953832 Share on other sites More sharing options...
mastercjb Posted November 8, 2009 Author Share Posted November 8, 2009 Its doubling my header so I took out a bunch of stuff however, it is putting my whole page inside the table on my race.php page. I think I might be able to take it from here. Thank you so much for the help. Quote Link to comment https://forums.phpfreaks.com/topic/180743-what-does-this-mean/#findComment-953836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.