parse error AGAIN!!!!

so I’m working on a PHP page to upload an image to my server and store the image path in MySQL and I keep getting the following error.

Parse error: syntax error, unexpected ‘mysql_query’ (T_STRING) in C:\xampp\htdocs\beta\tests\image_upload.php on line 53

and here is line 53 for the above error.

[php] mysql_query(“INSERT INTO uploaded_images (ImgData) VALUES (” . $location . “)”); [/php]

I’ve searched on this for hours and have tried all suggestions, checked my spelling and what I think is proper punctuation and can’t find out what I’m doing wrong.

This error would be a problem on the line before it. Likely missing a semi-colon ;

That’s crazy, it was exactly that, the line before it was missing the semi colon, added it and fixed a missing curly brace and I’m good to go. You’re amazing Matt, I should be paying you for fixing my mistakes. lol I said should! ;D Thanks again for saving my sanity!

Ok EVERY time I think I’ve figured it out and got it working something goes wrong.
So below is the entire code for uploading and image and storing it in a folder and setting the path to the image in MySQL. After fixing the parse errors posted earlier I was able to get the form to show and select and image and submit it with no errors, it appeared to work perfectly as it looked as if it submitted the images then reset the page for a new image to be submitted. After checking the upload folder it was empty and the database tables is empty as well, Now, all I get is a blank white page when I attempt to call up the page in a browser. Any suggestions? [php]

Upload <?php require "../dbconnect/portal_connect.php";

//Select database, database_name
mysql_select_db(“image_test”);

if(isset($_POST[‘uploaded’])) {
//If nothing has been uploaded display the form
?>

Upload:



<?php }else{ //The image is named after the persons IP address until it gets moved into the database //get users IP $ip=$_SERVER['REMOTE_ADDR']; //don't continue if an image hasn't been uploaded if (isset($_POST['image'])){ $image = $_POST['image']; //copy the image to directory $path = "upload/images"; move_uploaded_file($image,$path); //store the name and path. $location = $path . "/" . $image; $mysql_query ("INSERT INTO uploaded_images (ImgData) VALUES (" . $location . ")"); } } ?> [/php]

Is this right?

[php]if(isset($_POST[‘uploaded’])) { [/php]

Why would you display a form if a form is already posted?

Shouldn’t it be

[php]if(!isset($_POST[‘uploaded’])) { [/php]

Thanks again Matt, that was it, I must have deleted the ! when I was experimenting with things, as for the display form comment, I can’t explain that, it’s not my code it was posted as a tutorial and hasn’t worked from the start. It’s frustrating as I’m doing my best to learn this but finding good working examples or tutorials is nearly impossible it seems. Every tutorial I’ve watched and tried out the examples don’t work correctly, for example this code will now display the form after some tweaking but it looks as though it still doesn’t work as I can select the image and click upload and the form disappears and I once again have a white screen and nothing i my db or in the upload folder. I’m ready to give up!

You just need to take your time and learn the basics first.

[php]$mysql_query (“INSERT INTO uploaded_images (ImgData) VALUES (” . $location . “)”);[/php]

This is not a variable, remove the $. Also add error reporting.

[php]mysql_query (“INSERT INTO uploaded_images (ImgData) VALUES (” . $location . “)”)or die(mysql_error());[/php]

A blank page is also to be expected since you do not output anything after uploading. So perhaps:

[php]
$res = mysql_query(“INSERT INTO uploaded_images (ImgData) VALUES (” . $location . “)”)or die(mysql_error());
echo ($res ? “Success” : “Failed”);
[/php]

Matt is there a way to debug my code as I go along? I remember seeing something somewhere about being able to use something like debug () stop or something like that at each variable and see what is being output?

If you want to learn this is where you should start:

http://www.php.net/manual/en/language.basic-syntax.php

Go through each one of these sections on the left, and all the sub-sections.

Types, variables, constants, etc. I promise you will learn A LOT :slight_smile:

Not necessarily. You can do things like echo a variable or print_r an array (or var_dump whatever you want) then use exit(). For example:

[php]
$location = $path . “/” . $image;

// debug
echo $location;
exit;
[/php]

could be a simple $ missing at start of line 53, i have also had problems with double quotes inside double quote and found single quotes work

so if the ! was missing from isset in the above should isset always be !isset? is the below code incorrect as well?
[php]if (isset($_POST[‘image’])){
$image = $_POST[‘image’];
[/php]

I don’t even see !isset shown in the php manual here http://php.net/manual/en/function.isset.php

! means “not”

So the translation of !isset would be that isset() does not return true. For example:

[php]
if (isset($myVar)) // if true
if (!isset($myVar)) // if false
[/php]

They don’t have an example here but you can find the ! operator here:
http://www.php.net/manual/en/language.operators.logical.php

! $a Not TRUE if $a is not TRUE.

Sponsor our Newsletter | Privacy Policy | Terms of Service