我从html页面将数据分配到我的数据库表时遇到错误

时间:2016-03-03 05:35:06

标签: php html mysql

这是我的php代码,我在插入数据的行警告请提供答案

                if($_POST['submitted'] == 1){

                    $q = "INSERT INTO user(fullname,email,password,conform-password,mobileno) VALUES ('$_POST[form-full-name]','$_POST[form-email]','$_POST[form-password]','$_POST[form-conform-password]','$_POST[form-mobile-no]')";

                    $r= mysqli_query($dbc,$q); 

                    if($r){

                        echo '<p>you are REGISTERED SUCCESSFULLY !</p>';
                    }
                    else{

                        echo '<p>your REGISTRATION FAILED !</p>'.mysqli_error($dbc);
                        echo '<p>'.$q.'</p>';
                    }

                }

enter image description here

//&#34; plz给我解决我的问题&#34;

  

块引用

4 个答案:

答案 0 :(得分:1)

如果您不想分配变量以便不进行内存分配,那么您可以尝试使用它:

           <?php

            if($_POST['submitted'] == 1){

                  $q = "INSERT INTO user(`fullname`,`email`,`password`,`conform-password`,`mobileno`) VALUES (?,?,?,?,?)";

                  $stmt = $mysqli->prepare($q);

                    if ( false===$stmt ) {

                    die('prepare() failed: ' . htmlspecialchars($mysqli->error));
                    }

                  $rc = $stmt->bind_param("sssss",  $_POST['form-full-name'], $_POST['form-email'], $_POST['form-password'], $_POST['form-conform-password'],$_POST['form-mobile-no']);


                  if ( false===$rc ) {

                      die('bind_param() failed: ' . htmlspecialchars($stmt->error));
                    }

                  $rc = $stmt->execute();
                    if ( false===$rc ) {
                      die('execute() failed: ' . htmlspecialchars($stmt->error));
                    }

                   $stmt->close();


            }

根据此示例,您必须在表字段中使用手机号码数据类型作为字符串。

不需要在表格中保存确认密码,您应该使用prepare语句进行插入。在这种情况下,它会使您的查询安全插入

答案 1 :(得分:0)

试试这个

 if($_POST['submitted'] == 1)
{

  $full_name =$_POST['form-full-name'];
  $form_email=$_POST['form-email'];
  $password = $_POST['form-password'];
  $conform_pass=$_POST['form-conform-password'];
  $mobile =$_POST['form-mobile-no'];

  $q = "INSERT INTO user(fullname,email,password,conform-password,mobileno) VALUES ('$full_name','$form_email','$password','$conform_pass','$mobile')";

  $r= mysqli_query($dbc,$q); 

  if($r)
  {

   echo '<p>you are REGISTERED SUCCESSFULLY !</p>';
  }
  else{

    echo '<p>your REGISTRATION FAILED !</p>'.mysqli_error($dbc);
    echo '<p>'.$q.'</p>';
      }

    }

您错过了单引号$_POST['']方法

答案 2 :(得分:0)

Just try saving your posted form data to php variable and then use that in   your insert query.

For ex: 

$fullname = $_POST['form-full-name'];
$email = $_POST['form-email'];
$password = $_POST['form-password'];
$confirmpassword = $_POST['form-conform-password'];
$mobilenumber = $_POST['form-mobile-no'];

And then the query as 


$q = "INSERT INTO user(fullname,email,password,conform-password,mobileno) VALUES ('$fullname','$email ','$password ','$confirmpassword ','$mobilenumber ')";


Hope this help.

答案 3 :(得分:0)

感谢所有人的回复 我解决了那个我犯了2个错误的问题 1)使用&#34; - &#34;,我用_ underscore替换(例如:form_email) 2)我使用了isset()函数 在更改了以上两件事之后,我在数据库中获取数据