0

I have put together what I think is a simple addition to a php form-processing script (to insert data in a database, after sending it through to an email).

For some reason, I always get the error message, and the actual input of the data never gets through to the database. I've added the query to the output, and all the received values seem alright.

Thanks in advance.

// username, passw, database are all defined earlier in code.
// all the variables are taken out of form inputs (and they all arrive fine by email.
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

//inserting data order
$order = "INSERT INTO flights('restime', 'flyfrom', 'flyto', 'dateoutbound', 'outboundflex', 'datereturn', 'returnflex', 'pax', 'klasse', 'name', 'email', 'phone', 'comments', 'status') VALUES('$date', '$fly_from', '$fly_to', '$date_outbound', '$outbound_flex', '$date_return', '$return_flex', '$pax', '$class', '$name', '$email', '$phone', '$comments', '1')";

//declare in the order variable
$result = mysql_query($order);  //order executes
if($result){
    echo("<br>Input data is succeed");
} else{
    echo("<br>Input data is fail");
    echo $order;
}

Thanks a lot in advance.

3 Answers3

0

You should not use the single quotes for fields in the query. if you use the backticks, then you don't get error. Just like the following

You must use the mysql_error() function to check the error in the query. Check the below code.

I have found one more issue. You have to use single quotes around the hostname in mysql_connect function. This also may cause error.

I have used the following code. It is working fine for me.

<?php mysql_connect('localhost','root','');
@mysql_select_db('test') or die( "Unable to select database");





//inserting data order
$order = "INSERT INTO testone (`restime`, `flyfrom`, `flyto`, `dateoutbound`, `outboundflex`, `datereturn`, `returnflex`, `pax`, `klasse`, `name`, `email`, `phone`, `comments`, `status`) VALUES('$date', '$fly_from', '$fly_to', '$date_outbound', '$outbound_flex', '$date_return', '$return_flex', '$pax', '$class', '$name', '$email', '$phone', '$comments', '1')";

//declare in the order variable
$result = mysql_query($order) or die(mysql_error());  //order executes
if($result){
    echo("<br>Input data is succeed");
} else{
    echo("<br>Input data is fail");
    echo $order;
}
Ananth
  • 1,520
  • 3
  • 15
  • 28
  • Thanks for your response. I just did that (see above). But it's not working yet. – S Weinberger Aug 19 '13 at 13:43
  • I'm not sure whose answer really did it, I put in many recommended edits at once :) My reputation isn't high enough to give you +1 yet, but I'll come back for it, I promise! – S Weinberger Aug 19 '13 at 14:30
0

Database configuration setting must be like below

$link=mysql_connect(localhost,$username,$password);
@mysql_select_db($database,$link) or die( "Unable to select database"); 

After this you can write your insert query and etc....

sam anderson
  • 130
  • 1
  • 8
0

error is in this query :

$order = "INSERT INTO flights('restime', 'flyfrom', 'flyto', 'dateoutbound', 'outboundflex', 'datereturn', 'returnflex', 'pax', 'klasse', 'name', 'email', 'phone', 'comments', 'status') VALUES('$date', '$fly_from', '$fly_to', '$date_outbound', '$outbound_flex', '$date_return', '$return_flex', '$pax', '$class', '$name', '$email', '$phone', '$comments', '1')";

You are using ' in-spite of using ` for the column name in the table.

use this query and i am sure it will run great

$order = "INSERT INTO testone (`restime`, `flyfrom`, `flyto`, `dateoutbound`, `outboundflex`, `datereturn`, `returnflex`, `pax`, `klasse`, `name`, `email`, `phone`, `comments`, `status`) VALUES('$date', '$fly_from', '$fly_to', '$date_outbound', '$outbound_flex', '$date_return', '$return_flex', '$pax', '$class', '$name', '$email', '$phone', '$comments', '1')";

:)

Rahul
  • 1,181
  • 1
  • 11
  • 20
  • That's good.. there are several ways of saying thanks on stackoverflow if you find answer useful. :) – Rahul Aug 19 '13 at 14:30
  • I know, but I need a higher reputation to do so (see what I wrote above to Ananth). I'll come back once the time is ripe ;) – S Weinberger Aug 19 '13 at 14:37