Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/235328-variables-empty-on-db-query/
Share on other sites

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());

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...

 

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);

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.