Jump to content

MySQL query error in php


rmail2006

Recommended Posts

Im trying to upload an image to my server and then copy information to a MySQL database.

 

this is my code that isnt working.

 

<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h1>Uploading file...</h1>
<?php
include_once("./include/config.php");

db_connect();
if ($_FILES['userfile']['error'] > 0)
{
  echo 'Problem: ';
  switch ($_FILES['userfile']['error'])
  {
   case 1: echo 'File exceeded upload_max_file_size'; break;
   case 2: echo 'File exceeded max_file_size'; break;
   case 3: echo 'File only partially uploaded'; break;
   case 4: echo 'No File Uploaded'; break;
  }
  exit;
}
// Does the file have the right MIME type?





//Put the file where we'd like it
$upfile = './images/'.time().$_FILES['userfile']['name'] ;
$tmpfile = $_FILES['userfile']['tmp_name'] ;
$imgloc = $_POST['imglocation'];
echo $upfile;
echo '<br /><b>';
echo $imgloc;
echo '</b><br />';

if (is_uploaded_file($tmpfile))
{
  if (!move_uploaded_file($tmpfile, $upfile))
  {
   echo 'Could not move file to destination';
   exit;
  }
}
else
{
  echo 'Possible File Upload Attack. Filename: ';
  echo $_FILES['userfile']['name'];
  exit;
}
$date = date("Y-m-d");
$sqlresult = mysql_query ("INSERT INTO `photos` (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc'");
if (!$sqlresult){
  die('<br />Invalid Query: ' . mysql_error());
  };
  
echo '<div align="center">';
echo 'File uploaded successfully<br /><br />';
echo '<b>Preview: </b><br />';
echo '<img border="2" src="'.$upfile.'" width="30%" >';
echo '</div>';

?>
</body>
</html>

 

can n e 1 help plz ?  ;D

Link to comment
https://forums.phpfreaks.com/topic/156247-mysql-query-error-in-php/
Share on other sites

move the " outside the ), ie.

$sqlresult = mysql_query ("INSERT INTO `photos` (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc')");

you should use an editor with syntax highlighting .. will help you to track these problems.

Change this line:

 

$sqlresult = mysql_query ("INSERT INTO `photos` (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc'");

 

To this:

 

$sqlresult=mysql_query("INSERT INTO photos (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc')");

 

Edit: Oops, too late. :)

Archived

This topic is now archived and is closed to further replies.

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