Jump to content

Can't use SQL Quert INSERT INTO and upload an image in the same file


Username:

Recommended Posts

Code I'm using

 

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Successfully uploaded image!";
    if (file_exists("img/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "img/" . $_FILES["file"]["name"]);
      
      echo "<a href='img/$filename'>Your File</a>;
      }
    }
  }
else
  {
  echo "Invalid file";
  }
mysql_query("INSERT INTO $tbl (body, name, subject, ip, timestamp, img) VALUES ('$body', '$name', '$subject', '$ip', '$timestamp', '$imglink')");
mysql_query("INSERT INTO total (ip, subject, name, board) VALUES ('$ip','$subject','$name','$dfg')");
echo "<font color='red'><font size='15'><strong><center>Successfully posted to /$tbl/";
//print("<meta http-equiv='REFRESH' content='0;url=index.php?board=$tbl'>");

If I have the query on the top it runs, and the upload img doesn't

&& vice versa

Link to comment
Share on other sites

I am going to assume that you do not have error_reporting turned on?

 

 error_reporting(E_ALL); ini_set('display_errors',1); 

 

I say this because you have missed a quote in your code.

echo "<a href='img/$filename'>Your File</a>;

 

:)

 

 

 

Link to comment
Share on other sites

I am going to assume that you do not have error_reporting turned on?

 

 error_reporting(E_ALL); ini_set('display_errors',1); 

 

I say this because you have missed a quote in your code.

echo "<a href='img/$filename'>Your File</a>;

 

:)

I fixed the missing quote. Sorry,  typo.

 

"Notice: Undefined variable: subject in /hosted/domains/t/e/testchan.org/public_html/create.php on line 80"

Link to comment
Share on other sites

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.