Why do you insert SQL statements and echo fails?

Source: Internet
Author: User
Tags php error terminates
The way I execute the INSERT statement is
       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, I have executed the INSERT statement so that it has been inserted into the database table, but ECHO has not been exported to the Web page. What's the reason?
echo can be output to a Web page by executing the query statement in a different way.

Methods for executing query statements
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 return value of the function Execute_data $result was freed by the function mysql_free_result and returned is null.

Print out the $result to see if it's fake.

Print out the $result to see if it's fake.



It's not a lie. I've all succeeded in inserting. Just the echo output does not come out.

Mysql_free_result

You've been released, and you've returned?

mysql_query ($sql) returns only logical values for insert Directives
therefore Mysql_free_result ($result) will error: $result is not a valid resource
But you blocked the PHP error message, and Die (Mysql_error ()) just terminates the program because the SQL command is not wrong (mysql_error () returns an empty string)

mysql_query ($sql) returns only logical values for insert Directives
therefore Mysql_free_result ($result) will error: $result is not a valid resource
But you blocked the PHP error message, and Die (Mysql_error ()) just terminates the program because the SQL command is not wrong (mysql_error () returns an empty string)



So what can I do to get him out of the way?

Comment out @mysql_free_result ($result) or Die (Mysql_error ()); This sentence

Comment out @mysql_free_result ($result) or Die (Mysql_error ()); This sentence


Thanks, it's settled!
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.