Jump to content

problem with INSERT


newman

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 ?

Link to comment
https://forums.phpfreaks.com/topic/7302-problem-with-insert/
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 )
Link to comment
https://forums.phpfreaks.com/topic/7302-problem-with-insert/#findComment-26573
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]
Link to comment
https://forums.phpfreaks.com/topic/7302-problem-with-insert/#findComment-26722
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
Link to comment
https://forums.phpfreaks.com/topic/7302-problem-with-insert/#findComment-26729
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 .
Link to comment
https://forums.phpfreaks.com/topic/7302-problem-with-insert/#findComment-26740
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
Link to comment
https://forums.phpfreaks.com/topic/7302-problem-with-insert/#findComment-26763
Share on other sites

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.