關於PHP更新資料庫解決辦法

來源:互聯網
上載者:User
關於PHP更新資料庫
本帖最後由 UR_Not_Alone 於 2013-06-03 11:55:36 編輯

剛開始學PHP遇到一些基礎問題請大家幫忙
從網上看的一個例子,做了下練習。
我填好頁面內容點擊提交時,頁面預設開啟insert.php,而不是執行insert.php中代碼插入資料庫是怎麼回事啊。
代碼如下
Html頁面




無標題文檔






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;
}
?>


另外,如果我想實現上傳圖片的功能該怎麼做啊,求提供思路,如果有人有例子最好了,謝謝大家

分享到:


------解決方案--------------------
include("connect_mysql.php");
mysql_open();
------解決方案--------------------
php環境配好了沒有,檔案有沒有放入web伺服器根目錄下,怎麼訪問的?
------解決方案--------------------
,問題出現在連結資料庫上,
連結資料庫函數有問題,注釋掉下面的函數部分就可以直接執行了!
//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;
//}
------解決方案--------------------
如果 id 是主鍵,那麼因為主鍵不能重複,你向其賦 max(id) 顯然是不對的!應為 max(id) + 1
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.