我正在尝试为我的网站制作一个消息传递系统。我在我的处理程序php文件(处理msg的发送)中有这个代码:
if($actions=="verstuur"){
//read variables
$naar = $_POST['naar'];//varchar in database. the post = 'ikdekker
$van = $username;//varchar in database. the username = 'user1'
$status = "0";//int in database
if ($_POST['admin'] != ""){
$admin = $_POST['admin'];}else{
$admin=2; //int in database. the post = '0 or 1'
}
$onderwerp = $_POST['onderwerp'];//varchar in database. the post = 'example'
$bericht = $_POST['berichtl'];//varchar in database. the post = 'example message'
$tijd=date("Y-m-d H:i:s");//timestamp in database. the post = '2014-18-1 20:20:20'
// enter is enter
$bericht=nl2br($bericht);
$bericht=eregi_replace("\n","",$bericht);
mysql_query($conn, "INSERT INTO pm (van,naar,status,admin,onderwerp,tijd,bericht) VALUES ('$van','$naar','$status','$admin', '$onderwerp','$tijd','$bericht')");
echo"<script>";
echo"alert('". $actions . "');";
echo "</script>";
}
但它一直给我这个错误:
警告:mysql_query()期望参数1为字符串,资源在第34行的/home/deb70377/domains/cowboycombat.nl/public_html/misc/php/pm_verwerk.php中给出
无法弄清楚,我通常会做html ..
答案 0 :(得分:1)
您不应该使用mysql *函数,因为它们已被弃用。使用mysqli *:
mysqli_query($conn, "INSERT INTO pm (van,naar,status,admin,onderwerp,tijd,bericht) VALUES ('$van','$naar','$status','$admin', '$onderwerp','$tijd','$bericht')");
另请考虑使用预先准备好的陈述http://lt1.php.net/pdo.prepared-statements
UPADTE
获取你写的$ conn变量:
$conn = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
答案 1 :(得分:0)
先查询,然后查询$ conn变量