svabhishek Posted August 4, 2011 Share Posted August 4, 2011 Hello everyone ... I am trying out something similar too but just cant get it to work The code I have been using is as follows : * My database is FB and the table in it is profs. The field in profs is rating ** The include/connection.php file is absolutely fine and it also echo me that the connection to the database has been successful FOR exp.php <?php include 'includes/connection.php'; ?> <h2>POST</h2> <form action="exp_process.php" method="post"> <select name="rating"> <option value="1" selected="selected">1</option> <?php for($i=2; $i<=10 ; $i++) { echo '<option value="'.$i.'"> '.$i.' </option>'; } ?> </select><br> <input type="button" value="submit" /> </form> FOR exp_process.php <?php include 'includes/connection.php'; ?> <?php $rating = $_POST['rating']; $query = "INSERT INTO `profs` (`rating`) VALUES (`rating`)"; $result = mysql_query($query, $connection); if ($result) { // Success! echo " Success "; } else { // Display error message. echo "<p>Updation Failed</p>"; echo "<p>" . mysql_error() . "</p>"; } ?> I tried to put in values to buttons and tried everything but dont know why but just can't get it to work the way it should. Any kind of help would be appreciated Thank you Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/ Share on other sites More sharing options...
Nodral Posted August 4, 2011 Share Posted August 4, 2011 Hi In this line, you are not referencing any variable? $query = "INSERT INTO `profs` (`rating`) VALUES (`rating`)"; Surely it should be $query = "INSERT INTO `profs` (`rating`) VALUES (`$rating`)"; Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251798 Share on other sites More sharing options...
WebStyles Posted August 4, 2011 Share Posted August 4, 2011 change this: $query = "INSERT INTO `profs` (`rating`) VALUES (`rating`)"; to this: $query = "INSERT INTO `profs` (`rating`) VALUES ('$rating')"; Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251800 Share on other sites More sharing options...
Nodral Posted August 4, 2011 Share Posted August 4, 2011 Too slow again WebStyles!!! lol Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251801 Share on other sites More sharing options...
WebStyles Posted August 4, 2011 Share Posted August 4, 2011 yep... lol. except my code will work and yours wont (you left the backticks) Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251804 Share on other sites More sharing options...
svabhishek Posted August 4, 2011 Author Share Posted August 4, 2011 Thanks guys ... I tried both the codes and also tried to display an error message but I dont think the files are linked properly ... there is no response from the exp_process.php file. Could you help me out with that ... Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251806 Share on other sites More sharing options...
WebStyles Posted August 4, 2011 Share Posted August 4, 2011 there HAS to be a response, even if it's just an error in your logs. my guess is the connection. check your error logs to see what went wrong. Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251808 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2011 Share Posted August 4, 2011 type="button" Use type="submit" buttons don't actually do anything unless you attach an event to them. Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251809 Share on other sites More sharing options...
svabhishek Posted August 4, 2011 Author Share Posted August 4, 2011 @PFMaBiSmAd Yea .. thanks a lot ... my code is up and working Many Many Many thanks for your help .. It was small but I missed that ... @WebStyles @Nodral Thanks a lott for your help guys Quote Link to comment https://forums.phpfreaks.com/topic/243813-insert-drop-down-values-into-database/#findComment-1251812 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.