Jump to content

should be simple mysql query


ldb358

Recommended Posts

this is part of my php script that is responcable for uploading the users files up to my server and stores the information about the file

 

//assume that all the variables are set

<?
$check = mysql_query ("SELECT * FROM '$artistFill' LIMIT 0,1"); 
if($check){
     mysql_query("INSERT INTO '$artistFill' (id, name, sType, fSize, artist) VALUES('NULL', '$nameFill', 'photo', '$sizeFill', '$artistFill');") or die(mysql_error());
}else{
//if table doesnt exsist
mysql_query("CREATE TABLE '$artistFill' (id INT NOT NULL, name VARCHAR( 30 ) NOT NULL ,fType VARCHAR( 30 ) NOT NULL ,fSize INT NOT NULL ,artist VARCHAR( 30 ) NOT NULL ,fDesc TEXT NOT NULL ,rating INT NOT NULL ,PRIMARY KEY (id))") or die("1"); 
mysql_query("INSERT INTO '$artistFill' (id, name, sType, fSize, artist) VALUES('NULL', '$nameFill', 'photo', '$sizeFill', '$artist');") or die("2");
echo "added";				

?>

Link to comment
Share on other sites

I tried, got a 1 which tells us the query failed..

 

mysql_query("CREATE TABLE '$artistFill' (id INT NOT NULL, name VARCHAR( 30 ) NOT NULL ,fType VARCHAR( 30 ) NOT NULL ,fSize INT NOT NULL ,artist VARCHAR( 30 ) NOT NULL ,fDesc TEXT NOT NULL ,rating INT NOT NULL ,PRIMARY KEY (id))") or die("1");

 

Have you tried running this query manually via the mySQL prompt or through phpmyadmin changing the variables to the actual values?

 

Instead of using die("1"); use die(mysql_error()); as this will output the actual error.

Link to comment
Share on other sites

added this

if($check){
			mysql_query("INSERT INTO ".$artistFill." (id, name, fType, fSize, artist) VALUES(NULL, ".$nameFill.", ".photo.", ".$sizeFill.", ".$artistFill.");") or die(mysql_error());
			}else{
			//if table doesnt exsist
			mysql_query("CREATE TABLE ".$artistFill."(id INT NOT NULL, name VARCHAR( 30 ) NOT NULL ,fType VARCHAR( 30 ) NOT NULL ,fSize INT NOT NULL ,artist VARCHAR( 30 ) NOT NULL ,fDesc TEXT NOT NULL ,rating INT NOT NULL ,PRIMARY KEY (id))") or die(mysql_error()); 
			mysql_query("INSERT INTO ".$artistFill." (id, name, sType, fSize, artist) VALUES (NULL, ".$nameFill.", photo, ".$sizeFill.", ".$artist.");") or die(mysql_error());
			echo "added";
			}

 

 

now its saying there is an error with the files im trying to up load "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 'of image.jpg, photo, 56372, lane)' at line 1"

Link to comment
Share on other sites

Your SQL makes no sense. You create the table indicating that the id field can't be null and you put in null for id in your INSERT. :-\

 

For int, don't you have to specify a size?

 

Lastly, keep the SQL you had in your first post, but remove the single quotes around $artistFill.

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.