Reputation: 3
I have a user reg form which then inserts into the db however its throwing up a bind param error
if(isset($_POST['submit'])){
// Login Query
// Connection
$mysqli = new mysqli("localhost", "root", "", "pg");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
// Query
$query = "INSERT INTO `affiliates` (aid,affname,title,fname,lname,add1,add2,add3,city,county,country,pcode,email,password,paymethod) VALUES (,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('ssssssssssssss',$_POST['affname'],$_POST['title'],$_POST['fname'],$_POST['lname'],$_POST['add1'],$_POST['add2'],$_POST['add3'],$_POST['city'],$_POST['county'],$_POST['country'],$_POST['pcode'],$_POST['email'],$_POST['password'],$_POST['paymethod']); // If 2x Variables are used etc 's' would become 'ss',$_GET['VAR'],$_GET['VAR']
// Bind Results
$stmt->execute();
//$result = $stmt->get_result()->fetch_all();
}
I cant work out whats wrong can anyone help thanks
Updated Form & Query Code
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<p>
<label for="textfield"></label>
<input type="text" name="affname" id="textfield" />
</p>
<p>
<label for="textfield"></label>
<input type="text" name="title" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="fname" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="lname" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="add1" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="add2" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="add3" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="city" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="county" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="country" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="pcode" id="textfield" />
</p> <p>
<label for="textfield"></label>
<input type="text" name="email" id="textfield" />
</p>
<p>
<label for="textfield"></label>
<input type="text" name="password" id="textfield" />
</p>
<p>
<label for="textfield"></label>
<input type="text" name="paymethod" id="textfield" />
<input type="hidden" value="" name="aid" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</form>
<?php
if(isset($_POST['submit'])){
// Login Query
// Connection
$mysqli = new mysqli("localhost", "root", "", "pg");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
// Query
$query = "INSERT INTO `affiliates` (aid,affname,title,fname,lname,add1,add2,add3,city,county,country,pcode,email,password,paymethod) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('sssssssssssssss',$_POST['aid'],$_POST['affname'],$_POST['title'],$_POST['fname'],$_POST['lname'],$_POST['add1'],$_POST['add2'],$_POST['add3'],$_POST['city'],$_POST['county'],$_POST['country'],$_POST['pcode'],$_POST['email'],$_POST['password'],$_POST['paymethod']); // If 2x Variables are used etc 's' would become 'ss',$_GET['VAR'],$_GET['VAR']
// Bind Results
$stmt->execute();
//$result = $stmt->get_result()->fetch_all();
}
I have amended the query and now have the correct amount of vars being passed However it now shows NO errors but also does not insert the data
Upvotes: 0
Views: 3474
Reputation: 939
As your aid is autocremented just change the query to this, no need to insert it in the query.
$query = "INSERT INTO affiliates (affname,title,fname,lname,add1,add2,add3,city,county,country,pcode,email,password,paymethod) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Upvotes: 0
Reputation: 4038
you trying to insert 15 columns
1)aid
2)affname
3)title
4)fname
5)lname
6)add1
7)add2
8)add3
9)city
10)county
11)country
12)pcode
13)email
14)password
15)paymethod
but here you are metioning only 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14
,?,?,?,?,?,?,?,?,?,?, ?, ?, ?, ?
s s s s s s s s s s s s s s
as well as here only 14
$_POST['affname'],$_POST['title'],$_POST['fname'],$_POST['lname'],$_POST['add1'],$_POST['add2'],$_POST['add3'],$_POST['city'],$_POST['county'],$_POST['country'],$_POST['pcode'],$_POST['email'],$_POST['password'],$_POST['paymethod']
Upvotes: 0
Reputation: 4772
Change
$query = "INSERT INTO `affiliates` (aid,affname,title,fname,lname,add1,add2,add3,city,county,country,pcode,email,password,paymethod) VALUES (,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
to :
$query = "INSERT INTO `affiliates` (aid,affname,title,fname,lname,add1,add2,add3,city,county,country,pcode,email,password,paymethod) VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
or to
$query = "INSERT INTO `affiliates` (affname,title,fname,lname,add1,add2,add3,city,county,country,pcode,email,password,paymethod) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Upvotes: 1