简体   繁体   English

PHP生成的表单名称不发布?

[英]php generated form name not posted?

I am trying to make a messaging system for my site. 我正在尝试为我的站点创建消息传递系统。 I have this code in my handler php file (which processes the sending of msg): 我的处理程序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>";
}

but it keeps giving me this error: 但它一直给我这个错误:

Warning: mysql_query() expects parameter 1 to be string, resource given in /home/deb70377/domains/cowboycombat.nl/public_html/misc/php/pm_verwerk.php on line 34 警告:mysql_query()期望参数1是字符串,在第34行的/home/deb70377/domains/cowboycombat.nl/public_html/misc/php/pm_verwerk.php中给出的资源

cant figure it out, I normally do the html.. 无法弄清楚,我通常做的HTML。

You should not use mysql* functions as they are deprecated. 您不应该使用mysql *函数,因为它们已被弃用。 Use mysqli* ones: 使用mysqli *的:

mysqli_query($conn, "INSERT INTO pm (van,naar,status,admin,onderwerp,tijd,bericht)         VALUES ('$van','$naar','$status','$admin', '$onderwerp','$tijd','$bericht')");

Also consider using prepared statements http://lt1.php.net/pdo.prepared-statements 还可以考虑使用准备好的语句http://lt1.php.net/pdo.prepared-statements

UPADTE UPADTE

to get the $conn variable you write: 得到你写的$ conn变量:

$conn = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');

首先查询,然后查询$ conn变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM