Reputation:
At the moment I'm trying to add a new feature to my gallery. Basically in the galleries listings are cover photos and I'd like to allow myself to select a cover photo through the site without having to manually add the image address to my gallery table.
At the moment I have this code below and I seem to be getting an error although I'm not too sure what's causing it, whether it's the posting a variable - I'm not too sure :S.
The code is supposed to use the url parameter to grab all necessary information from the gallery table and images table. I've also create the $imgurl variable which displays the image url to be inserted into the gallery table. The $galleryid variable is used to determine where the main column should be updated by adding the image url. It then connects and updates the gallery table by setting the 'main' column value to the image url already retrieved above, where the gallery id equals the $galleryid variable also gained above.
The error I'm receiving:
Failed to run query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7
<?php
require "../../resources/includes/common.php";
include "../../resources/includes/image-retrieval.php";
$imgurl = htmlentities($row['url'], ENT_QUOTES, 'UTF-8');
$galleryid = htmlentities($row['gallery'], ENT_QUOTES, 'UTF-8');
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$id = $_GET['id'];
mysql_select_db("database", $con);
$sql="UPDATE gallery SET main='$imgurl' WHERE id='$galleryid'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header("Location: ../../image.php?id=" . $id);
die("Redirecting to: image.php");
mysql_close($con);
?>
Any help would be much appreciated as I don't know where to go from here :S!
Upvotes: 0
Views: 44
Reputation: 37233
your query looks right
please try verifiy your variables those which are inside your query if they give right values
$imgurl , $galleryid
try echo them before the query and see what they give
Upvotes: 1