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. Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/ 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? Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170362 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? Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170364 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()); } ?> Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170366 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? Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170371 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? Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170374 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. Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170382 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. Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170387 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 . . . Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170388 Share on other sites More sharing options...
forumnz Posted February 5, 2011 Author Share Posted February 5, 2011 What.... that worked.... but why? Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170391 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? Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170398 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. Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170401 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. Link to comment https://forums.phpfreaks.com/topic/226813-why-wont-it-select-anything/#findComment-1170403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.