Jump to content

Warning: mysqli_error() expects exactly 1 parameter, 0


Go to solution Solved by NigelRel3,

Recommended Posts

Hi all,


Can anyone help as I get this error 


Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/ubuntu/workspace/Project/Admin.php on line 48 Call Stack: 0.0011 239616 1. {main}() /home/ubuntu/workspace/Project/Admin.php:0 0.0028 249744 2. mysqli_error() /home/ubuntu/workspace/Project/Admin.php:48 Error in query: INSERT `Membership` (`First_Name`, `Surname`, `Gender`, `DOB`, `Email Address`, `Password`) VALUES ('ewqewq', 'qweqw', '', '1966','eqweqe', 'eqwe').

//include files
include 'header/header.php';
include 'nav/navigation.php';
include 'init.php';

print_r ($_POST);
echo "<br />";
if (isset($_POST['loginSubmit']))
$firstname = $_POST['txtFirstName'] ;
$surname = $_POST['txtSurname'] ;
$gender = $_POST['myList'];
$email =$_POST['txtEmail'];
$password = $_POST['txtPass'];
$DOB = $_POST['edob'];

echo "$firstname";
echo "<br />";
echo "$surname";
echo "<br />";
echo "$gender";
echo "<br />";
echo "$email";
echo "<br />";
echo "$password";
echo "<br />";
echo "$DOB";
echo "<br />";


//run $query
//(b)Construct INSERT query using variables holding data gathered
$query =  "INSERT  `Membership` (`First_Name`, `Surname`, `Gender`, `DOB`, `Email Address`, `Password`) VALUES ('$firstname', '$surname', '$gender', '$DOB','$email', '$password')";

//Temporarily echo $query for debugging purposes	
echo "$query";

//run $query
include 'init.php';
echo "<br />";
//echo "$query";
echo "<br />";
$result = mysqli_query($connection,$query) or exit ("Error in query: $query. ".mysqli_error()); 
<div class="large-6 columns">
 <form method="post" action="Admin.php">
          <legend>Registration Form</legend>
          <legend>First Name</legend>
<input type="text"name="txtFirstName" placeholder="Your first Name" 
 <input type="text"name="txtSurname" placeholder="Your Surame" 
             <select name="Gender"id =  "myList">
               <option value = "Male">Male</option>
               <option value = "Female">Female</option>
          <div class="small-6 columns">
  <tr> <th> <td>
 <select size="1" name="edob" value="date">
  <select size="1" name="edob" value="month">  </th>

   <select size="1" name="edob" value="Year">
</select> </td></tr>
          <legend>Email Address</legend>
<input type="text" name="txtEmail" placeholder="Your email address">
<input type="text" name="txtPass" placeholder="Your password">
<input type="text" placeholder="Confirm your password">
<button name="loginSubmit" class="Submit" value="Submit" >Submit</button>
<button class="reset" value="Clear" >Clear</button>

//include files
include 'footer/footer.php';
  <script src="js/vendor/jquery.js"></script>
  <script src="js/foundation.min.js"></script>
Link to comment
Share on other sites

Switching from the old mysql_* functions to the new mysqli_* functions takes a lot more than adding an “i” everyhwere. Or adding connection arguments.


You first have to unlearn plenty of wrong practices: Your code has SQL injection vulnerabilities all over the place, and printing error messages on the screen isn't very smart either. It gives attackers valuable information about your system, and it makes legitimate users think your website is fudged up.


Then you need to actually learn mysqli. The old extension represented the technology of the 90s, mysqli is a database interface for the 21st century and often takes a very different approach. For example, passing data to queries is now implemented with prepared statements, which provides much better protection against SQL injection attacks. mysqli also supports exceptions to properly indicate errors.


Unfortunately, mysqli is fairly difficult to learn, especially when you don't like to read manuals. A much better alternative is the PDO extension. Since you haven't invested any time into mysqli yet, now would be a great time to jump straight to PDO.

Edited by Jacques1
Link to comment
Share on other sites

Hi Jacques1,


The site is just for demo only and a work in progress


The reason for displaying the details was for testing purposes, these will be removed when the required section is working. MySQL may have vulnerabilities but these are going to be addressed shortly and it will help in learning about sql injection attacks for my course.  

Link to comment
Share on other sites

I don't think you're getting my point. You invest time for turning broken mysql_* code into broken mysqli_* code. Why on earth would you do that? If you don't care about broken code, just keep your old mysql_* functions and then go straight to PDO when you rewrite everything.

Link to comment
Share on other sites

Additionally, do not depend on the name of a button for your script to work. It will completely fail in certain circumstances. The proper way is to check the request method.




Also, do not create variables for nothing.


You are mixing case for your attribute names. Stick to all lowercase with underscores_for_long_words.


Since you are processing in the same page (as you should), remove the hardcoded action and filename. You can leave it out completely and the page will submit to itself.

Edited by benanamen
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.