osyrys14 Posted May 2, 2011 Share Posted May 2, 2011 Server information is below. I'm running a query that isn't returning any results, even though I know the information is in the database. Here's the code... $getid = $_GET['id']; mysql_connect("localhost","myusername","mypassword"); //(host, username, password) mysql_select_db("acinquemani_applications") or die("Unable to select database"); //select which database we're using $query = "select * from contacts where id = '$getid' "; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); $title = $row["lname"]; $title2 = $row["fname"]; $profile = $row["ID"]; echo "Hi!$title2 $title $getid $title.) <a href=edit.php?id=$profile>$title2 $title </a> <br>" ; When I put the $getid in the echo part of the code by itself, that comes through ok, but the variables after the query are still just blank. Thanks in advance to anyone that can help! Osyrys Server: Localhost via UNIX socket Server version: 5.0.92-community-log Protocol version: 10 User: acinquemani@localhost MySQL charset: UTF-8 Unicode (utf8) Web server cpsrvd 11.28.87 MySQL client version: 5.0.92 PHP extension: mysql Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/ Share on other sites More sharing options...
Muddy_Funster Posted May 2, 2011 Share Posted May 2, 2011 echo $getid, and $_GET['id'] and see what you get. Check the URL structure. change your query to: $query = "select lname, fname, ID from contacts where id = '$getid' "; Change the line here $numresults=mysql_query($query); to include error capture like this : $numresults=mysql_query($query) or die ($query.'<br><br> FAILED WITH THE FOLLOWING ERROR :<br><br>'.mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209330 Share on other sites More sharing options...
osyrys14 Posted May 2, 2011 Author Share Posted May 2, 2011 Already tried just selecting certain tables, thanks for the reply, but I use SELECT * in my database queries cause I only put the information in each table that I need from that query... I'm not a newbie, just been looking at the code too long and looking for a second set of eyes... Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209337 Share on other sites More sharing options...
mikosiko Posted May 2, 2011 Share Posted May 2, 2011 your code doesn't shows any sentence and/or logic to read/process the query resultset . Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209376 Share on other sites More sharing options...
osyrys14 Posted May 2, 2011 Author Share Posted May 2, 2011 your code doesn't shows any sentence and/or logic to read/process the query resultset . Could be my eyes as mentioned before, but isn't that what I'm doing here.... $query = "select * from contacts where id = '$getid' "; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209381 Share on other sites More sharing options...
trq Posted May 2, 2011 Share Posted May 2, 2011 You have not defined $row anywhere. See http://php.net/mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209396 Share on other sites More sharing options...
osyrys14 Posted May 2, 2011 Author Share Posted May 2, 2011 You have not defined $row anywhere. See http://php.net/mysql_fetch_assoc From original post.... $title = $row["lname"]; $title2 = $row["fname"]; $profile = $row["ID"]; Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209408 Share on other sites More sharing options...
PFMaBiSmAd Posted May 2, 2011 Share Posted May 2, 2011 That's not defining $row. That's attempting to reference $row and it does not exist. Did you bother to read the information at the mysql_fetch_assoc link that thorpe posted? It contains an example that shows how you would execute a query and fetch the data that the query returns. Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209410 Share on other sites More sharing options...
osyrys14 Posted May 2, 2011 Author Share Posted May 2, 2011 Yes, I did read it, and like I said before, I'm not a newbie, just been looking at this for close to 24 hours straight and know I'm missing something and needed another set of eyes... I know I'm new on this forum, and I appreciate the replies... Maybe some sleep is on order on my part and reload all the messages and files to see what I'm missing... Osyrys Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209411 Share on other sites More sharing options...
osyrys14 Posted May 2, 2011 Author Share Posted May 2, 2011 Freakin' really.... Thanks guys, I couldn't sleep till I figured it out... One stupid line fixed it all, I owe you a beer next time you're in Chicagoland... (we need a "feeling stupid" smiley LOL) Quote Link to comment https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/#findComment-1209417 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.