Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在向数据库发送0个值_Php_Mysql - Fatal编程技术网

Php 正在向数据库发送0个值

Php 正在向数据库发送0个值,php,mysql,Php,Mysql,我创建了第一个将数据发送到数据库的ajax脚本。但有一个问题,在新的created行中有0个值。在Firebug中,我可以看到php文件中有这些值 Parametersapplication/x-www-form-urlencodedDo not sort currentTasken 1415 currentUser 37 Source currentUser=37&currentTasken=1415 但不知何故,他们无法访问数据库,这是我的php文件 <?php $c

我创建了第一个将数据发送到数据库的ajax脚本。但有一个问题,在新的created行中有0个值。在Firebug中,我可以看到php文件中有这些值

Parametersapplication/x-www-form-urlencodedDo not sort
currentTasken   
1415
currentUser 
37
Source
currentUser=37&currentTasken=1415
但不知何故,他们无法访问数据库,这是我的php文件

<?php
$currentUser = isset($_POST['$currentUser']);
$currentTasken = isset($_POST['$currentTasken']);
    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    if(!$con)
        die('Could not connectzzz: ' . mysql_error());
    mysql_select_db("foxi" , $con) or die ("could not load the database" . mysql_error());

    $check = mysql_query("SELECT * FROM dotp_task_log");
    $numrows = mysql_num_rows($check);
    if($numrows >= 1)
    {
        //$pass = md5($pass);

            $ins = mysql_query("INSERT INTO dotp_task_log (task_log_creator, task_log_Task) VALUES ('$currentUser' , '$currentTasken')" ) ;

       if($ins)
            die("Succesfully Created Log!");

        else
            die("ERROR");

    }
    else
    {
        die("Log already exists!");
    }

?>

您的代码中有两个bug

$currentUser = isset($_POST['$currentUser']);
1:我相信你错了,你的意思是:

$currentUser = isset($_POST['currentUser']);
2:
isset
是一个函数,在变量定义和设置与否的情况下返回布尔值。因此,
$currentUser
变量现在保存的是布尔值(0或1),而不是发布数据的值

您应该这样使用它:

$currentUser = isset($_POST['currentUser']) ? $_POST['currentUser'] : '';
这是
if-else
条件的简短版本。 如果设置了
$\u POST['currentUser']
,变量
$currentUser
应保持其值,否则-它将有一个空字符串

进一步说明:

  • 请记住,您应该清理
    $\u POST
    数据
  • 您正在使用已弃用的
    mysql.*
    。考虑使用<代码> MySqLI:/CODE >或<代码> PDO < /代码>。<李>
不客气。如果有帮助,请考虑接受我的回答。我需要等3分钟:
$currentUser = isset($_POST['currentUser']) ? $_POST['currentUser'] : '';