Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

What does this error mean and do I need to worry about it?

I'm building an insert statement based on the presence of values in several pulldown menus in the preceding page.

It looks like this:

$insert_statement="";
			$handle=fopen("$csv_name", "r");
			$counter=0;
			while ((!$row=fgetcsv($handle))== false) 
			{
			$counter++;
				if($counter>1) //omit the column headings
				{
				//here's where you need to craft your query
				$insert_statement = 'insert into '.$table_name.'(';
				for($i=0; $i<=$_POST['column_count']; $i++)
				{
					if (isset($_POST['select_name_'.$i.'']) && $_POST['select_name_'.$i.'']=="")
					{
					header("location:csv_upload_error.php");
					exit();
					}
					else
					{
						$insert_statement.=$_POST['select_name_'.$i.''];
						if($i<$_POST['column_count'])
						{
							$insert_statement.=',';
						}
						else
						{
							$insert_statement.=', session_id)';
						}
					}
				}
				$insert_statement.=' VALUES (';
				for($i=0; $i<=$_POST['column_count']; $i++)
					{
						$the_row[$i]=$mysqli->real_escape_string($row[$i]);
						$insert_statement .='\'';
						$insert_statement .=$_POST['column_'.$i.''];
						$insert_statement .='\'';
						if($i<$_POST['column_count'])
						{
							$insert_statement.=',';
						}
						else
						{
							$insert_statement .=', \'';
							$insert_statement .="$the_session_id";
							$insert_statement .='\'';
							$insert_statement .=')';
						}
					}
				//echo $insert_statement;	
				//$query=$mysqli->query($insert_statement);
				}
			}
		}
		return $insert_statement;

Open in new window


The good news is that it works. I can print each individual insert statement and verify that it's sound. I can go to the database and see that the data has been correctly inserted.

But at the top of my page, I get this error: Warning: mysqli::query(): Empty query in C:\wamp\www\vbs\upload\csvClass.php on line 268

Line 268 is this guy right here: if(!$query=$mysqli->query($insert_statement))...

I can copy and paste the compiled insert statement into phpMyAdmin and it works fine. Data, everything - good to go. But I keep getting this error and I don't know why.

Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To clarify my thought,  I agree with Dave thinking that it's a function routine. I just think in your script that routine is called more than one time: probably it's called when values are the expected one to execute the query and so the query is executed and record is insertedd in the database and a second time i called when values are not the expected ones so $insert_statement remains empty and you get the warning message.
So perhaps you can investigate if you suppress one of the function calls but if you can't, checking if $insert_statement is empty before to execute it can solve the issue.