PHP database update solution

Source: Internet
Author: User
For PHP database update, this post was last edited by UR_Not_Alone from 2013-06-0311: 55: 36. I encountered some basic problems in learning PHP. please refer to the example on the Internet, I have done some exercises. When I fill in the page content and click submit, insert. php is opened by default on the page, instead of executing insert. p on PHP to update the database
This post was edited at 11:55:36 on by UR_Not_Alone at the beginning of learning PHP. I have encountered some basic problems. please help me.
I read an example from the internet and did some exercises.
When I fill in the page content and click submit, insert. php is opened by default on the page, instead of executing the insert. php code to insert the database.
The code is as follows:
Html page




Untitled Document






Insert. php
 include("connect_mysql.php");
$q = "insert into new(title,content,time,news_cate_id) values('".$_POST["title"]."','".$_POST["content"]."',now(),".$_POST["c_id"].")";
mysql_query($q);
if(mysql_affected_rows()>0) echo "xinwentianjiachenggong!";
?>

fanhuijixutianjiaxinwen


Connect_mysql.php
 function mysql_open()
{
$mysql_servername="localhost"; //
$mysql_username="root";
$mysql_password="11111";
$mysql_dbname="new";

$conn=mysql_connect($mysql_servername ,$mysql_username ,$mysql_password);
      mysql_query("set names UTF8"); //UTF8
      mysql_select_db($mysql_dbname , $conn);
  return $conn;
}
?>


In addition, if I want to implement the image upload function, please provide ideas. if someone has an example, it would be better. thank you!
Share:
------ Solution --------------------
Include ("connect_mysql.php ");
Mysql_open ();
------ Solution --------------------
If the php environment is ready, is the file stored in the root directory of the web server? how can I access it?
------ Solution --------------------
, The problem occurs on the connected database,
If there is a problem with linking database functions, you can directly execute the function part that has been commented out below!
// Function mysql_open ()
//{
$ Mysql_servername = "localhost ";//
$ Mysql_username = "root ";
$ Mysql_password = "11111 ";
$ Mysql_dbname = "new ";
 
$ Conn = mysql_connect ($ mysql_servername, $ mysql_username, $ mysql_password );
Mysql_query ("set names UTF8"); // UTF8
Mysql_select_db ($ mysql_dbname, $ conn );
// Return $ conn;
//}
------ Solution --------------------
If id is the primary key, it is obviously incorrect to assign max (id) to it because the primary key cannot be repeated! Max (id) + 1

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.