How to Insert Value From Radio Button in MySQL in PHP -
i'm making online voting system. system has limit people (population of area) can vote (example-10) & votes add database. want insert values radio buttons in database. tried code. has error.the vote form data doesn't insert db & don't know suitable code case. please if has idea, please let me know. thank-you
<html> <head> <title>election</title> <link rel="stylesheet" href="bootstrap-3.3.4-dist/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="css/presidential.css" type="text/css"> <link rel="stylesheet" href="css/login.css" type="text/css"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> </head> <body> <div class="head"> <div class="container-fluid"> <div class="navbar-header"> <b> online voting system </b> </div> <input type="submit" class="btn btn-primary nextbtn btn-lg pull-right" name="submit" value="cast vote" /> </div> </div> <div class="container"> <form name="vote" method="post" action=""> <div class="one"> <h2><b>election</b></h2> <br> <div class="funkyradio"> <div class="funkyradio-default"> <input type="radio" name="radio" id="radio1" value="radio1" /> <label for="radio1"><b>a party</b> <div class="img"><img src="img\a.png" height="75.8em" width="50.3em" ></img> </div> </label> </div> <div class="funkyradio-default"> <input type="radio" name="radio" id="radio2" value="radio2" /> <label for="radio2"><b>b party</b><div class="img"><img src="img\b.jpg" height="75.8em" width="50.3em" ></img> </div></label> </div> <div class="funkyradio-default"> <input type="radio" name="radio" id="radio3" /> <label for="radio3"><b>c party</b><div class="img"><img src="img\c.jpg" height="75.8em" width="50.3em" ></img> </div></label> </div> <div class="funkyradio-default"> <input type="radio" name="radio" id="radio4" /> <label for="radio4"><b>d party</b><div class="img"><img src="img\d.jpg" height="75.8em" width="50.3em" ></img> </div></label> </div> <div class="funkyradio-default"> <input type="radio" name="radio" id="radio5" /> <label for="radio5"><b>e party</b><div class="img"><img src="img\e.jpg" height="75.8em" width="50.3em" ></img> </div></label> </div> <div class="funkyradio-default"> <input type="radio" name="radio" id="radio6" /> <label for="radio6"><b> f party</b><div class="img"><img src="img\f.jpg" height="75.8em" width="50.3em" ></img> </div></label> </div> </div> </div> </form> </div> </body> </html> <?php require'database.php'; if (isset($_post['submit'])) {$radio=$_post['radio']; if($radio!="") { $query=mysql_query("insert `election`(`candidate_name`) values ('$radio')"); if ($query) { echo"cast vote successfully"; } else { echo"there problem in database"; } } } ?>
your query won't work because call variable in string. should close string first, call variable , end query in string again.
something this
values ('" . $radio . "');"
the single quotes in query, close query , put php code in, , open string again double quoutes. in string finish query.
look sql injection, because you're vulnerable if use method. question.
Comments
Post a Comment