Beginners get values from the foreground form input database

Source: Internet
Author: User
Rookie help get values from the foreground form in the input database
PHP Code
  
   $db =mysql_connect (' localhost ', ' root ', ' ', ' news1 '); $query = "INSERT INTO News (title,author,datetime,content) VALUES (' $title ', ' $author ', ' $datetime ', ' $content ');        $result =mysql_query ($query), if ($result) {    echo mysql_affected_rows (). " Row (s) insert into database. ";} else{    echo "An error has occurred. The item is not added. ";}


After entering the relevant value, the result of the output is always an error with occurred. The item is not added what reason should be changed?

Thank you ~



------Solution--------------------
mysql_connect (' localhost ', ' root ', ');

mysql_select_db (' news1 ')
------Solution--------------------
Mysql_connect and Mysqli_connect parameters do not have the same use of specifying a database

You look through the manual,
------Solution--------------------
$db =mysql_connect (' localhost ', ' root ', ') or Die (' database connected to server failed ');
mysql_select_db (' news1 ', $db) or Die (' Database connection failed ');
........
------Solution--------------------
$query = "INSERT INTO News" values (' $title ', ' $author ', ' $datetime ', ' $content ') or Die ( Mysql_error ()) ";

See what you are suggesting.
------Solution--------------------
This problem ... First time Output SQL ...
  • Related Article

    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.