co.ador Posted July 12, 2011 Share Posted July 12, 2011 <select name="category_id" size="1"><br />'; $sql = "SELECT id, name FROM categories ORDER BY name"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['id']."\">".$row['name']."</option>\n "; } echo' </select> Above I want to insert id into category_id value which is sending it to the database to the category_id field which is a int(11) as you can see it will insert a empty value because of the problem of phpmyadmin interpreting a character value in <option value=\"".$row['id']."\">".$row['name']."</option>\n "; and inserting it into the category_id field as int(11). I also want to set up the form to send the value of name through post to insert it in a field called category varchar(255). how can I send <option value=\"".$row['id']."\"> as an interger and then wihin that select tag send name as a varchar ? Quote Link to comment https://forums.phpfreaks.com/topic/241766-having-trouble-sending-a-character-form-field-value-to-an-sql-integer-field/ Share on other sites More sharing options...
trq Posted July 12, 2011 Share Posted July 12, 2011 What? Quote Link to comment https://forums.phpfreaks.com/topic/241766-having-trouble-sending-a-character-form-field-value-to-an-sql-integer-field/#findComment-1241766 Share on other sites More sharing options...
co.ador Posted July 12, 2011 Author Share Posted July 12, 2011 I thought you have understood. The form in the first post will insert in the query below. sql = mysql_query("INSERT INTO products (product_name, price, details, subcategory, city, state, country, category_id, date_added) VALUES('$productname','$price','$details','$subcategory','$city','$state','$country','$category_id', now())") or die (mysql_error()); // Get the inserted ID here to use in the activation email $id = mysql_insert_id(); ?> the query above won't insert the $category_id in category_id field I have defined as follows $category_id = $_POST['category_id']; I guess it is not inserting any value because category_id is a character value no a numeric value. while category_id the table field is a numeric value (integer) int(11) What can I do to insert that the value in the table field? Quote Link to comment https://forums.phpfreaks.com/topic/241766-having-trouble-sending-a-character-form-field-value-to-an-sql-integer-field/#findComment-1241835 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.