pahunrepublic Posted July 31, 2010 Share Posted July 31, 2010 I wrote a code with prepared statements MySQLi: <?php include_once 'dbinfo.php'; if(isset($_POST['kuldes'])) { $name = trim($_POST['nev']); $username = $_POST['felh_nev']; $password = $_POST['jelszo']; $email = $_POST['email']; $phone = $_POST['telefon']; $gender = $_POST['sex']; $hobby = $_POST['hobby']; $regfelt = $_POST['regfelt']; $name = strip_tags($name); $name = stripslashes($name); $username = strip_tags($username); $email = strip_tags($email); $phone = strip_tags($phone); $date = date("d-m-Y"); if($name == NULL || $username == NULL || $password == NULL || $email == NULL || $phone == NULL || $gender == NULL) { echo "Please complete the form below or one of the boxes is empty."; } elseif(strlen($username) <= 3 || strlen($username) >= 30){ $final_report.="Your username must be between 3 and 30 characters.."; } elseif($stmt = $connect->prepare('SELECT * FROM users WHERE username=?')) { $stmt->bind_param('s', $username); $stmt->execute(); $stmt->bind_result($username); while ($stmt->fetch()) { printf("Name: %s\n", $name); $final_report.="The username is already in use!"; } $stmt->close(); }elseif(strlen($password) <= 6 || strlen($password) >= 12){ $final_report.="Your password must be between 6 and 12 digits and characters.."; } elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $final_report.="Your email address was not valid.."; } elseif(!eregi("^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$",$phone)){ $final_report.="Phone number is invalid. Only numbers with hyphen. Allowed format: countrycode-areacode-phonenumber"; } elseif(!isset($hobby)){ $final_report.="Youd didn't select any hobbies"; } elseif(!isset($regfelt)){ $final_report.="You didn't accept the terms"; } else { if ($stmt = $connection->prepare('INSERT INTO users(name,sex,email,phone_number,username,password,hobby) VALUES(?, ?, ?, ?, ?, ?, ?)')) { $stmt->bind_param('sssssss', $name, $sex, $email, $phone_number, $username, $password, $hobby); $stmt->execute(); $stmt->close(); } }}?> <h1>Registration Form</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration_form" method="POST"> <p>Name: <input type="text" name="nev" value="<?php echo (isset($name) ? $name : ''); ''?>" size=25></p> <p>Username: <input type="text" name="felh_nev" value="<?php echo (isset($username) ? $username : ''); ?>" size=10></p> <p>Password: <input type="password" name="jelszo" size=10></p> <!--<p>Password again:<input type="password" name="password_confirmation"></p>--> <p>E-mail: <input type="text" name="email" value="<?php echo (isset($email) ? $email : ''); ?>"/></p> <p>Phone number: <input type="text" name="telefon" value="<?php echo (isset($phone) ? $phone : ''); ?>"/></p> <p>Sex: <label><input type="radio" name="sex" value="no" >Female</label> <label><input type="radio" name="sex" value="ferfi" >Male</label></p> <p>Favorite hobbies (Using CTRL you can select more than one):</p> <select name="hobby[]" size="4" multiple> <option value="sport">Sport</option> <option value="mozi">Movies</option> <option value="kirandulas">Hiking</option> <option value="olvasas">Reading</option> </select> <p><input name="regfelt" type="checkbox" value="elfogad">I accept the terms!</p> <p><input name="kuldes" type="submit" value="Submit form"> <input name="reset" type="reset" value="delete"></p> <table width="501" border="1"> <tr> <td><?php echo $final_report; ?></td> </tr> </table> <p> </p> </form> And I get the following error message: Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in I don't understand what's the problem is, many people can't give solution for this? Anyone who can help me? It's brain racking. Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/ Share on other sites More sharing options...
JasonLewis Posted August 2, 2010 Share Posted August 2, 2010 In one place you're using: $connect->prepare() Then further down your page when you're inserting you're using: $connection->prepare() Is it connect or connection? Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1093994 Share on other sites More sharing options...
pahunrepublic Posted August 2, 2010 Author Share Posted August 2, 2010 In one place you're using: $connect->prepare() Then further down your page when you're inserting you're using: $connection->prepare() Is it connect or connection? It's $connect. The content of the dbinfo.php is the following: <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'eunice'; $dbname = 'usersform'; $connect = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if(!$connect) { die('Connection failed: ' . $mysqli->error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1094346 Share on other sites More sharing options...
PFMaBiSmAd Posted August 2, 2010 Share Posted August 2, 2010 elseif($stmt = $connect->prepare('SELECT * FROM users WHERE username=?')) $stmt->bind_result($username); ^^^ You must supply enough variables in bind_result() to match the number of items in the SELECT statement. Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1094351 Share on other sites More sharing options...
pahunrepublic Posted September 7, 2010 Author Share Posted September 7, 2010 I changed the code like this: elseif($stmt = $connect->prepare('SELECT username FROM users WHERE username=?')) But It pops this warning: Wrong parameter count for mysqli_stmt::bind_param() in What could be the problem now If someone gives me any solution please also tell me if you tried the code out? Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108071 Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2010 Share Posted September 7, 2010 bind_param() deals with the replaceable parameters in the query. It would be a little hard to tell you what is wrong with your code without seeing the code that is responsible for the error. Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108077 Share on other sites More sharing options...
pahunrepublic Posted September 7, 2010 Author Share Posted September 7, 2010 bind_param() deals with the replaceable parameters in the query. It would be a little hard to tell you what is wrong with your code without seeing the code that is responsible for the error. Here is my code: <?php include_once 'dbinfo.php'; if(isset($_POST['kuldes'])) { $name = trim($_POST['nev']); $username = $_POST['felh_nev']; $password = $_POST['jelszo']; $email = $_POST['email']; $phone = $_POST['telefon']; $gender = $_POST['sex']; $hobby = $_POST['hobby']; $regfelt = $_POST['regfelt']; $name = strip_tags($name); $name = stripslashes($name); $username = strip_tags($username); $email = strip_tags($email); $phone = strip_tags($phone); $date = date("d-m-Y"); if($name == NULL || $username == NULL || $password == NULL || $email == NULL || $phone == NULL || $gender == NULL) { echo "Please complete the form below or one of the boxes is empty."; } elseif(strlen($username) <= 3 || strlen($username) >= 30){ $final_report.="Your username must be between 3 and 30 characters.."; } elseif($stmt = $connect->prepare('SELECT username FROM users WHERE username=?')) { $stmt->bind_param($username); $stmt->execute(); $stmt->bind_result($username); while ($stmt->fetch()) { printf("Name: %s\n", $name); $final_report.="The username is already in use!"; } $stmt->close(); }elseif(strlen($password) <= 6 || strlen($password) >= 12){ $final_report.="Your password must be between 6 and 12 digits and characters.."; } elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $final_report.="Your email address was not valid.."; } elseif(!eregi("^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$",$phone)){ $final_report.="Phone number is invalid. Only numbers with hyphen. Allowed format: countrycode-areacode-phonenumber"; } elseif(!isset($hobby)){ $final_report.="Youd didn't select any hobbies"; } elseif(!isset($regfelt)){ $final_report.="You didn't accept the terms"; } else { if ($stmt = $connection->prepare('INSERT INTO users(name,sex,email,phone_number,username,password,hobby) VALUES(?, ?, ?, ?, ?, ?, ?)')) { $stmt->bind_param('sssssss', $name, $sex, $email, $phone_number, $username, $password, $hobby); $stmt->execute(); $stmt->close(); } }}?> <h1>Registration Form</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration_form" method="POST"> <p>Name: <input type="text" name="nev" value="<?php echo (isset($name) ? $name : ''); ''?>" size=25></p> <p>Username: <input type="text" name="felh_nev" value="<?php echo (isset($username) ? $username : ''); ?>" size=10></p> <p>Password: <input type="password" name="jelszo" size=10></p> <!--<p>Password again:<input type="password" name="password_confirmation"></p>--> <p>E-mail: <input type="text" name="email" value="<?php echo (isset($email) ? $email : ''); ?>"/></p> <p>Phone number: <input type="text" name="telefon" value="<?php echo (isset($phone) ? $phone : ''); ?>"/></p> <p>Sex: <label><input type="radio" name="sex" value="no" >Female</label> <label><input type="radio" name="sex" value="ferfi" >Male</label></p> <p>Favorite hobbies (Using CTRL you can select more than one):</p> <select name="hobby[]" size="4" multiple> <option value="sport">Sport</option> <option value="mozi">Movies</option> <option value="kirandulas">Hiking</option> <option value="olvasas">Reading</option> </select> <p><input name="regfelt" type="checkbox" value="elfogad">I accept the terms!</p> <p><input name="kuldes" type="submit" value="Submit form"> <input name="reset" type="reset" value="delete"></p> <table width="501" border="1"> <tr> <td><?php echo $final_report; ?></td> </tr> </table> <p> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108080 Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2010 Share Posted September 7, 2010 You removed the 's' (first parameter) that was originally in your code - $stmt->bind_param('s', $username); Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108082 Share on other sites More sharing options...
pahunrepublic Posted September 8, 2010 Author Share Posted September 8, 2010 You removed the 's' (first parameter) that was originally in your code - $stmt->bind_param('s', $username); I wrote it back, but now when I submit the form it doesn't do anything, just gives the form back it doesn't record data anything, in database. Any help? <?php include_once 'dbinfo.php'; if(isset($_POST['kuldes'])) { $name = trim($_POST['nev']); $username = $_POST['felh_nev']; $password = $_POST['jelszo']; $email = $_POST['email']; $phone = $_POST['telefon']; $gender = $_POST['sex']; $hobby = $_POST['hobby']; $regfelt = $_POST['regfelt']; $name = strip_tags($name); $name = stripslashes($name); $username = strip_tags($username); $email = strip_tags($email); $phone = strip_tags($phone); $date = date("d-m-Y"); if($name == NULL || $username == NULL || $password == NULL || $email == NULL || $phone == NULL || $gender == NULL) { echo "Please complete the form below or one of the boxes is empty."; } elseif(strlen($username) <= 3 || strlen($username) >= 30){ $final_report.="Your username must be between 3 and 30 characters.."; } elseif($stmt = $connect->prepare('SELECT username FROM users WHERE username=?')) { $stmt->bind_param('s',$username); $stmt->execute(); $stmt->bind_result($username); while ($stmt->fetch()) { printf("Name: %s\n", $name); $final_report.="The username is already in use!"; } $stmt->close(); }elseif(strlen($password) <= 6 || strlen($password) >= 12){ $final_report.="Your password must be between 6 and 12 digits and characters.."; } elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $final_report.="Your email address was not valid.."; } elseif(!eregi("^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$",$phone)){ $final_report.="Phone number is invalid. Only numbers with hyphen. Allowed format: countrycode-areacode-phonenumber"; } elseif(!isset($hobby)){ $final_report.="Youd didn't select any hobbies"; } elseif(!isset($regfelt)){ $final_report.="You didn't accept the terms"; } else { if ($stmt = $connection->prepare('INSERT INTO users(name,sex,email,phone_number,username,password,hobby) VALUES(?, ?, ?, ?, ?, ?, ?)')) { $stmt->bind_param('sssssss', $name, $sex, $email, $phone_number, $username, $password, $hobby); $stmt->execute(); $stmt->close(); } }}?> <h1>Registration Form</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration_form" method="POST"> <p>Name: <input type="text" name="nev" value="<?php echo (isset($name) ? $name : ''); ''?>" size=25></p> <p>Username: <input type="text" name="felh_nev" value="<?php echo (isset($username) ? $username : ''); ?>" size=10></p> <p>Password: <input type="password" name="jelszo" size=10></p> <!--<p>Password again:<input type="password" name="password_confirmation"></p>--> <p>E-mail: <input type="text" name="email" value="<?php echo (isset($email) ? $email : ''); ?>"/></p> <p>Phone number: <input type="text" name="telefon" value="<?php echo (isset($phone) ? $phone : ''); ?>"/></p> <p>Sex: <label><input type="radio" name="sex" value="no" >Female</label> <label><input type="radio" name="sex" value="ferfi" >Male</label></p> <p>Favorite hobbies (Using CTRL you can select more than one):</p> <select name="hobby[]" size="4" multiple> <option value="sport">Sport</option> <option value="mozi">Movies</option> <option value="kirandulas">Hiking</option> <option value="olvasas">Reading</option> </select> <p><input name="regfelt" type="checkbox" value="elfogad">I accept the terms!</p> <p><input name="kuldes" type="submit" value="Submit form"> <input name="reset" type="reset" value="delete"></p> <table width="501" border="1"> <tr> <td><?php echo $final_report; ?></td> </tr> </table> <p> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108836 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2010 Share Posted September 8, 2010 The current problem is a logical error in your code. In the block of code that is checking if the username is currently in use, you are using a prepare() statement as the elseif() logic test - elseif($stmt = $connect->prepare('SELECT username FROM users WHERE username=?')) When that is TRUE (the prepare itself worked) the code inside that conditional statement is executed, but then your code skips over the remainder of the logic and displays the form again. When validating user input, you generally want to check as much of it as possible, rather than check one value, display one error, fix one value, go onto the next value... I would get rid of all those elseif() statements and perform each test by itself, one after the other unconditionally, and either set an error element in an array or add to your $final_report error message if any of them fail. Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108855 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2010 Share Posted September 8, 2010 Here is rework of your code that will get you closer to a final solution - <?php include_once 'dbinfo.php'; if(isset($_POST['kuldes'])){ $name = trim($_POST['nev']); $username = $_POST['felh_nev']; $password = $_POST['jelszo']; $email = $_POST['email']; $phone = $_POST['telefon']; $gender = $_POST['sex']; $hobby = $_POST['hobby']; $regfelt = $_POST['regfelt']; $name = strip_tags($name); $name = stripslashes($name); $username = strip_tags($username); $email = strip_tags($email); $phone = strip_tags($phone); $date = date("d-m-Y"); $errors = array(); if($name == NULL || $username == NULL || $password == NULL || $email == NULL || $phone == NULL || $gender == NULL){ $errors[] = "Please complete the form or one of the boxes is empty."; } else { // all the required form fields are present, validate data if(strlen($username) <= 3 || strlen($username) >= 30){ $errors[] = "Your username must be between 3 and 30 characters.."; } else { // username is valid length, check if already in use $stmt = $connect->prepare('SELECT username FROM users WHERE username=?'); $stmt->bind_param('s',$username); $stmt->execute(); $stmt->bind_result($username); while ($stmt->fetch()){ printf("Name: %s\n", $name); $errors[] = "The username is already in use!"; } $stmt->close(); } if(strlen($password) <= 6 || strlen($password) >= 12){ $errors[] = "Your password must be between 6 and 12 digits and characters.."; } if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $errors[] ="Your email address was not valid.."; } if(!eregi("^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$",$phone)){ $errors[] ="Phone number is invalid. Only numbers with hyphen. Allowed format: countrycode-areacode-phonenumber"; } if(!isset($hobby)){ $errors[] ="Youd didn't select any hobbies"; } if(!isset($regfelt)){ $errors[] ="You didn't accept the terms"; } // all validation is done, process data if no errors if(empty($errors)){ $stmt = $connection->prepare('INSERT INTO users(name,sex,email,phone_number,username,password,hobby) VALUES (?,?,?,?,?,?,?)'); $stmt->bind_param('sssssss', $name, $sex, $email, $phone_number, $username, $password, $hobby); $stmt->execute(); $stmt->close(); } } } // prepare error string for form $final_report = ''; if(!empty($errors)){ foreach($errors as $error){ $final_report .= $error . '<br />'; } } ?> <h1>Registration Form</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration_form" method="POST"> <p>Name: <input type="text" name="nev" value="<?php echo (isset($name) ? $name : ''); ''?>" size=25></p> <p>Username: <input type="text" name="felh_nev" value="<?php echo (isset($username) ? $username : ''); ?>" size=10></p> <p>Password: <input type="password" name="jelszo" size=10></p> <!--<p>Password again:<input type="password" name="password_confirmation"></p>--> <p>E-mail: <input type="text" name="email" value="<?php echo (isset($email) ? $email : ''); ?>"/></p> <p>Phone number: <input type="text" name="telefon" value="<?php echo (isset($phone) ? $phone : ''); ?>"/></p> <p>Sex: <label><input type="radio" name="sex" value="no" >Female</label> <label><input type="radio" name="sex" value="ferfi" >Male</label></p> <p>Favorite hobbies (Using CTRL you can select more than one):</p> <select name="hobby[]" size="4" multiple> <option value="sport">Sport</option> <option value="mozi">Movies</option> <option value="kirandulas">Hiking</option> <option value="olvasas">Reading</option> </select> <p><input name="regfelt" type="checkbox" value="elfogad">I accept the terms!</p> <p><input name="kuldes" type="submit" value="Submit form"> <input name="reset" type="reset" value="delete"></p> <table width="501" border="1"> <tr> <td><?php echo $final_report; ?></td> </tr> </table> <p> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108877 Share on other sites More sharing options...
pahunrepublic Posted September 8, 2010 Author Share Posted September 8, 2010 The current problem is a logical error in your code. In the block of code that is checking if the username is currently in use, you are using a prepare() statement as the elseif() logic test - elseif($stmt = $connect->prepare('SELECT username FROM users WHERE username=?')) When that is TRUE (the prepare itself worked) the code inside that conditional statement is executed, but then your code skips over the remainder of the logic and displays the form again. When validating user input, you generally want to check as much of it as possible, rather than check one value, display one error, fix one value, go onto the next value... I would get rid of all those elseif() statements and perform each test by itself, one after the other unconditionally, and either set an error element in an array or add to your $final_report error message if any of them fail. Hi! First of all thank you for keeping this post alive. It's a lot of help to me. thank you I'm bit new to PHP I finished like 3 books so far but there is always something new. I try to do this registration form as a practice. you said: "I would get rid of all those elseif() statements and perform each test by itself" I thought I should get rid of all the 'elseif' and 'if' statements, but now I see your solution and it wasn't the case. I was going to ask you about that. Let me see if it works and I let you know. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1108885 Share on other sites More sharing options...
pahunrepublic Posted September 11, 2010 Author Share Posted September 11, 2010 Ok I tried out the code: <?php include_once 'dbinfo.php'; if(isset($_POST['kuldes'])){ $name = trim($_POST['nev']); $username = $_POST['felh_nev']; $password = $_POST['jelszo']; $email = $_POST['email']; $phone = $_POST['telefon']; $gender = $_POST['sex']; $hobby = $_POST['hobby']; $regfelt = $_POST['regfelt']; $name = strip_tags($name); $name = stripslashes($name); $username = strip_tags($username); $email = strip_tags($email); $phone = strip_tags($phone); $date = date("d-m-Y"); $errors = array(); if($name == NULL || $username == NULL || $password == NULL || $email == NULL || $phone == NULL || $gender == NULL){ $errors[] = "Please complete the form or one of the boxes is empty."; } else { // all the required form fields are present, validate data if(strlen($username) <= 3 || strlen($username) >= 30){ $errors[] = "Your username must be between 3 and 30 characters.."; } else { // username is valid length, check if already in use $stmt = $connect->prepare('SELECT username FROM users WHERE username=?'); $stmt->bind_param('s',$username); $stmt->execute(); $stmt->bind_result($username); while ($stmt->fetch()){ printf("Name: %s\n", $username); $errors[] = "The username is already in use!"; } $stmt->close(); } if(strlen($password) <= 6 || strlen($password) >= 12){ $errors[] = "Your password must be between 6 and 12 digits and characters.."; } if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $errors[] ="Your email address was not valid.."; } if(!eregi("^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$",$phone)){ $errors[] ="Phone number is invalid. Only numbers with hyphen. Allowed format: countrycode-areacode-phonenumber"; } if(!isset($hobby)){ $errors[] ="Youd didn't select any hobbies"; } if(!isset($regfelt)){ $errors[] ="You didn't accept the terms"; } // all validation is done, process data if no errors if(empty($errors)){ $stmt = $connection->prepare('INSERT INTO users(name,sex,email,phone_number,username,password,hobby) VALUES (?,?,?,?,?,?,?)'); $stmt->bind_param('sssssss', $name, $gender, $email, $phone, $username, $password, $hobby); $stmt->execute(); $stmt->close(); header("Location: login_form.php"); exit; } } } // prepare error string for form ?> <h1>Registration Form</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration_form" method="POST"> <p>Name: <input type="text" name="nev" value="<?php echo (isset($name) ? $name : ''); //ha $name változó meg lett adva akkor írja ki amit beírt ha nem akkor ''?>" size=25></p> <p>Username: <input type="text" name="felh_nev" value="<?php echo (isset($username) ? $username : ''); ?>" size=10></p> <p>Password: <input type="password" name="jelszo" size=10></p> <!--<p>Password again:<input type="password" name="password_confirmation"></p>--> <p>E-mail: <input type="text" name="email" value="<?php echo (isset($email) ? $email : ''); ?>"/></p> <p>Phone number: <input type="text" name="telefon" value="<?php echo (isset($phone) ? $phone : ''); ?>"/></p> <p>Sex: <label><input type="radio" name="sex" value="no" >Female</label> <label><input type="radio" name="sex" value="ferfi" >Male</label></p> <p>Favorite hobbies (Using CTRL you can select more than one):</p> <select name="hobby[]" size="4" multiple> <option value="sport">Sport</option> <option value="mozi">Movies</option> <option value="kirandulas">Hiking</option> <option value="olvasas">Reading</option> </select> <!-- <p>Other message:</p> <textarea name="megjegyzes" cols="40"></textarea>--> <p><input name="regfelt" type="checkbox" value="elfogad">I accept the terms!</p> <p><input name="kuldes" type="submit" value="Submit form"> <input name="reset" type="reset" value="delete"></p> <table width="501" border="1"> <tr> <td><?php for($i=0; $i<8; $i++){echo $errors[$i]."</br>";}?></td> </tr> </table> <p> </p> </form> But it gives me the error: "Fatal error: Call to a member function prepare() on a non-object in" line 54, which is: $stmt = $connection->prepare('INSERT INTO users(name,sex,email,phone_number,username,password,hobby) VALUES I guessed it had something wrong with the column names that they don't match but I corrected some of it and I also corrected the values and it just keeps giving me the error message. Please anyone qho can help with this? Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1110065 Share on other sites More sharing options...
PFMaBiSmAd Posted September 12, 2010 Share Posted September 12, 2010 Your code is using two different mysqli connection instance names, which ProjectFear pointed out back on August 01 and asked you which was correct. To which you replied: "It's $connect." Is there some reason you didn't change $connection to $connect in your code? Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1110100 Share on other sites More sharing options...
pahunrepublic Posted September 12, 2010 Author Share Posted September 12, 2010 Your code is using two different mysqli connection instance names, which ProjectFear pointed out back on August 01 and asked you which was correct. To which you replied: "It's $connect." Is there some reason you didn't change $connection to $connect in your code? YESSSSS!! You're awesome PFMaBiSmAd. I couldn't see that it's not just the fresh eye I didn't notice it. It'S $connect which is in my dbinfo.php. I also did some other small stuff now it works. I hope this registration form is now bulletproof and secure. Thank you again PFMaBiSmAd you showed me the way. Now I'm more eager to study PHP. Quote Link to comment https://forums.phpfreaks.com/topic/209464-warning-with-mysqli-prepared-statement/#findComment-1110377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.