-1

I am trying to connect to a MySQL database using PHP, but I am getting 32767 error reporting in the console. I tried to show the error message using echo error_reporting() but it is not showing the error message.

Here is the code:

$name = $_POST[name];
$topic = $_POST[topic];
$tell = $_POST[tell];
$birthDay = $_POST[birthDay];
$job = $_POST[job];
$email = $_POST[email];
$lastMajor = $_POST[lastMajor];
$major = $_POST[major];
$add = $_POST[add];
$today = "test";

$connectionString = mysqli_connect("localhost","root","root","myDB");
 if (mysqli_connect_errno()) 
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($connectionString,"INSERT INTO coWork (topic , name , tell , birthDay , job , email , lastMajor , major, add , date )
     VALUES ('$topic', '$name','$tell','$birthDay','$job' , '$email' , '$lastMajor' , '$major' , '$add' , '$today')");

mysqli_close($connectionString);
echo error_reporting();

How can I get the content of the error message?

Majid khalili
  • 520
  • 1
  • 4
  • 24
  • 6
    `error_reporting` doesn't report errors, it sets/gets error reporting _level_. – georg Sep 09 '14 at 11:01
  • 2
    I don't think I can explain it better than [the manual](http://php.net/manual/en/function.error-reporting.php). – georg Sep 09 '14 at 11:07
  • 4
    **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Sep 09 '14 at 11:07
  • Georg ,thanks for the link , of course u can't ;) i read that , how should i know what does 32767 means , as it being reported in the browser when i run the code ?!! – Majid khalili Sep 09 '14 at 11:13
  • 2
    Also look at [Predefined Constants](http://php.net/manual/en/errorfunc.constants.php). You'll see that 32767 is E_ALL. (PHP 5.4) – bitWorking Sep 09 '14 at 11:16
  • I don't get it :-? when i run this , in the browser 32767 shows , and the record is not in my DB is there any way that i can track it to get whats going on ?!!!! as i looked again , when i set error reporting level to 32767 it shows any error that happens on the browser , is that true ? if so why record is not saved in the DB , and there isn't any error reporting on the browser page ?!!!!! – Majid khalili Sep 09 '14 at 11:20
  • `error_reporting` `[...]Returns the old error_reporting level or the current level if no level parameter is given.[...]` `[...]The available error level constants and the actual meanings of these error levels are described in the predefined constants.[...]` (the link _bitWorking_ gave you) – t.niese Sep 09 '14 at 11:21
  • what is the reason you are trying to echo error_reporting() function ? read about the function, this isn't the way you should use it. – Nitsan Baleli Sep 09 '14 at 11:23
  • as i looked again , when i set error reporting level to 32767 it shows any error that happens on the browser , is that true ? if so why record is not saved in the DB , and there isn't any error reporting on the browser page ?!!!!! OK , Then , i don't echo the return value of the error reporting function , but still i can't save the record into DB – Majid khalili Sep 09 '14 at 11:30
  • `E_ALL`(32767) reports all php related errors (wether this will be in the browser or just in a log file depends on the settings). Anyway a php code that does not report an error does not guarantee that e.g. a row is inserted into the database. You need to check the error message of you mysql connection [mysqli_error](http://php.net/manual/de/mysqli.error.php). – t.niese Sep 09 '14 at 11:32

1 Answers1

3

error_reporting() => Sets which PHP errors are reported

To get/handle errors you have to use functions like error_get_last or set_error_handler

In your case you want to get the MySql error, so you have to use mysqli_error or mysqli_errno

if (!mysqli_query($connectionString, 'INSERT ...')) {
    printf("Error: %s\n", mysqli_error($connectionString));
}

Like Quentin noted you are vulnerable to SQL injection attacks. So please use mysqli_real_escape_string or mysqli_prepare.

bitWorking
  • 12,485
  • 1
  • 32
  • 38
  • it was really use full i got it , but now that i change the code to what you said , i get 1064 error number , which means syntax error , any idea where I'm being wrong ? – Majid khalili Sep 09 '14 at 12:06
  • @Majidkhalili probably you have some bad characters in your post vars. This is another reason to better use `mysqli_real_escape_string` or `mysqli_prepare` – bitWorking Sep 09 '14 at 12:21
  • i finally find the reason , it was because of the add column , i just changed it to address and everything works fine ; Thanks all guys ;) – Majid khalili Sep 09 '14 at 12:37