2017-04-25 224 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

您必須瞭解字符串變量之間的差異。

變量不是字符串。並應寫入不含引號。