Jump to content

having trouble sending a character form field value to an sql integer field


co.ador

Recommended Posts

<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 ?

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.