2017-04-25 160 views
-1

我一直得到不能通过参考传递参数2,虽然名称在形式,变量类型是好的。 我看过其他人的病例,他们似乎很合理,但我无法在这里找到我的错误。connot通过参数传递参数

$sid = $_POST['staff_id']; 
 
$sname = $_POST['staff_name']; 
 
$sgender = $_POST['gender']; 
 
$sdob = $_POST['staff_dob']; 
 
$sbranch = $_POST['branch']; 
 
$stell = $_POST['tel_no']; 
 
$position = $_POST['position']; 
 
$salary =$_POST['salary']; 
 
$login = $_POST['staff_login']; 
 
$password = $_POST['staff_password']; 
 
} 
 
else{  
 
$stmt = $mysqli->prepare("INSERT INTO 
 
       staff (staff_id, staff_name, gender, staff_dob, branch, tell_no, position, salary, staff_login, staff_password) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 
 
$stmt->bind_param('ssssssiiss', '$sid', '$sname', '$sgender', '$sdob', '$sbranch', '$stell', '$position', '$salary', '$login', '$password'); 
 

这里是我的HTML表单:

 <form method="post" action=""> 

     <input type="text" name="staff_id" placeholder="your given ID"> 
     <input type="text" name="staff_name" placeholder="Full Name"/> 
     <label class="formlabel">Your gender:</label> 
     <input type="text" name="gender" placeholder="male/female"> 
     <label class="formlabel"><b>Date of Birth:</b></label> 
     <input type="date" name="staff_dob"> 
     <input type="text" name="branch" placeholder="Your branch ID"> 
     <input type="tel" name="tel_no" placeholder="your telephone number"> 
     <label class="formlabel"><b>Your position</b></label> 
     <select name="position"> 
     <option value="1"> Asisstant</option> 
     <option value="2"> Supervisor</option> 
     <option value="3"> Manager</option> 
     </select> 
     <input type="number" name="salary" placeholder="your salary ammount"> 
     <input type="text" name="staff_login" placeholder="Make your new login"> 
    <input type="password" name="staff_password" placeholder="Enter your new password"> 
     <button type="submit" name="btn-register" value="submit">Register</button> 
    </form> 
+0

还有''sid''这是错误的,而不是使用'$ sid'而不是引号 –

+0

sqli之前的其他功能是什么?你需要这些后变量,它看起来像... – clearshot66

+0

当然,谢谢你,你是对的 –

回答

0

删除 '' 周围所有的变量。那是什么意思是,你不能在一个参考变量传递它需要有bind_param

$stmt->bind_param('ssssssiiss', $sid, $sname, $sgender, $sdob, $sbranch, $stell, $position, $salary, $login, $password); 

你为什么在$ _ POST变量将也有mysqli的前一个else价值?

+0

我试图解决问题之前,它使我做了一些重定位,现在得解决这个错误。 –

+0

也非常感谢,thas解决了这个问题! –

+0

没问题:)! – clearshot66

-1

您必须了解字符串变量之间的差异。

变量不是字符串。并应写入不含引号。