newman Posted April 13, 2006 Share Posted April 13, 2006 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 Link to comment Share on other sites More sharing options...
predator12341 Posted April 13, 2006 Share Posted April 13, 2006 [!--quoteo(post=364386:date=Apr 13 2006, 02:09 PM:name=newman)--][div class=\'quotetop\']QUOTE(newman @ Apr 13 2006, 02:09 PM) [snapback]364386[/snapback][/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 nullso 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 ) Quote Link to comment Share on other sites More sharing options...
newman Posted April 13, 2006 Author Share Posted April 13, 2006 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 Quote Link to comment Share on other sites More sharing options...
predator12341 Posted April 13, 2006 Share Posted April 13, 2006 hmmmm have you got the code please Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 13, 2006 Share Posted April 13, 2006 Please post the code you're using and any error messages you've recieved.Ken Quote Link to comment Share on other sites More sharing options...
newman Posted April 13, 2006 Author Share Posted April 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 13, 2006 Share Posted April 13, 2006 Where are the variables $cat_id, $good_name, $unit, $price, $lprice, $good_descriptionbeing 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 Quote Link to comment Share on other sites More sharing options...
newman Posted April 13, 2006 Author Share Posted April 13, 2006 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 . Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 13, 2006 Share Posted April 13, 2006 For debugging, change the insert query to:[code]<?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());?>[/code]and try the failing queries again. See if you get any errors printed.Ken Quote Link to comment Share on other sites More sharing options...
newman Posted April 13, 2006 Author Share Posted April 13, 2006 i get this error : Out of range value adjusted for column 'price' at row 1 Quote Link to comment 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.