Why does echo fail when an SQL statement is inserted?
function execute_data($sql){$result = @mysql_query($sql) or die(mysql_error());@mysql_free_result($result) or die(mysql_error());return $result;}
$sql = "insert into test(name) values('$name')"; if(execute_data($sql)) { echo 'ok';}
In this way, the insert statement has been executed and inserted into the database table, but echo has not been output to the webpage .. Why?
If you execute a query statement using other methods, echo can be output to the web page.
How to execute a query statement
function get_js_array($sql){$result = @mysql_query($sql) or die(mysql_error());$arr = array();while($row = @mysql_fetch_array($result, MYSQL_ASSOC)){$arr[] = $row; }$js = json_encode($arr);mysql_free_result($result);return $js;}
Reply to discussion (solution)
The returned value of the execute_data function $ result is released by the function mysql_free_result. if it is returned, it is null.
Print the $ result to see if it is false.
Print the $ result to see if it is false.
It's not false. I have successfully inserted them. Only echo output is unavailable.
Mysql_free_result
Are you still returning after you release them?
Mysql_query ($ SQL) only returns logical values for the insert command
Therefore, mysql_free_result ($ result) returns an error: $ result is not a valid resource.
However, you have blocked the php error message, while die (mysql_error () only terminates the program because the SQL command does not make a mistake (mysql_error () returns an empty string)
Mysql_query ($ SQL) only returns logical values for the insert command
Therefore, mysql_free_result ($ result) returns an error: $ result is not a valid resource.
However, you have blocked the php error message, while die (mysql_error () only terminates the program because the SQL command does not make a mistake (mysql_error () returns an empty string)
So what can I do to let him output it?
Comment out @ mysql_free_result ($ result) or die (mysql_error ();
Comment out @ mysql_free_result ($ result) or die (mysql_error ();
Thank you!