Jump to content

PHP SQL Error and I dont get it


ThunderAI

Recommended Posts

I admit this isn't really just a PHP problem, but it does have PHP elements to it.  Here is my problem.

 

I have an SQL statement that works and will submit data to the MYSQL table, BUT MySQL gives an error message.  Any ideas?

 

Here is the error statement:

 

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 'files/1/KATY.csv', user_f_rows = '42' WHERE user_f_id = '1' ] ')' at line 1

 

the sql statement print out is:

 

SQL is [[[ UPDATE tbl_users_files SET user_f_name = 'files/1/KATY.csv', user_f_rows = '42' WHERE user_f_id = '1' ]]]

 

 

This error happens reguardless if i am overwiting an exisiting file or not.  It does add the new record to the DB with all of the right information.

 

here is the code:

 

<?
else {
								$objrs_support = mysqli_query($objconn_support, $sql);
								if ($objrs_support) {
										$number_of_rows = mysqli_num_rows($objrs_support);
										if ($number_of_rows == 0) {
												// There are no records, so this is a new entry
												$sql2 = "INSERT INTO tbl_users_files (user_f_name,user_f_rows, user_f_parent_id) VALUES ( '".$target_path."', '".$rowcounter."', '".$tmp_userid."' )";
											}
										while ($objfields = mysqli_fetch_array($objrs_support, MYSQLI_ASSOC)) {
												$tmp_user_f_id = $objfields['user_f_id'];
												$sql2 = "UPDATE tbl_users_files SET user_f_name = '".$target_path."', user_f_rows = '".$rowcounter."' WHERE user_f_id = '".$tmp_user_f_id."' ";
												echo "SQL is [[[ ".$sql2." ]]]";
											}
									}
							}
						//echo $sql2;
						$mysqli = mysqli_connect("-", "-", "-", "-");				
						if (mysqli_connect_errno()) {
								// there was an error trying to connect to the mysql database
								printf("connect failed: %s\n", mysqli_connect_error());
								exit();
							}		
							else {
								$objrs = mysqli_query($mysqli, $sql2) or die(mysqli_error($mysqli));
								//printf("Last inserted record has id %d\n", LAST_INSERT_ID());
								//echo mysql_insert_id($mysqli);
								}
						$function = "Uploaded a new User CSV file with SQL Statement [ ".$sql2." ] ";
						put_systemactivity($_SESSION["user_id"],$function);
						?>

 

Please pardone the code, im not a great programmer, just a programmer.

Link to comment
Share on other sites

strange.  does the query work if you run it from console or PMA or whatever administration tool you have installed?  also, does it work if you drop the user_f_name from that (ie. just update the user_f_rows)?

 

The SQL works without error when entereted into PHPMyAdmin. If the user uploads a file with a different name i need to save the name of the file, so I dont see how removing the name will benefit me.

 

Tried it again this morning and I get the same error.

Link to comment
Share on other sites

i was suggesting that not as a final solution, but just to check whether it's that specific parameter that's causing the error.

 

as far as i can tell, there's no error - could just be a mysqli extension issue; how does it do if you switch to regular mysql_query()?  (obviously you'll need to change the connection functions).

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.