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
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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";