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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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