forumnz Posted February 5, 2011 Share Posted February 5, 2011 I am trying to get an id from a table where clientid is equal to a session var. I know the session is set because if I echo it, it shows up, and I know there is a row in the db that matches because I am looking at it right now. The problem is, the query is not selecting any data. I need to select the clientid from the table so I can set another session var. Please please help my brain is not coping! Thank you! <? session_start(); $uid = $_SESSION['logid']; include('../connectdb.php'); mysql_select_db("maindb", $con); $result = mysql_query("SELECT * FROM projects WHERE clientid = $uid"); while($row = mysql_fetch_array($result)) { echo $row['id']; } ?> I'm down to just echoing the row to problem solve but nothing comes up. Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 5, 2011 Author Share Posted February 5, 2011 I did some error reporting and I got: Notice: Undefined variable: con in /var/www/vhosts/pricelesswebsites.co.nz/subdomains/client/httpdocs/SignUp/upload.php on line 8 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/vhosts/pricelesswebsites.co.nz/subdomains/client/httpdocs/SignUp/upload.php on line 8 Line 8 is: mysql_select_db("maindb", $con); (with the error reporting code. Help please? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Where is your code that connects to the database with mysql_connect? Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 5, 2011 Author Share Posted February 5, 2011 It's in that include: <?php $con = mysql_connect("localhost","aaaa","aaaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 There's no error regarding not being able to open connectdb.php, and it seems to connect without returning an error? Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 5, 2011 Author Share Posted February 5, 2011 Correct, I get no connection error when I run the main script or the connect script. It's really weird isn't it... any ideas? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Try changing the include() to a require_once() and see what happens. Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 5, 2011 Author Share Posted February 5, 2011 Nothing is different - same errors. I'm no pro with PHP, but even this should be simple for me... it's a strange one. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Alright, comment out the include and paste the contents of the included file directly into the script. Let's see if that works . . . Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 5, 2011 Author Share Posted February 5, 2011 What.... that worked.... but why? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 The only reason I can think of is a path problem with the include, but changing it to require_once should have generated a fatal error if that was the case. Are you sure you're including the correct file, rather than maybe another file that exists, but doesn't contain the right credentials? Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 5, 2011 Author Share Posted February 5, 2011 I'm 100% sure - I'm using Dreamweaver which displays a list of all linked files within a doc, and I clicked onto the one I was including to copy the code. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 doh. i suggest that you look at the files outside of dreamweaver. i finish design and then leave dreamweaver because of odd stuff like this. Quote Link to comment 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.