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