Jump to content

Expects Parameter


Go to solution Solved by slove05,

Recommended Posts

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();
Link to comment
https://forums.phpfreaks.com/topic/294062-expects-parameter/
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503413
Share on other sites

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..

Link to comment
https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503433
Share on other sites

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 by Barand
Link to comment
https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503441
Share on other sites

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..

Link to comment
https://forums.phpfreaks.com/topic/294062-expects-parameter/#findComment-1503452
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.