0

I can't understand why this will not be executed into the mySQL database? Everything is set and all it does is to update some values.

    <?php
$con=mysqli_connect(This is filled.);
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_query($con,"UPDATE `members` SET `rank`='$_POST[rank]' WHERE `id`='$_POST[id]'");


mysqli_close($con);
header("Location: index.php");
?>

Heres the thing that should fill the $_POSTs

<form action="setrank.php" method="post">
User: 
  <select>
      <?php
  $result = mysqli_query($con,"SELECT * FROM members ORDER BY id");

while($row = mysqli_fetch_array($result))
  {
  echo "<option name='id' id='id' value='" . $row['id'] . "'>" . $row['username'] . " (" . $row['id'] . ")</option>";
  }
?>
  </select><br />
Set rank to: 
    <select><option name="rank" id="rank" value="0" >Guest.</option><option name="rank" id="rank" value="1" >Moderator.</option><option value="2" name="rank" id="rank">Administrator.</option><option value="3" name="rank" id="rank">Owner.</option></select>
<br /><input type="submit">
</form>

Thank you very much for help, i've been using hours. :/

1
  • 1
    The name attribute belongs on <select name='rank'> not on <option name='rank'>, same for id You should be checking that the form was posted before attempting to do the UPDATE, and most importantly, the code is vulnerable to SQL injection. It is important to start learning how to use mysqli::prepare() to create prepared statements, safe from SQL injection. Commented Mar 8, 2014 at 3:02

1 Answer 1

1

The form select element define incorrect, add form field name in select box not an options please try this way

<select name="id"> 
 <option value="xyz">Name</option>
</select>
Sign up to request clarification or add additional context in comments.

1 Comment

@KinJacob, ok good, if you answer useful then please correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.