-2
  • I am using AWS EC2
  • My Security Groups Inbound rules are :

enter image description here

Mysql User Tables is:

mysql> select user,host from mysql.user;

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
  • I can access database by using SELECT, and able to print on php webpages.
  • The Problem is INSERT query.

Code is :

$queryb = "INSERT INTO contact_us (name,contact,email,message) 
           VALUES ('$_POST[contact_person]', 
                   '$_POST[mobile]',
                   '$_POST[email]',
                   '$_POST[messages]')";
if (mysql_query($queryb))
{
    $success='Thank You ';
}
else
{
    $error='Error Occured ! Try after sometime';
}

Need Suggestion !!!

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
helpdoc
  • 1,910
  • 14
  • 36

1 Answers1

2

You will need to check at the error you get while trying to execute that statement. Let's see the problems and possible problems:

Rights

You will need to make sure the MySQL user you try to execute the query with has the necessary rights to do so. Try to hard-code an insert statement along with all parameters. Are you able to do so? Or do you get an error that you do not have the rights to do so?

Deprecation

mysql_ functions are deprecated. You will need to use either mysqli_ functions or PDO.

SQL Injection

Your code has high risks of security due to possibility of SQL Injection. You will need to escape your query via mysqli_real_escape_string or parameterize your query via PDO. If you do not do so, users will be able to damage your database if they want to hack your site, or even steal data.

XSS Injection

Your code has high risks of security due to possibility of XSS injection as well. You will need to make sure no scripts will be injected into your fields unless you explicitly want to allow that. XSS injection is a possible means to steal data from other users.

Is it message or messages

Check what is inside your $_POST["messages"]. Is it an array? If so, you try to use an array as a string and hence you get an exception.

Check your logs

You will need to check the server logs to find the exact problem you face. If server logging is not enabled, then you will need to enable it and run the PHP code again.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175