Why does php $result from mysql_query() have bool-type but no value? Won't INSERT to mysql -
i have simple php script adds value $_get['lightstate'] mysql db.
connection database successful, , error-handling sql statement doesn't show problem.
since sql statement of "insert" type, expect boolean in response per http://www.php.net/mysql_query
for other type of sql statements, insert, update, delete, drop, etc, mysql_query() returns true on success or false on error.
when open php live session, can see $result has bool-type, no value.
i had been able query post db once, have no been able replicate result...
here's code as-is...thanks in advance.
<?php # setup connection info $servername = "localhost"; $username = [username]; $password = [password]; $dbname = "esp8266"; # set data table , connect db $lightstate = $_get['lightstate']; $conn = mysql_connect($servername, $username, $password); # check connection , abort if not connected if(!$conn) { die('could not connect: ' . mysql_error()); } # write data db (date , lightstate table, lightstatus) $datenow = date('y-m-d'); $sql = sprintf("insert lightstatus (logdate,lightstate) values ('%s',$lightstate)", mysql_real_escape_string($datenow)); echo $sql, "\n"; //just check statement correct $result = mysql_query($sql); if(!result) { die('invalid query: ' . mysql_error()); } # let me know posted data & close db echo "<h1>the data has been sent!</h1>\n"; mysql_close($conn); ?> edit: when run php live session, i'm running on local machine (raspi running lamp-server).
Comments
Post a Comment