Home > Backend Development > PHP Tutorial > 关于PHP更新数据库解决办法

关于PHP更新数据库解决办法

WBOY
Release: 2016-06-13 12:47:19
Original
962 people have browsed it

关于PHP更新数据库

本帖最后由 UR_Not_Alone 于 2013-06-03 11:55:36 编辑 刚开始学PHP遇到一些基础问题请大家帮忙
从网上看的一个例子,做了下练习。
我填好页面内容点击提交时,页面默认打开insert.php,而不是执行insert.php中代码插入数据库是怎么回事啊。
代码如下
Html页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<title>无标题文档</title><br />
</head><br />
<body><br />
<form action="insert.php" method="post" target="win"><br />
请输入新闻的title:<input type="text" name="title" /><br />
请选择新闻类型:<select name="c_id"><option value="1">体育</option><option value="2">娱乐</option></select><br />
<br /><br />
请输入新闻的content:<br /><br />
<textarea cols="60" rows="15" name="content"></textarea><br />
<input type="submit" value="提交" /><br />
</form><br />
</body><br />
</html>
Copy after login


insert.php
<?php<br />
include("connect_mysql.php");<br />
$q = "insert into new(title,content,time,news_cate_id) values('".$_POST["title"]."','".$_POST["content"]."',now(),".$_POST["c_id"].")";<br />
mysql_query($q);<br />
if(mysql_affected_rows()>0) echo "xinwentianjiachenggong!";<br />
?><br />
<hr /><br />
<a href="add_news.php" target="win">fanhuijixutianjiaxinwen</a>
Copy after login


connect_mysql.php
<?php<br />
function mysql_open()<br />
{<br />
$mysql_servername="localhost"; //<br />
$mysql_username="root";<br />
$mysql_password="11111";<br />
$mysql_dbname="new";<br />
<br />
$conn=mysql_connect($mysql_servername ,$mysql_username ,$mysql_password);<br />
      mysql_query("set names UTF8"); //UTF8<br />
      mysql_select_db($mysql_dbname , $conn);<br />
	  return $conn;<br />
}<br />
?>
Copy after login


另外,如果我想实现上传图片的功能该怎么做啊,求提供思路,如果有人有例子最好了,谢谢大家
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template