开发者

Updating table with POST from external program

i have an external program which sends some data VIA POST to my server. I know the data is being sent because i echo the POST and its fine. but when i add an INSERT INTO query it doesnt work. here is my code: id = int (primary key), home,mob = double, the rest are varchar. Thanks in advanced.

<?php
$mysqli = new mysqli('####','###','###','user');
if (mysqli_connect_errno()) {
  printf("Can't connect to SQL Server. Error Code %s\n",       mysqli_connect_error($mysqli));
exit;
}
$date   = $_POST['date'];
$desc   = $_POST['desc'];

mysqli->query("INSERT INTO user_info (id, home, mob, type, description, date) VALUES    (NULL,'','','',$desc,$date);");

mysql_real_escape_string($date),
mysql_real_escape_string($suburb));

$mysqli->clo开发者_如何学Gose(); 
?>


Given your error message, you are missing the "$" on your $mysqli->query, corrected code should be:

for additional issues, try to get the SQL that is being sent to the database, and run it on a local query to see if there are SQL errors that you are missing.

<?php
$date   = mysql_real_escape_string( $_POST['date'] );
$desc   = mysql_real_escape_string( $_POST['desc'] );

$query =<<<SQLQUERY
     INSERT INTO user_info 
              (home, mob, type, description, date) 
        VALUES    
              ('',   '',  '',   $desc,       $date)
SQLQUERY;

// Can you print out or get the value for $query?

$mysqli->query($query);

$mysqli->close();
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜