Need MySQL to show errors.

Rad

...
Reaction score
228
I'm uploading around 150 entries each with 18 fields of data to a Database.

The script is all fine, and converted using a program I made with Autoit.

The problem is, once uploaded, the database looks clean but there are only around 120-130 entries, meaning some don't go in there.

I except it to be some fields aren't supporting the value being inserted, for example one field called "Rooms" is an Int, but some fields in the spreadsheet may have "Quad". Although I converted this for all integer fields, some others appear to have a problem with the VarChar(15)'s.

Is there a way to have MySQL queries output a message if they failed so I can figure out lines aren't being accepted?

Here is an example query, although I think showing what each type of field is would be a waste of time if theres a simple "Show Errors" tag you can put in a MySQL query.

Code:
mysql_query('INSERT INTO list (aval, area, city, rms, bth, type, rent, dep, petdep, sec8, cat, dog, wd, ht, gar, address, street, phone, addinfo, state, image, email, ha) VALUES ("Jun, 25", "Southeast", "Eugene", "1", "1", "Apt", "550", "Yes", "Yes", "Yes", "Yes", "Yes", "Site", "NA", "NA", "630", "E. 25th Pl. 8", "555-5000", "Near xxx Park", "Oregon", "NA", "NA", "NA")');

The entire page has all 160 of these. I upload it, and if all goes well the page stays blank. Once and awhile I get a syntax error from an entry with a single quote in it thats easily fixed. Some fields have characters, such as [#, ???] and the 1/2 symbol represented as one character. Are these rejected by the VarChar field?
 

enouwee

Non ex transverso sed deorsum
Reaction score
240
You have to check whether the query succeeds or not.
PHP:
if (mysql_query( /* ... */ ) === false)
{
  print mysql_error();
}
 

ertaboy356b

Old School Gamer
Reaction score
86
PHP:
mysql_query('INSERT INTO list (aval, area, city, rms, bth, type, rent, dep, petdep, sec8, cat, dog, wd, ht, gar, address, street, phone, addinfo, state, image, email, ha) VALUES ("Jun, 25", "Southeast", "Eugene", "1", "1", "Apt", "550", "Yes", "Yes", "Yes", "Yes", "Yes", "Site", "NA", "NA", "630", "E. 25th Pl. 8", "555-5000", "Near xxx Park", "Oregon", "NA", "NA", "NA")') or die(mysql_error());

look at the very end
 

TFlan

I could change this in my User CP.
Reaction score
64
create a function that will be used for every MySQL query, have within this function an escape route to inform the browser of the error.

example:
PHP:
function query($q){
	$result = mysql_query($q);
	if($result!=false){
		return $result;
	}else{
		return mysql_error();
	}
}

code using said example:
PHP:
function page($n){
	$p = $_GET['p'];
	$q = "SELECT contents FROM pages WHERE page = ".$p;
	print(query($query));
}

EDIT::
Forgive me if my syntax is off, has been awhile since I worked with PHP.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top