我有使用php + mysql將消息添加到數據庫的任務。 我在html中創建了表單並創建了php腳本,但沒有任何效果。它重定向我的PHP文件,我看不到任何東西只有空白頁.Inn地址線需要PhP + MySql幫助
本地主機/ Twitter的/ lib目錄/ addTweet.php
我沒有任何變化在我的數據庫表中。 請幫我解決我的問題。謝謝。
HTML
<form action="lib/addTweet.php" method="post">
<textarea class="m_twitt" name="t_message" placeholder=" Write your twitt there."/></textarea><br>
<input class="fright" type="submit" name="addTweet" value="Add"/>
</form>
比索
<?
session_start();
include "connect.php";
if(!empty($_POST['t_message'])){
if(isset($_POST['addTweet'])){
$userId = $_SESSION['userId'];
$tweet = $_POST['t_message'];
// $curTime = date("Y-m-d H:i:s");
// $query = mysql_query("INSERT INTO `111212_tweets` (`user_id`,`text`,`pubdate`) VALUES ('$userId','$tweet','$curTime')",$connect) ;
$query = mysql_query("INSERT INTO `111212_tweets` (`user_id`,`text`) VALUES ('$userId', '$tweet'");
if (!$query){
die('Error: ' . mysql_error());
}else{
header('Location: ../main.php');
}
}
}else{
// header('Location: ../index.php');
echo 'KOLOBOK';
}
你可以粘貼文件「connect.php」的內容嗎? – Pouki
<?php $ connect = mysql_connect('localhost','root','')或die(mysql_error()); mysql_select_db('tweeter'); ?> – vladja
只是因爲沒有人提到棄用的方法... http://bit.ly/1dFCkWP ...或sql注入和準備語句... http://bit.ly/19sv0Pb – Strawberry