p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Inserting records into the DB


Message #1 by "Srinivasan Prasanna" <sri_core@m...> on Wed, 18 Sep 2002 20:50:19
Hi,
I have a php form which inserts records into the mysql db. All the columns 
are getting inserted except 4 columns. 
My table script is this:
CREATE TABLE mirs_survey1 ( 
qno tinyint(4) NOT NULL auto_increment, 
emailid varchar(255) default NULL, 
date date default NULL, 
email_alert tinyint(4) NOT NULL default '0', 
capitol_capsule tinyint(4) NOT NULL default '0', 
mirs_service tinyint(4) NOT NULL default '0', 
coverage_written tinyint(4) NOT NULL default '0', 
coverage_democrat tinyint(4) NOT NULL default '0', 
written_repub tinyint(4) NOT NULL default '0', 
ADeep tinyint(4) NOT NULL default '0', 
service tinyint(4) NOT NULL default '0', 
Mirs_update tinyint(4) NOT NULL default '0', 
competitor tinyint(4) NOT NULL default '0', 
good tinyint(4) NOT NULL default '0', 
accounts tinyint(4) NOT NULL default '0', 
list tinyint(4) NOT NULL default '0', 
bill tinyint(4) NOT NULL default '0', 
price tinyint(4) NOT NULL default '0', 
staff tinyint(4) NOT NULL default '0', 
Rreport tinyint(4) NOT NULL default '0', 
BCalendar tinyint(4) NOT NULL default '0', 
Inet tinyint(4) NOT NULL default '0', 
Attn tinyint(4) NOT NULL default '0', 
version tinyint(4) NOT NULL default '0', 
email tinyint(4) NOT NULL default '0', 
Mirs_text tinyint(4) NOT NULL default '0', 
list_fundraisers tinyint(4) NOT NULL default '0', 
content_capsule tinyint(4) NOT NULL default '0', 
Mirs_content tinyint(4) NOT NULL default '0', 
Mirs_cover tinyint(4) NOT NULL default '0', 
Mirs_delivery tinyint(4) NOT NULL default '0', 
Mirs_online tinyint(4) NOT NULL default '0', 
Mirs_search tinyint(4) NOT NULL default '0', 
Mirs_newsemail tinyint(4) NOT NULL default '0', 
Mirs_anotherletter tinyint(4) NOT NULL default '0', 
Mirs_otherbipolitical tinyint(4) NOT NULL default '0', 
Mirs_servicecharge tinyint(4) NOT NULL default '0', 
Mirs_keyissues tinyint(4) NOT NULL default '0', 
Mirs_othernewsletters tinyint(4) NOT NULL default '0', 
Mirs_providemore tinyint(4) NOT NULL default '0', 
Mirs_judicial tinyint(4) NOT NULL default '0', 
mirs_aspects varchar(255) default NULL, 
mirs_likeleast varchar(255) default NULL, 
PRIMARY KEY (qno), 
UNIQUE KEY qno (qno), 
KEY qno_2 (qno), 
FULLTEXT KEY emailid (emailid) 
) 
The column that is not getting inserted are
mirs_aspects varchar(255) default NULL, 
mirs_likeleast varchar(255) default NULL, 
emailid varchar(255) default NULL, 
date date default NULL, 
the script can be acessed online at 
(http://www.enddebtmisery.com/sri/survey.php).
Any thoughts/ideas?
Thanks
Sri
Message #2 by "David Scott-Bigsby" <DScott-Bigsby@P...> on Wed, 18 Sep 2002 13:59:25 -0700
> I have a php form which inserts records into the mysql db.
> All the columns
> are getting inserted except 4 columns.
> My table script is this:
> CREATE TABLE mirs_survey1 (
> ...
> mirs_likeleast varchar(255) default NULL,
> PRIMARY KEY (qno),
> UNIQUE KEY qno (qno),
> KEY qno_2 (qno),
> FULLTEXT KEY emailid (emailid)
> )
> The column that is not getting inserted are
> mirs_aspects varchar(255) default NULL,
> mirs_likeleast varchar(255) default NULL,
> emailid varchar(255) default NULL,
> date date default NULL,
> the script can be acessed online at
> (http://www.enddebtmisery.com/sri/survey.php).
> Any thoughts/ideas?

I don't understand -- are you trying to create the table each time your 
a user submits their survey data?

dsb

***************************************       
David Scott-Bigsby
Product Manager, Web Site and PEDN

PureEdge Solutions
The Leader in Secure XML e-Forms

v:250-708-8145  f:250-708-8010
1-888-517-2675   www.PureEdge.com
***************************************
Message #3 by "Srinivasan Prasanna" <Sri_core@m...> on Wed, 18 Sep 2002 22:22:30
Sorry I was not clear. Oh no I am not creating table each time. I am 
trying to insert record from a form. All the values gets into the DB 
except these columns.
Thanks
Sri

> > I have a php form which inserts records into the mysql db.
> All the columns
> are getting inserted except 4 columns.
> My table script is this:
> CREATE TABLE mirs_survey1 (
> ...
> mirs_likeleast varchar(255) default NULL,
> PRIMARY KEY (qno),
> UNIQUE KEY qno (qno),
> KEY qno_2 (qno),
> FULLTEXT KEY emailid (emailid)
> )
> The column that is not getting inserted are
> mirs_aspects varchar(255) default NULL,
> mirs_likeleast varchar(255) default NULL,
> emailid varchar(255) default NULL,
> date date default NULL,
> the script can be acessed online at
> (http://www.enddebtmisery.com/sri/survey.php).
> Any thoughts/ideas?

I don't understand -- are you trying to create the table each time your 
a user submits their survey data?

dsb

***************************************       
David Scott-Bigsby
Product Manager, Web Site and PEDN

PureEdge Solutions
The Leader in Secure XML e-Forms

v:250-708-8145  f:250-708-8010
1-888-517-2675   www.PureEdge.com
***************************************
Message #4 by "Nikolai Devereaux" <yomama@u...> on Wed, 18 Sep 2002 14:20:22 -0700
> Sorry I was not clear. Oh no I am not creating table each time. I am
> trying to insert record from a form. All the values gets into the DB
> except these columns.


I would think that the code that actually performed the _INSERT_ would be
more appropriate than the code that performed the CREATE...

That the insert is being completed successfully (i.e. without any mysql
errors) means that your INSERT query is syntactically correct.

The first thing I'd do is look for typos -- misspelled variables and the
like.

Also, echo your query to the screen before you execute it just to make sure
everything looks good to you.  You'll probably find that you're not actually
inserting anything into the columns you're having problems with.


nik

Message #5 by "Srinivasan Prasanna" <Sri_core@m...> on Wed, 18 Sep 2002 23:06:18
I think you are right but I am just not seeing any issue with the code. 
These are the 4 columns that are having issues.
$sql = "INSERT INTO mirs_survey1 
(qno,emailid,date,email_alert,capitol_capsule,mirs_service,coverage_written
,coverage_democrat,written_repub,ADeep,service,Mirs_update,competitor,good,
accounts,list,bill,price,staff,Rreport,BCalendar,Inet,Attn,version,email,Mi
rs_text,list_fundraisers,content_capsule,Mirs_content,Mirs_cover,Mirs_deliv
ery,Mirs_online,Mirs_search,Mirs_newsemail,Mirs_anotherletter,Mirs_otherbip
olitical,Mirs_servicecharge,Mirs_keyissues,Mirs_othernewsletters,Mirs_provi
demore,Mirs_judicial,Mirs_aspects,Mirs_likeleast) VALUES 
('','$emailid','$today','$email_alert','$capital_capsule','$mirs_service','
$coverage_written','$coverage_democrat','$written_repub','$ADeep','$service
','$Mirs_update','$competitor','$good','$accounts','$list','$bill','$price'
,'$staff','$Rreport','$BCalendar','$Inet','$Attn','$version','$email','$Mir
s_text','$list_fundraisers','$content_capsule','$Mirs_content','$Mirs_cover
','$Mirs_delivery','$Mirs_online','$Mirs_search','$Mirs_newsemail','$Mirs_a
notherletter','$Mirs_otherbipolitical','$Mirs_servicecharge','$Mirs_keyissu
es','$Mirs_othernewsletters','$Mirs_providemore','$Mirs_judicial', '$Mirs_a
spects','$Mirs_likeleast')";
$result = mysql_query($sql) or die (mysql_error());
echo "ThankYou!\n"; 
} 
else
{
?>
<form id="MIRSSURVEY" name="MIRSFORM" method="post" action="<?PHP echo 
$PHP_SELF?>">
  <p><FONT face=Arial>Email 
ID:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; 
  <INPUT type="text" name="emailid"value="emailid"</FONT> </P>
<p><FONT face=Arial>Today's 
Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp; 
  <INPUT type="text" name="date" value ="<?php $today = date("m.d.y"); 
print $today;?>"</FONT> </P>
 <p><FONT face=Arial>
39.)  In the space provided, please detail what aspects of MIRS' service 
you like the most.<br>
<Textarea name="mirs_aspects" cols=40 rows=8 
value="mirs_aspects"></textarea>
 </FONT> </P>
 <p><FONT face=Arial>
40.)  In the space provided, please detail what aspects of MIRS' service 
you like least.<br>
<Textarea name="mirs_likeleast" cols=40 rows=8 
value="mirs_likeleast"></textarea>
 </FONT> </P>
 	   </SELECT></FONT></TD></TR></TBODY></TABLE>
  <p><input type="Submit" name="submit" 
value="Submit">&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" 
value="Reset"></p>

Thoughts/ideas?
Thanks
Sri


I would think that the code that actually performed the _INSERT_ would be
more appropriate than the code that performed the CREATE...

That the insert is being completed successfully (i.e. without any mysql
errors) means that your INSERT query is syntactically correct.

The first thing I'd do is look for typos -- misspelled variables and the
like.

Also, echo your query to the screen before you execute it just to make sure
everything looks good to you.  You'll probably find that you're not 
actually
inserting anything into the columns you're having problems with.


nik

Message #6 by "Srinivasan Prasanna" <Sri_core@m...> on Wed, 18 Sep 2002 23:10:30
Also you are right I am not inserting any records from these variables 
into the DB.
The records I am inserting is like this.
INSERT INTO mirs_survey1 VALUES (8, '', '0000-00-00', 1, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, '', '');

2 is the emailID column, somehow the date is defaulting to 0000-00-00 and 
last 2 columns are '',''

Thanks
Sri

  Return to Index