Jump to content

Archived

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

newman

problem with INSERT

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
[!--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 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 )

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Please post the code you're using and any error messages you've recieved.

Ken

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 .

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
i get this error : Out of range value adjusted for column 'price' at row 1

Share this post


Link to post
Share on other sites

×

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.