Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-25-2012, 07:46 PM   PM User | #1
loopsnhoops
New Coder

 
Join Date: Aug 2011
Posts: 24
Thanks: 6
Thanked 0 Times in 0 Posts
loopsnhoops is an unknown quantity at this point
Exclamation MYSQL error (confused)

Hi,

I am trying to create an upload file system to my mysql database and I keep getting the same error message. Can you take a quick look and help please?

Thanks, Eric

HTML FORM

Code:
<form action="show.php" method="post" enctype="multipart/form-data">
	
	IB2: 
	<input type=radio name="grade" value="IB2" />
	<br />
	IB1: 
	<input type=radio name="grade" value="IB1" />
	<br />
	FY: 
	<input type=radio name="grade" value="FY" />
	<br />
	Y2: 
	<input type=radio name="grade" value="Y2" />
	<br />
	Y1: 
	<input type=radio name="grade" value="Y1" />
	<br />
	<input type=file method=post enctype=multipart/form-data /> 
	<input type=submit name="submitb" value="Upload File" />
	
</form>
PHP CODE (show.php)

PHP Code:
<?php

$TheGrade 
$_POST['grade'];
$name $_FILES['file']['name'];
$type $_FILES['file']['type'];
$size $_FILES['file']['size'];
            
$Server="xxxx";
$User="xxxx";
$Password="xxxx";
$Database="db1083186_Files";

if(
$TheGrade==IB2){

$gradetable="IB2FILES";
    
} elseif(
$TheGrade==IB1){

$gradetable="IB1FILES";
    
} elseif(
$TheGrade==FY){

$gradetable="FYFILES";
    
} elseif(
$TheGrade==Y2){

$gradetable="Y2FILES";
    
} elseif(
$TheGrade==Y1){

$gradetable="Y1FILES";
    
} else {
    
    echo 
"Connection error: No grade submission";
    
$gradetable=null;
    echo 
$gradetable;
    
}

$connection mysql_connect($Server$User$Password);
if(!
$connection){
    die(
"Couldn't Connect" mysql_error());
}
echo 
"Connection Working";
echo 
$TheGrade;    
echo 
$name;    
echo 
$type;    
echo 
$size;    

mysql_select_db($Database$connection);

$query "INSERT INTO " $gradetable " (name,type,size) VALUES (" $name "," $type "," $size ")";

$table mysql_query($query,$connection) or die(mysql_error());  



// echo "<table border='1'>";
// echo "<tr> <th>id</th> <th>name</th> </tr>";
// // keeps getting the next row until there are no more to get
// while($row = mysql_fetch_array( $query )) {
    // // Print out the contents of each row into a table
    // echo "<tr><td>"; 
    // echo $row['id'];
    // echo "</td><td>"; 
    // echo $row['name'];
    // echo "</td></tr>"; 
// }  

// echo "</table>";
            
?>
ERROR MESSAGE:

Connection WorkingY1 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 1
loopsnhoops is offline   Reply With Quote
Old 04-25-2012, 08:04 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
The problem is how you are building your INSERT query. Each value needs to be enclosed in single quotes (except columns that are integers, doubles, floats and decimals), and because you are not including these quotes in the string, the last value of " " is causing a syntax error with your query. Your query looks like this:

Code:
INSERT INTO tablename (name,type,size) VALUES (Y,1,)
It needs to look like this:

Code:
INSERT INTO tablename (name,type,size) VALUES ('Y','1',' ')
Whenever you run into a syntax error like this, echo out the _actual_ query (the string where you've put all the variables in) and the error will most likely jump right out at you.

PHP Code:
$query "INSERT INTO " $gradetable " (name,type,size) VALUES (" $name "," $type "," $size ")";

$table mysql_query($query,$connection);
if (!
$table)
{
    die(
"SQL Error! Query is $query<br />Error is ".mysql_error());

__________________

Last edited by Fumigator; 04-25-2012 at 08:06 PM..
Fumigator is offline   Reply With Quote
Users who have thanked Fumigator for this post:
loopsnhoops (04-26-2012)
Old 04-25-2012, 09:59 PM   PM User | #3
loopsnhoops
New Coder

 
Join Date: Aug 2011
Posts: 24
Thanks: 6
Thanked 0 Times in 0 Posts
loopsnhoops is an unknown quantity at this point
Hi,

Thanks for the reply and advice so far. I did what you said and I got the same error unfortunately.

Here it is:

Connection Working IB1 SQL Error! Query is INSERT INTO IB1FILES (name,type,size) VALUES (,,)
Error is 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 1



I think the problem is that the code isn't filling the file variables with information. Is this a reasonable thought?

Last edited by loopsnhoops; 04-25-2012 at 10:01 PM.. Reason: Thoughts
loopsnhoops is offline   Reply With Quote
Old 04-25-2012, 11:24 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
A reasonable thought. What did your debug code show?
Code:
echo "Connection Working";
echo $TheGrade;    
echo $name;    
echo $type;    
echo $size;
???

Incidentally, that would be really hard to figure out what is/isn't working, as written.

Better:
Code:
echo "Connection Working<br/>";
echo "grade: $TheGrade <br/>";    
echo "name: $name <br/>"
echo "type: $type <br/>"
echo "size: $size <hr/>"
And you *REALLY* should follow the advice Fumigator gave you.

To wit: If the name and/or type fields in your DB is a string type (e.g., VARCHAR or CHAR) then you *MUST* have apostrophes around their values.
Code:
$query = "INSERT INTO " . $gradetable . " (name,type,size) "
      . " VALUES ('" . $name . "','" . $type . "'," . $size . ")";
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
loopsnhoops (04-26-2012)
Old 04-26-2012, 12:54 AM   PM User | #5
loopsnhoops
New Coder

 
Join Date: Aug 2011
Posts: 24
Thanks: 6
Thanked 0 Times in 0 Posts
loopsnhoops is an unknown quantity at this point
Yay, you guys helped me get the SQL error out of the way. The problem of the missing data in the variables $name, $type and $size remains though. When I use the echo function on them nothing appears leaving me to believe the transfer of information from my html form to the php script was void.

Sorry for continuing the thread but if you help me with just this one problem I will award thanks virtually and in reality.
loopsnhoops is offline   Reply With Quote
Old 04-26-2012, 01:07 AM   PM User | #6
loopsnhoops
New Coder

 
Join Date: Aug 2011
Posts: 24
Thanks: 6
Thanked 0 Times in 0 Posts
loopsnhoops is an unknown quantity at this point
MUAHAHAHHAHAHA THANKS FOR THE HELP BUT I FINALL FIXED IT!!! retard mistake :S I didn't write
Code:
name="file"
in my input file form



thanks for all the help guys!
loopsnhoops is offline   Reply With Quote
Reply

Bookmarks

Tags
error, file, php, sql, upload

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:07 AM.


Advertisement
Log in to turn off these ads.