Jump to content

Recommended Posts

I keep getting the mysql resource id #4 on a query that I am running and I have tried everything that I have read to fix it and nothing is working. I tried using the mysql_fetch_array, mysql_fetch_accoc, and the mysql_fetch_row functions

 

I would appreciate any help that can be given to me.

 

Here is my code as it stands now

<?php

include('includes/config.php');

$last = $_GET['l_name'];
$first = $_GET['f_name'];

$sql = 'SELECT * FROM `ttmautos` WHERE `l_name` LIKE \'$last\' AND `f_name` LIKE \'$first\''; 
$autographs = mysql_query($sql, $connection)or die(mysql_error()); 
$row = mysql_fetch_array($autographs); 

echo $sql;
echo $autographs;

$l_name = $row['l_name'];
$f_name = $row['f_name'];
$sent = $row['date_sent'];
$return = $row['date_return'];
$address = $row['address'];
$isent = $row['item_sent'];
$ireturn = $row['item_return'];
$project = $row['project'];
$team = $row['team'];

$address = stripslashes($address);

?>

It is not showing any of the fields that I am trying to get information from. I was echoing out the $autographs query to see what the results are.

 

Every row should post information pertaining to that certain field onto a web page and I am not getting anything. Just the resource id

 

Sorry if I was not clear enough in  the first posting.

 

You're not reading the reply.  A result set resource is not a variable you can do anything with.  It is only used to support other functions that actually retrieve data from the result set (which is stored on the server). 

 

The variable in your script that actually has data is $row.

I modified the code to look like this now and I am still not getting any results.... What am I doing wrong?

 

<?php

include('includes/config.php');

$last = $_GET['l_name'];
$first = $_GET['f_name'];

$sql = 'SELECT * FROM `ttmautos` WHERE `l_name` LIKE \'$last\' AND `f_name` LIKE \'$first\''; 
$autographs = mysql_query($sql)or die(mysql_error()); 

while ($row = mysql_fetch_assoc($autographs)) {
$l_name = $row['l_name'];
$f_name = $row['f_name'];
$sent = $row['date_sent'];
$return = $row['date_return'];
$address = $row['address'];
$isent = $row['item_sent'];
$ireturn = $row['item_return'];
$project = $row['project'];
$team = $row['team'];
}

$address = stripslashes($address);

?>

where are you echoing - $team, $project, $address  etc etc?

 

I am doing it further down in the page. That was just the script that I wrote. Here is the full code of everything

 

<?php

include('includes/config.php');

$last = $_GET['l_name'];
$first = $_GET['f_name'];

$sql = 'SELECT * FROM `ttmautos` WHERE `l_name` LIKE \'$last\' AND `f_name` LIKE \'$first\''; 
$autographs = mysql_query($sql)or die(mysql_error()); 

while ($row = mysql_fetch_assoc($autographs)) {
$l_name = $row['l_name'];
$f_name = $row['f_name'];
$sent = $row['date_sent'];
$return = $row['date_return'];
$address = $row['address'];
$isent = $row['item_sent'];
$ireturn = $row['item_return'];
$project = $row['project'];
$team = $row['team'];
}

$address = stripslashes($address);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Michael48060's Autographs - <?php echo "$f_name"; ?> <?php echo "$l_name"; ?> Autograph</title>
</head>
<body>
<div id="wrapper">
         <h6>Information</h6>
         <ul>
            <li><span class="header_two">Player Name</span> – <?php echo "$f_name"; ?> <?php echo "$l_name"; ?></li>
            <li><span class="header_two">date sent</span> – <?php echo "$sent"; ?></li>
            <li><span class="header_two">date return</span> – <?php echo "$return"; ?></li>
            <li><span class="header_two">address used</span> – <?php echo "$address"; ?></li>
            <li><span class="header_two">item sent</span> – <?php echo "$isent"; ?></li>
            <li><span class="header_two">item return</span> – <?php echo "$ireturn"; ?></li>
            <li><span class="header_two">project</span> – <?php echo "$project"; ?></li>
            <li><span class="header_two">team</span> – <?php echo "$team"; ?></li>
         </ul>
   </div>
   <!--End #content-->
</div>
<!-- End #wrapper -->
</body>
</html>

I changed the sql code and added the error message but I am still getting no results or errors

 

<?php

include('includes/config.php');

$last = $_GET['l_name'];
$first = $_GET['f_name'];

$sql = "SELECT * FROM ttmautos WHERE l_name LIKE '$last' AND f_name LIKE '$first' "; 
$autographs = mysql_query($sql);
if (!$autographs) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

while ($row = mysql_fetch_assoc($autographs)) {
$l_name = $row['l_name'];
$f_name = $row['f_name'];
$sent = $row['date_sent'];
$return = $row['date_return'];
$address = $row['address'];
$isent = $row['item_sent'];
$ireturn = $row['item_return'];
$project = $row['project'];
$team = $row['team'];
}

$address = stripslashes($address);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Michael48060's Autographs - <?php echo "$f_name"; ?> <?php echo "$l_name"; ?> Autograph</title>
</head>
<body>
<div id="wrapper">
         <h6>Information</h6>
         <ul>
            <li><span class="header_two">Player Name</span> – <?php echo "$f_name"; ?> <?php echo "$l_name"; ?></li>
            <li><span class="header_two">date sent</span> – <?php echo "$sent"; ?></li>
            <li><span class="header_two">date return</span> – <?php echo "$return"; ?></li>
            <li><span class="header_two">address used</span> – <?php echo "$address"; ?></li>
            <li><span class="header_two">item sent</span> – <?php echo "$isent"; ?></li>
            <li><span class="header_two">item return</span> – <?php echo "$ireturn"; ?></li>
            <li><span class="header_two">project</span> – <?php echo "$project"; ?></li>
            <li><span class="header_two">team</span> – <?php echo "$team"; ?></li>
         </ul>
   </div>
   <!--End #content-->
</div>
<!-- End #wrapper -->
</body>
</html>

This seems to indicate that your query is valid, but that the result set is empty.

 

echo out your $sql and use a tool like phpMyAdmin to double check it.

 

One other thing.. using the technique you're using, you will only ever see the last row, because you fetch all the rows in a loop, then only seem to go to display logic on the last row fetched.

 

Just for quick testing, inside the fetch loop you could put in:

 

var_dump($row);

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.