Jump to content

php update mysql database with form/checkbox


Recommended Posts

 

I try this code but submit button non work.
any help ? pls.

echo "<form method=post action=#>";

while($row = mysqli_fetch_assoc($result))

{

echo"<center>".$row["data"]." ".$row["time"]."<br>"; echo $row["country"]." ".$row["lega"]."<br>"; echo "".$row["team1"]."[".$row['pos_t1']."]vs".$row["team2"]."[".$row['pos_t2']."]<br>"; echo "<input type=checkbox value=".$row['team1']." name=team1";

}

echo"<input type=submit value=submit></form>";

Edited by tonypoli783
Link to comment
Share on other sites

Telling us that some thing isn't working tells us nothing.

  • What should happen that isn't?
  • What shouldn't happen that is?

Your topic title mentions a database update. Where and what is that code?

NOTE - use the code button (<>) when posting code.

Link to comment
Share on other sites

8 hours ago, tonypoli783 said:

 

I try this code but submit button non work.
any help ? pls.

echo "<form method=post action=#>";

while($row = mysqli_fetch_assoc($result))

{

echo"<center>".$row["data"]." ".$row["time"]."<br>"; echo $row["country"]." ".$row["lega"]."<br>"; echo "".$row["team1"]."[".$row['pos_t1']."]vs".$row["team2"]."[".$row['pos_t2']."]<br>"; echo "<input type=checkbox value=".$row['team1']." name=team1";

}

echo"<input type=submit value=submit></form>";

Short answer: Your HTML is incorrect. 

You're missing the closing '>' on the Checkbox's input element. 

I'd also recommend using quotes on HTML attributes.  The cases where you need them far outnumber those where you can get away without them. 

I'd suggest something more like this: 

echo '<form method="post" action="#">';

while( $row = mysqli_fetch_assoc( $result ) )
{
  printf( '<center>' 
    . '%1$s %2$t<br>'
    . '%3%s %4$s<br>' 
    . '%5$s[%6$s] vs %7$s[%8$s]<br>'
    . '<input type="checkbox" value="%5$s" name="team">
    . '</center>'
    , $row['data'] 
    , $row['time'] 
    , $row['country'] 
    , $row['lega'] 
    , $row['team1'] 
    , $row['pos_t1'] 
    , $row['team2']
    , $row['pos_t2']
    ); 

echo '<input type="submit" value="submit"></form>';

 

Regards, 
   Phill W. 

 

Link to comment
Share on other sites

the current markup will only submit the last checkbox value that is checked. to submit a set of values, the form field name needs to be an array, e.g. name='team[]'

you also need to apply htmlentities() to dynamic values being output in a html context so that any html entity in a value, such as a ', cannot break the markup.

Link to comment
Share on other sites

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.