The beginner obtains the value from the foreground form in the input database.

Source: Internet
Author: User
Cainiao asks for help to obtain the value from the front-end form. in the input database, PHPcode $ db = mysql_connect ('localhost', 'root', '', 'news1'); $ query = & quot; insertintonews (title, author, datetime, content) values ('$ Cainiao asking for help getting value from the front-end 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 was not added.";}


After The related values are input, The output result is always An error has occurred. The item was not added. why should I modify it?

Thank you ~



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

Mysql_select_db ('news1 ')
------ Solution --------------------
If the mysql_connect and mysqli_connect parameters are used differently, the database cannot be specified.

Look at the manual,
------ Solution --------------------
$ Db = mysql_connect ('localhost', 'root', '') or die ('database connection to server failed ');
Mysql_select_db ('news1', $ db) or die ('database connection failed ');
........
------ Solution --------------------
$ Query = "insert into news (title, author, datetime, content) values ('$ title',' $ author', '$ datetime', '$ content ') or die (mysql_error ())";

See what is prompted.
------ Solution --------------------
This problem... Immediately output SQL...

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.