Jump to content


Photo

problem with INSERT


  • Please log in to reply
9 replies to this topic

#1 newman

newman
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 13 April 2006 - 01:09 PM

hi everybody .
my INSERT query can not insert anything into database when a field in the html form remains empty by the user.i have a database table for goods containing : cat_name,good_name,price,description .
and i have a html form that user can enter data for this table , but if the user does not fill even one of them , the INSERT can not take place , what's the problem , is it with mysql installation ?



#2 predator12341

predator12341
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts
  • LocationCheshunt, Hertfordshire, England

Posted 13 April 2006 - 01:20 PM

[!--quoteo(post=364386:date=Apr 13 2006, 02:09 PM:name=newman)--][div class=\'quotetop\']QUOTE(newman @ Apr 13 2006, 02:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
hi everybody .
my INSERT query can not insert anything into database when a field in the html form remains empty by the user.i have a database table for goods containing : cat_name,good_name,price,description .
and i have a html form that user can enter data for this table , but if the user does not fill even one of them , the INSERT can not take place , what's the problem , is it with mysql installation ?
[/quote]
hi man make sure you database fields are set to null
so null values can be entered that way it will add a record if data is missing
(you should have an auto increment id though so there is a way to reference each required )
[a href="http://www.sloganizer.net/en/" target="_blank"][/a]

#3 newman

newman
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 13 April 2006 - 02:14 PM

thank you for your answer. they they're all set to NULL en i have a unique ID with auto increment behavior but i still have the problem

#4 predator12341

predator12341
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts
  • LocationCheshunt, Hertfordshire, England

Posted 13 April 2006 - 02:20 PM

hmmmm have you got the code please
[a href="http://www.sloganizer.net/en/" target="_blank"][/a]

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 April 2006 - 03:04 PM

Please post the code you're using and any error messages you've recieved.

Ken

#6 newman

newman
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 13 April 2006 - 08:06 PM

i couldnt be with the code , it was workin on another installation of PHP&MYSQL .

here is the code :

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]mysql_query("INSERT INTO goods(cat_id,good_name,unit,price,lprice,good_description) VALUES ('$cat_id','$good_name','$unit','$price','$lprice','$good_description')");[/quote]

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 April 2006 - 08:18 PM

Where are the variables

$cat_id, $good_name, $unit, $price, $lprice, $good_description

being set?

When I hear (or read) the phrase "it couldn't be with the code , it was workin on another installation of PHP&MYSQL" I immediately ask "Is register_globals the same on both machines?"

What you are seeing would make sense if register_globals is enabled on the machine where your script works and disabled where id doesn't.

Ken

#8 newman

newman
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 13 April 2006 - 08:46 PM

all the varibales are set :

$good_name=$_POST['good_name'];
.
.
.
.
as i said in my first post , when user fills all the fields of the html form , INSERT takes place without any problem but if even one of the field isnt filled by the user the INSERT can not take place , i do not get any error .

#9 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 April 2006 - 09:37 PM

For debugging, change the insert query to:
<?php
$q = "INSERT INTO goods(cat_id,good_name,unit,price,lprice,good_description) VALUES ('$cat_id','$good_name','$unit','$price','$lprice','$good_description')";
$rs = mysql_query($q) or die('There was a problem with the query: ' . $q . '<br />' . mysql_error());
?>
and try the failing queries again. See if you get any errors printed.

Ken

#10 newman

newman
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 13 April 2006 - 09:55 PM

i get this error : Out of range value adjusted for column 'price' at row 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users