Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL adding variable

    Hi first post here.
    This is my first real experience with PHP and MySQL. I have the following code which allows me to put information from a form into my database.
    However I'm having trouble importing one thing. Here is my code.
    Code:
            $item="$_POST[item]";
    	$price="$_POST[price]";
    	$description="$_POST[description]";
    	$picture2=$_FILES['uploadedfile']['name'];
    	
    	
    	$sql="INSERT INTO items (Name, Description, Price, Button, pic)
    	VALUES
    	('$item','$description','$price','$button',../upload/uploads/$picture2)";
    
    	if (!mysql_query($sql,$con))
    	  {
    	  die('Error: ' . mysql_error());
    	  }
    	echo "Thankyou, You have just added $_POST[item] to the database";
    I want it to post the file name of the image but also with the "../upload/uploads/"on the beginning of it.
    All other items enter fine into the database but i get this error
    http://img407.imageshack.us/my.php?image=print.jpg
    does anyone have any ideas?
    Thanks all

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Can you attach the file showing the error? I am blocked from getting to imageshack. Or just copy/paste the text of the error.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,548
    Thanks
    77
    Thanked 4,382 Times in 4,347 Posts
    Not a PHP person, at all, but just looking at the pattern you have there I would say you are simply missing the surrounding apostrophes:
    Code:
    $sql="INSERT INTO items (Name, Description, Price, Button, pic)
    	VALUES ('$item','$description','$price','$button','../upload/uploads/$picture2')";

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Nevermind, I see your problem-- each string in the query needs to be enclosed in single quotes; you're missing single quotes around the last string.

    PHP Code:
    $sql="INSERT INTO items (Name, Description, Price, Button, pic)
        VALUES
        ('$item','$description','$price','$button','../upload/uploads/$picture2')"


  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,548
    Thanks
    77
    Thanked 4,382 Times in 4,347 Posts
    Fumigator: Just says there's a syntax error in the SQL
    near '/upload/uploads)'
    **************

    Added: LOL! Too little too late! Story of my life.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,548
    Thanks
    77
    Thanked 4,382 Times in 4,347 Posts
    FWIW: You could also solve it thus:
    Code:
    ...
    	$picture2="../upload/uploads/" . $_FILES['uploadedfile']['name'];
    	
    	
    	$sql="INSERT INTO items (Name, Description, Price, Button, pic)
    	VALUES ('$item','$description','$price','$button','$picture2')";
    Assuming I am understanding what's going on in the PHP code.

  • #7
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys worked like a charm


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •