Re: [PHP-DB] Re: radio form submission
The error is pretty explicit - there is no field in your table called '250kbps'. What you should have is a field (column) called "speed" for example, with values from 1...5 or whatever. To the users they will only deal with actual speed values on their screen if you use the speeds as the value parms of your html. To you, the programmer, yes - you could use a switch statement to convert the incoming radio button value to a 1 or 2 or 3, etc. and store that value to the "speed" column or not. I'm thinking that you are trying to store each radio button to its own column in your table which is not good, normalized structure. "Chris Stinemetz" wrote in message news:BANLkTi=jA+YeEGwCSvwBcjeb6WP1gG6M=g...@mail.gmail.com... > Thanks everyone. > > So I am trying to keep this simple and just assign the value with the > radio button and then insert it into mysql database, but with the > following code I am getting the mysql error: Unknown column '250kbps' > in 'field list' when I choose the first radio button. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: radio form submission
Thanks everyone. > If there is no purpose, I would make the values of the inputs the values you > want to store in your database. > Muuch easier.. > So I am trying to keep this simple and just assign the value with the radio button and then insert it into mysql database, but with the following code I am getting the mysql error: Unknown column '250kbps' in 'field list' when I choose the first radio button. I think it has to do with the value being a string, but I haven't been able to figure out the fix. Thanks everyone for your help in accomplishing one thing with many differnt techniques. It is greatly appreciated. Chris Form echo ' Store name: Market:'; echo ''; while($row = mysql_fetch_assoc($result)) { echo '' . $row['mar_name'] . ''; } echo ''; echo 'Broadband speed test results: 0-250kbps| 250-300kbps| 300-400kbps| 400-600kbps| 600kbps-3.8mbps Store visit details: '; } } } Insert Code $sql = "INSERT INTO posts(post_content, post_date, post_tptest, post_store, post_by) VALUES ('" . mysql_real_escape_string($_POST['post_content']) . "', NOW(), " . $_POST['post_tptest'] . ", " . $storeid . ", " . $_SESSION['user_id'] . " )"; $result = mysql_query($sql); if(!$result) { //something went wrong, display the error echo 'An error occured while inserting your post. Please try again later.' . mysql_error(); $sql = "ROLLBACK;"; $result = mysql_query($sql); } else { $sql = "COMMIT;"; $result = mysql_query($sql); //after a lot of work, the query succeeded! echo 'You have succesfully created your new store visit.'; } } } } } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: radio form submission
Hi Chris, Here is the corrected code. Yes, call the function before the SQL SELECT like so. You may have to work with it a bit. This was just off the top of the head. But now that I look at it, I think Jim may be right. What's the purpose of the inputs having 1, 2, 3, etc and not the 0-250kbps, etc? If there is no purpose, I would make the values of the inputs the values you want to store in your database. Muuch easier.. Otherwise try this. You should be able to copy an paste. //your form code... function getSpeed($val) { if($val != 'undefined') { switch ($val) { case "1": $post_speed = "0-250kbps"; break; case "2": $post_speed = "250-300kbps"; break; case "3": $post_speed = "300-400kbps"; break; case "4": $post_speed = "400-600kbps"; break; case "5": $post_speed = "600kbps-3.8mbps"; break; default: $post_speed = "Speed Undetected"; // or "0-250kbps" break; } return $post_speed; } else { die("Error, no speed value set"); } } //This part may need to be worked. Basically you want; posts.post_tptest to equal the result of getSpeed($_POST ['post_tptest']). //however you can get it there in your code. Or just try this, see if this works and go from there. $_POST['post_tptest'] = getSpeed($_POST['post_tptest']); $posts_sql = "SELECT posts.post_store, posts.post_content, posts.post_tptest, posts.post_date, posts.post_by, users.user_id, users.user_name, users.first_name, users.last_name FROM posts LEFT JOIN users ON posts.post_by = users.user_id WHERE posts.post_store = " . mysql_real_escape_string($_GET['id']) . " ORDER BY posts.post_date DESC "; //... rest of your code HTH, GL, Best, Karl On Jun 23, 2011, at 3:17 PM, Jim Giner wrote: If you put the "0-250kbps" as the value= of your html tag, php would give you that when you did this: $rb_picked = $_POST['post_tptest']. No need for a switch or anything to re-interpret what the user picked. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: radio form submission
If you put the "0-250kbps" as the value= of your html tag, php would give you that when you did this: $rb_picked = $_POST['post_tptest']. No need for a switch or anything to re-interpret what the user picked. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: radio form submission
Try reading a good html reference on how radio buttons work. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php