PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
include('design/header.php');
require('connect.php');
$albumid = $_SESSION['album'];
$id = $_SESSION['id'];
// find location of the photo
$image = mysql_query("SELECT * FROM items WHERE userid='$id' AND albumid='$albumid'");
echo "$image";
while ($row = mysql_fetch_assoc($image))
{
$location = $row['location'];
echo "Album Cover Change, Succes! Go Back To <a href=albums.php>Albums</a>.";
$setcover = mysql_query("UPDATE albums SET cover = '$location'
WHERE userid = '$id' AND id = '$albumid'") or die("Error While Changing your album's cover.Please Try Again.");
}
?>
The echo "$image"; Is there just to test what is getting out from that query... and there is where the Resource id #5 is coming... any help?
Last edited by Weirdan on Tue Nov 23, 2010 12:05 pm, edited 1 time in total.
Reason:[code] -> [syntax=php]
Celauran wrote:You can't echo an SQL result. What is it you're trying to do?
I am tring to update an database record... the first query is using to take some data's to use them in the UPDATE query...but the first query fails and the second is getting the Resource id #5 as result and using it to fill the data's...
Since the second query depends on the first, it's guaranteed to fail if the first fails. Have you tried the first query manually? Does that work? Can you paste the exact error you're getting?
Celauran wrote:Since the second query depends on the first, it's guaranteed to fail if the first fails. Have you tried the first query manually? Does that work? Can you paste the exact error you're getting?
Well Look, I Will post you the whole code, and an screen with the result...
<?php
include('design/header.php');
require('connect.php');
$albumid = $_SESSION['album'];
$id = $_SESSION['id'];
// find location of the photo
$image = mysql_query("SELECT * FROM items WHERE userid='$id' AND albumid='$albumid'");
echo "$image";
while ($row = mysql_fetch_assoc($image))
{
$location = $row['location'];
echo "Album Cover Change, Succes! Go Back To <a href=albums.php>Albums</a>.";
$setcover = mysql_query("UPDATE albums SET cover = '$location'
WHERE userid = '$id' AND id = '$albumid'") or die("Error While Changing your album's cover.Please Try Again.");
}
?>
Screen
Last edited by Weirdan on Tue Nov 23, 2010 12:06 pm, edited 1 time in total.
Reason:[code] -> [syntax=php]
That's not an error you're seeing, that's the result of echo $image. If it's not echoing the success message, though, then it looks like it's not entering the while loop. What does var_dump($image) display?
Last edited by Celauran on Mon Nov 22, 2010 9:31 am, edited 1 time in total.
Celauran wrote:That's not an error you're seeing, that's the result of echo $image.
Yeap, i know that... but i say that it's error cuz it's not normal, i mean the action is to take some data and echo them, well the data wassen't Recurce id #5 but it's echoing Recurce id #5 ... So pretty much error?
Anyway... thing is not if it's error or not... any help to fix that?
m1nistry wrote:
Yeap, i know that... but i say that it's error cuz it's not normal, i mean the action is to take some data and echo them, well the data wassen't Recurce id #5 but it's echoing Recurce id #5 ... So pretty much error?
Anyway... thing is not if it's error or not... any help to fix that?
No, that is normal. $image is defined as the result of a MySQL query, which is a resource. You are echoing a resource, which is why you are seeing that.
Celauran wrote:Have you echoed the query to make sure all fields have values assigned properly? What about echo mysql_num_rows($image)?
s992 wrote:
m1nistry wrote:
Yeap, i know that... but i say that it's error cuz it's not normal, i mean the action is to take some data and echo them, well the data wassen't Recurce id #5 but it's echoing Recurce id #5 ... So pretty much error?
Anyway... thing is not if it's error or not... any help to fix that?
No, that is normal. $image is defined as the result of a MySQL query, which is a resource. You are echoing a resource, which is why you are seeing that.
i don't realy care about echoing the result, i just need to don't get resource id #5 so the UPDATE query take the right VALUES...
m1nistry wrote:i don't realy care about echoing the result, i just need to don't get resource id #5 so the UPDATE query take the right VALUES...
As has already been explained, you're getting the resource id #5 'error' specifically because you're trying to echo an SQL result. Comment out the line echo $image and that will stop being displayed.
m1nistry wrote:i don't realy care about echoing the result, i just need to don't get resource id #5 so the UPDATE query take the right VALUES...
As has already been explained, you're getting the resource id #5 'error' specifically because you're trying to echo an SQL result. Comment out the line echo $image and that will stop being displayed.
You can't undestund what i am saying... even if i don't echo the result the query takes "Recurce id #5" as data and import them!
<?php
session_start();
require 'connect.php';
echo '<pre>';
echo "This is what I found in the session:\n";
print_r($_SESSION);
echo "\n";
$continue = true;
if (! isset($_SESSION['album'])) {
echo "I found no session key named 'album'.\n";
$continue = false;
}
if (! isset($_SESSION['id'])) {
echo "I found no session key named 'id'.\n";
$continue = false;
}
if (! $continue) {
echo "I cannot continue.\n";
} else {
echo "I found the two session keys I need.\n\n";
$query = sprintf(
"SELECT * FROM items WHERE userid = '%s' AND albumid = '%s'",
mysql_real_escape_string($_SESSION['album']),
mysql_real_escape_string($_SESSION['id'])
);
echo "I am going to run this query:\n";
echo $query, "\n\n";
$result = mysql_query($query);
echo "The result of the query is ";
var_dump($result);
echo "The string representation is '$result'\n\n";
if (is_resource($result)) {
$numRows = mysql_num_rows($result);
printf("The result set has %d row(s).\n\n", $numRows);
if ($numRows > 0) {
$rows = array();
echo "I will now fetch the row(s).\n";
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
echo "I found this data:\n";
print_r($rows);
}
}
}
echo '</pre>';