slove05 Posted January 19, 2015 Share Posted January 19, 2015 I am trying to create a simple voting form. Everything goes well until I submit and then I get a Warning: mysqli_error() expects exactly 1 parameter, 0 given on line 79 error. I am assuming it is not pulling the ID correctly but as I am new to php and mysqli I cannot exactly say if it the way the code is written or if I am calling the parameter incorrectly in the query. Again I am new to to this so please be gentle. Below is my code. It pulls the drop down list correctly and echo's correctly but I believe my post query to be a little out of wack. Could someone point me in the correct direction? It would be very appreciated. <form action="businesstype_update.php" method="post"> <?php if(isset($_POST['voteall'])){ $vote_lg = "update membertest where id={$row_lg['id']} set vote=vote+1"; $run_lg = mysqli_query($con, $vote_lg) or die(mysqli_error()); } $result_lg = mysqli_query($con, "SELECT id, business FROM membertest WHERE businesstype='large'"); echo "Vote for large business of the year! <SELECT name='business'>\n"; echo "<option>Select a large business</option>"; while($row_lg = $result_lg->fetch_assoc()) { echo "<option value='{$row_lg['id']}'>{$row_lg['business']}</option>\n"; } echo "</select></br></br>\n"; echo "<input type='submit' name='voteall' value='voteall'>"; $result_lg->close(); $con->close(); Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/ Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 mysqli_error function require the connection as a parameter mysqli_error($con) Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503400 Share on other sites More sharing options...
slove05 Posted January 19, 2015 Author Share Posted January 19, 2015 That really helped! At least now I am getting an error message I can use. Now I get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id= SET vote=vote+1' at line 1 So obviously I am on the right track thinking the update happens incorrect. I am calling the ID from the echoed option value in the form. Is should I be asking it to $_GET the id first? I am really confused. This is the last piece in my little project and could someone point me to an example of getting an id from an option value? Just some basic syntax or if your feeling generous help me fix this line. Thanks so much, I have so much to learn and forums like these connect me with people who tend to explain things in ways I can understand better than the manual. Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503413 Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 You have your clauses in the wrong order, Should be UPDATE .... SET.... WHERE .... Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503422 Share on other sites More sharing options...
slove05 Posted January 19, 2015 Author Share Posted January 19, 2015 Ok that narrowed it down to the exact thing I thought was wrong which is the where id={$row_lg['id']} Which I am getting from the following echo "<option>Select a large business</option>"; while($row_lg = $result_lg->fetch_assoc()) { echo "<option value='{$row_lg['id']}'>{$row_lg['business']}</option>\n"; } do I need to echo out the selected option somewhere... also now that I am looking it probably be mysqli_fetch_assoc maybe?? The code works to update every row in the table if I remove the where id... so this is the last peice of the puzzle.. Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503433 Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 (edited) The id you want to update would come from $_POST['voteall'] if(isset($_POST['voteall'])) { $id = intval($_POST['voteall']); // ensure it's an integer $vote_lg = "update membertest set vote=vote+1 where id = $id"; $run_lg = mysqli_query($con, $vote_lg) or die(mysqli_error($con)); } Edited January 19, 2015 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503441 Share on other sites More sharing options...
slove05 Posted January 19, 2015 Author Share Posted January 19, 2015 Ok I made the changes but I don't think this is exactly what I am trying to accomplish. The code does not error out but it also does not update the vote field in the database. Maybe a complete view of the code would help..?? Goodness I will not take on another php mysqli project until I have a better understanding. So I have a form. Inside that form is a list dynamically populated from a data base. The user should make a selection and click the submit button to vote for that business. <form action="businesstype_update.php" method="post"> <?php require('Connections/Members_new.php'); if(isset($_POST['voteall'])) { $id = intval($_POST['voteall']); // ensure it's an integer $vote_lg = "update membertest set vote=vote+1 where id = $id"; $run_lg = mysqli_query($con, $vote_lg) or die(mysqli_error($con)); } $result_lg = mysqli_query($con, "SELECT id, business FROM membertest WHERE businesstype='large'"); echo "Vote for large business of the year! <SELECT name='business'>\n"; echo "<option>Select a large business</option>"; while($row_lg = $result_lg->fetch_assoc()) { echo "<option value='{$row_lg['id']}'>{$row_lg['business']}</option>\n"; } echo "</select></br></br>\n"; echo "<input type='submit' name='voteall' value='voteall'>"; $result_lg->close(); ?> </form> Don't I still have to tell $_POST where to get the id from? This will be the death of me. I will hire out from now on... silly silly designer.. Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503452 Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 Sorry, it would come from the "business" input. $id = intval($_POST['business']); Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503456 Share on other sites More sharing options...
Solution slove05 Posted January 19, 2015 Author Solution Share Posted January 19, 2015 you sir are a saint... and it makes sense. I want the value of the option labeled business... Thank you so kindly for all your help. I really do appreciate it. All my best and you truly are guru... Quote Link to comment https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503459 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.