Forum Moderators: coopster
The HTML form page is quite large so I am removing the actual form table code. If I need to post that I will.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Parish Registration</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<img src="graphics/stt.banner2.gif" width="1000" height="175" />
<form method="post" action="insert.php" >
---REMOVED FOR POSTING OF MESSAGE---
<input type="submit" value="Submit" name="B1"></a><input type="reset" value="Reset" name="B2"></p>
</form>
and my Insert.php file is this.
<?php
/* Start of PHP3 Script */
/* Data of SQL-server */
$server= "myserver"; /* Address of database server */
$user= "myuserid"; /* Database username */
$_Password= "mypassword"; /* Database Password */
$database= "mydatabase"; /* name of database */
$table= "Member"; /* Name of table, you can select that */
$FamLast= $_POST['Family_Last'];
$famphone= $_POST['Family_Phone'];
$famlist= $_POST['Family_List'];
$famaddy= $_POST['Family_Address'];
$famcity= $_POST['Family_City'];
$famstate= $_POST['Family_State'];
$famzip= $_POST['Family_Zip'];
$hohfirst= $_POST['HOH_First'];
$hohmiddle= $_POST['HOH_Middle'];
$hohmaiden= $_POST['HOH_Maiden'];
$hohdob= $_POST['HOH_Birth'];
$hohrelig= $_POST['HOH_Religion'];
$hohprac= $_POST['HOH_Practicing'];
$hohbapt= $_POST['HOH_Baptised'];
$hohcath= $_POST['HOH_Bapcath'];
$hohcomm= $_POST['HOH_Cathcomm'];
$hohconf= $_POST['HOH_Confirm'];
$hohpof= $_POST['HOH_ProfFaith'];
$hohpofw= $_POST['HOH_POFwhen'];
$hohemp= $_POST['HOH_Employment'];
$hohtitle= $_POST['HOH_Title'];
$hohgrade= $_POST['HOH_Grade'];
$hohemp= $_POST['HOH_Employer'];
$hohwkph= $_POST['HOH_WkPhone'];
$spfirst= $_POST['SP_First'];
$spmiddle= $_POST['SP_Middle'];
$spmaiden= $_POST['SP_Maiden'];
$spdob= $_POST['SP_Birth'];
$sprelig= $_POST['SP_Religion'];
$spprac= $_POST['SP_Practicing'];
$spbapt= $_POST['SP_Baptised'];
$spcath= $_POST['SP_Bapcath'];
$spcomm= $_POST['SP_Cathcomm'];
$spconf= $_POST['SP_Confirm'];
$sppof= $_POST['SP_ProfFaith'];
$sppofw= $_POST['SP_POFwhen'];
$spemp= $_POST['SP_Employment'];
$sptitle= $_POST['SP_Title'];
$spgrade= $_POST['SP_Grade'];
$spemp= $_POST['SP_Employer'];
$spwkph= $_POST['SP_WkPhone'];
$marstat= $_POST['Mar_Status'];
$mardate= $_POST['MAR_Date'];
$marcath= $_POST['MAR_Cath'];
$marnote= $_POST['MAR_Note'];
$oth1name= $_POST['OTH1_Name'];
$oth1rel= $_POST['OTH1_Relation'];
$oth1sex= $_POST['OTH1_Sex'];
$oth1dob= $_POST['OTH1_DOB'];
$oth1cathbap= $_POST['OTH1_Baptism'];
$oth1comm= $_POST['OTH1_Communion'];
$oth1conf= $_POST['OTH1_Confirmation'];
$oth1sch= $_POST['OTH1_School'];
$oth1grd= $_POST['OTH1_Grade'];
$oth2name= $_POST['OTH2_Name'];
$oth2rel= $_POST['OTH2_Relation'];
$oth2sex= $_POST['OTH2_Sex'];
$oth2dob= $_POST['OTH2_DOB'];
$oth2cathbap= $_POST['OTH2_Baptism'];
$oth2comm= $_POST['OTH2_Communion'];
$oth2conf= $_POST['OTH2_Confirmation'];
$oth2sch= $_POST['OTH2_School'];
$oth2grd= $_POST['OTH2_Grade'];
$oth3name= $_POST['OTH3_Name'];
$oth3rel= $_POST['OTH3_Relation'];
$oth3sex= $_POST['OTH3_Sex'];
$oth3dob= $_POST['OTH3_DOB'];
$oth3cathbap= $_POST['OTH3_Baptism'];
$oth3comm= $_POST['OTH3_Communion'];
$oth3conf= $_POST['OTH3_Confirmation'];
$oth3sch= $_POST['OTH3_School'];
$oth3grd= $_POST['OTH3_Grade'];
$oth4name= $_POST['OTH4_Name'];
$oth4rel= $_POST['OTH4_Relation'];
$oth4sex= $_POST['OTH4_Sex'];
$oth4dob= $_POST['OTH4_DOB'];
$oth4cathbap= $_POST['OTH4_Baptism'];
$oth4comm= $_POST['OTH4_Communion'];
$oth4conf= $_POST['OTH4_Confirmation'];
$oth4sch= $_POST['OTH4_School'];
$oth4grd= $_POST['OTH4_Grade'];
$oth5name= $_POST['OTH5_Name'];
$oth5rel= $_POST['OTH5_Relation'];
$oth5sex= $_POST['OTH5_Sex'];
$oth5dob= $_POST['OTH5_DOB'];
$oth5cathbap= $_POST['OTH5_Baptism'];
$oth5comm= $_POST['OTH5_Communion'];
$oth5conf= $_POST['OTH5_Confirmation'];
$oth5sch= $_POST['OTH5_School'];
$oth5grd= $_POST['OTH5_Grade'];
$opnation= $_POST['Op_Nationality'];
$opspneed= $_POST['Op_SpecNeeds'];
$opsnhelp= $_POST['Op_SpecHelp'];
$ophandi= $_POST['Op_Handicap'];
$ophandhelp= $_POST['Op_HandHelp'];
$opnote= $_POST['Op_Note'];
/* Accessing SQL-server */
MYSQL_CONNECT($server, $user, $_Password) or die ( "<H3>Server unreachable</H3>");
MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");
/* Entering the values */
$query = "INSERT INTO $table VALUES(",'$FamLast', '$famphone', '$famlist', '$famaddy', '$famcity', '$famstate', '$famzip', '$hohfirst', '$hohmiddle', '$hohmaiden', '$hohdob', '$hohrelig', '$hohprac', '$hohbapt', '$hohcath', '$hohcomm', '$hohconf', '$hohpof', '$hohpofw', '$hohemp', '$hohtitle', '$hohgrade', '$hohemp', '$hohwkph', '$spfirst', '$spmiddle', '$spmaiden', '$spdob', '$sprelig', '$spprac', '$spbapt', '$spcath', '$spcomm', '$spconf', '$sppof', '$sppofw', '$spemp', '$sptitle', '$spgrade', '$spemp', '$spwkph', '$marstat', '$mardate', '$marcath', '$marnote', '$oth1name', '$oth1rel', '$oth1sex', '$oth1dob', '$oth1cathbap', '$oth1comm', '$oth1conf', '$oth1sch', '$oth1grd', '$oth2name', '$oth2rel', '$oth2sex', '$oth2dob', '$oth2cathbap', '$oth2comm', '$oth2conf', '$oth2sch', '$oth2grd', '$oth3name', '$oth3rel', '$oth3sex', '$oth3dob', '$oth3cathbap', '$oth3comm', '$oth3conf', '$oth3sch', '$oth3grd', '$oth4name', '$oth4rel', '$oth4sex', '$oth4dob', '$oth4cathbap', '$oth4comm', '$oth4conf', '$oth4sch', '$oth4grd', '$oth5name', '$oth5rel', '$oth5sex', '$oth5dob', '$oth5cathbap', '$oth5comm', '$oth5conf', '$oth5sch', '$oth5grd', '$opnation', '$opspneed', '$opsnhelp', '$ophandi', '$ophandhelp', '$opnote')");
MYSQL_QUERY($query)
/* Display number of entries */
$number=MYSQL_NUMROWS(MYSQL_QUERY( "SELECT * FROM $table"));
if ($number==0):
echo "database empty";
elseif ($number > 0):
echo "$number rows in database";
endif;
/* Close SQL-Connection */
MYSQL_CLOSE();
?>
So there it is, what am I missing?
[edited by: jatar_k at 3:02 pm (utc) on April 30, 2007]
[edit reason] fixed sidescroll and specifics [/edit]
your form tag implies that insert.php is located in the same folder as your reg form, is that actually the case?
some other thoughts
all php functions should be lowercase
when you use an 'or die' statement always include the error from mysql like so
mysql_connect($server, $user, $_Password) or die ( "<H3>Server unreachable" . mysql_error() . "</H3>");
mysql_select_db($database) or die ( "<H3>Database non existent" . mysql_error() . "</H3>");
you might as well use mysql_num_rows instead of MYSQL_NUMROWS as mysql_num_rows is the real function, the other is just an alias.
MYSQL_QUERY($query)
and you can add an or die there as well
mysql_query($query) or die ('<p>insert query failed: ' . mysql_error());
you can change your if statement syntax as well from
if ($number==0):
echo "database empty";
elseif ($number > 0):
echo "$number rows in database";
endif;
to
if ($number <= 0){
echo "database empty";
} else {
echo "$number rows in database";
}
this way the if covers 0 or less and the else can just be executed otherwise, no need for the if else
<added>I've never tried this
$number=MYSQL_NUMROWS(MYSQL_QUERY( "SELECT * FROM $table"));
so I am not sure if you can nest that. I usually do it in a couple steps
$result = mysql_query('select * from ' . $table) or die ('<p>select died: ' . mysql_error());
$number = mysql_num_rows($result);
Parse error: parse error, unexpected ',' in /homepages/10/d202105791/htdocs/insert.php on line 112
Line 112 is as follows;
$query = "INSERT INTO $table VALUES(",'$FamLast', '$famphone', '$famlist', '$famaddy', '$famcity', '$famstate', '$famzip', '$hohfirst', '$hohmiddle', '$hohmaiden', '$hohdob', '$hohrelig', '$hohprac', '$hohbapt', '$hohcath', '$hohcomm', '$hohconf', '$hohpof', '$hohpofw', '$hohemp', '$hohtitle', '$hohgrade', '$hohemp', '$hohwkph', '$spfirst', '$spmiddle', '$spmaiden', '$spdob', '$sprelig', '$spprac', '$spbapt', '$spcath', '$spcomm', '$spconf', '$sppof', '$sppofw', '$spemp', '$sptitle', '$spgrade', '$spemp', '$spwkph', '$marstat', '$mardate', '$marcath', '$marnote', '$oth1name', '$oth1rel', '$oth1sex', '$oth1dob', '$oth1cathbap', '$oth1comm', '$oth1conf', '$oth1sch', '$oth1grd', '$oth2name', '$oth2rel', '$oth2sex', '$oth2dob', '$oth2cathbap', '$oth2comm', '$oth2conf', '$oth2sch', '$oth2grd', '$oth3name', '$oth3rel', '$oth3sex', '$oth3dob', '$oth3cathbap', '$oth3comm', '$oth3conf', '$oth3sch', '$oth3grd', '$oth4name', '$oth4rel', '$oth4sex', '$oth4dob', '$oth4cathbap', '$oth4comm', '$oth4conf', '$oth4sch', '$oth4grd', '$oth5name', '$oth5rel', '$oth5sex', '$oth5dob', '$oth5cathbap', '$oth5comm', '$oth5conf', '$oth5sch', '$oth5grd', '$opnation', '$opspneed', '$opsnhelp', '$ophandi', '$ophandhelp', '$opnote')");
does that ") need to come off at the end? I I have the (", at the begining because the first field is an auto numbering key, is that correct?
[edited by: jatar_k at 4:11 pm (utc) on April 30, 2007]
[edit reason] fixed sidescroll [/edit]
Unexpected T_STRING in line 115.
That is the line I changed MYSQL_NUMROWS to mysql_num_rows
here's what I have
<?php
// Data of SQL-server
$server= "myserver"; /* Address of database server */
$user= "myuserid"; /* Database username */
$_Password= "mypassword"; /* Database Password */
$database= "mydatabase"; /* name of database */
$table= "Member"; /* Name of table, you can select that */
// form variables
$FamLast= $_POST['Family_Last'];
$famphone= $_POST['Family_Phone'];
$famlist= $_POST['Family_List'];
$famaddy= $_POST['Family_Address'];
$famcity= $_POST['Family_City'];
$famstate= $_POST['Family_State'];
$famzip= $_POST['Family_Zip'];
$hohfirst= $_POST['HOH_First'];
$hohmiddle= $_POST['HOH_Middle'];
$hohmaiden= $_POST['HOH_Maiden'];
$hohdob= $_POST['HOH_Birth'];
$hohrelig= $_POST['HOH_Religion'];
$hohprac= $_POST['HOH_Practicing'];
$hohbapt= $_POST['HOH_Baptised'];
$hohcath= $_POST['HOH_Bapcath'];
$hohcomm= $_POST['HOH_Cathcomm'];
$hohconf= $_POST['HOH_Confirm'];
$hohpof= $_POST['HOH_ProfFaith'];
$hohpofw= $_POST['HOH_POFwhen'];
$hohemp= $_POST['HOH_Employment'];
$hohtitle= $_POST['HOH_Title'];
$hohgrade= $_POST['HOH_Grade'];
$hohemp= $_POST['HOH_Employer'];
$hohwkph= $_POST['HOH_WkPhone'];
$spfirst= $_POST['SP_First'];
$spmiddle= $_POST['SP_Middle'];
$spmaiden= $_POST['SP_Maiden'];
$spdob= $_POST['SP_Birth'];
$sprelig= $_POST['SP_Religion'];
$spprac= $_POST['SP_Practicing'];
$spbapt= $_POST['SP_Baptised'];
$spcath= $_POST['SP_Bapcath'];
$spcomm= $_POST['SP_Cathcomm'];
$spconf= $_POST['SP_Confirm'];
$sppof= $_POST['SP_ProfFaith'];
$sppofw= $_POST['SP_POFwhen'];
$spemp= $_POST['SP_Employment'];
$sptitle= $_POST['SP_Title'];
$spgrade= $_POST['SP_Grade'];
$spemp= $_POST['SP_Employer'];
$spwkph= $_POST['SP_WkPhone'];
$marstat= $_POST['Mar_Status'];
$mardate= $_POST['MAR_Date'];
$marcath= $_POST['MAR_Cath'];
$marnote= $_POST['MAR_Note'];
$oth1name= $_POST['OTH1_Name'];
$oth1rel= $_POST['OTH1_Relation'];
$oth1sex= $_POST['OTH1_Sex'];
$oth1dob= $_POST['OTH1_DOB'];
$oth1cathbap= $_POST['OTH1_Baptism'];
$oth1comm= $_POST['OTH1_Communion'];
$oth1conf= $_POST['OTH1_Confirmation'];
$oth1sch= $_POST['OTH1_School'];
$oth1grd= $_POST['OTH1_Grade'];
$oth2name= $_POST['OTH2_Name'];
$oth2rel= $_POST['OTH2_Relation'];
$oth2sex= $_POST['OTH2_Sex'];
$oth2dob= $_POST['OTH2_DOB'];
$oth2cathbap= $_POST['OTH2_Baptism'];
$oth2comm= $_POST['OTH2_Communion'];
$oth2conf= $_POST['OTH2_Confirmation'];
$oth2sch= $_POST['OTH2_School'];
$oth2grd= $_POST['OTH2_Grade'];
$oth3name= $_POST['OTH3_Name'];
$oth3rel= $_POST['OTH3_Relation'];
$oth3sex= $_POST['OTH3_Sex'];
$oth3dob= $_POST['OTH3_DOB'];
$oth3cathbap= $_POST['OTH3_Baptism'];
$oth3comm= $_POST['OTH3_Communion'];
$oth3conf= $_POST['OTH3_Confirmation'];
$oth3sch= $_POST['OTH3_School'];
$oth3grd= $_POST['OTH3_Grade'];
$oth4name= $_POST['OTH4_Name'];
$oth4rel= $_POST['OTH4_Relation'];
$oth4sex= $_POST['OTH4_Sex'];
$oth4dob= $_POST['OTH4_DOB'];
$oth4cathbap= $_POST['OTH4_Baptism'];
$oth4comm= $_POST['OTH4_Communion'];
$oth4conf= $_POST['OTH4_Confirmation'];
$oth4sch= $_POST['OTH4_School'];
$oth4grd= $_POST['OTH4_Grade'];
$oth5name= $_POST['OTH5_Name'];
$oth5rel= $_POST['OTH5_Relation'];
$oth5sex= $_POST['OTH5_Sex'];
$oth5dob= $_POST['OTH5_DOB'];
$oth5cathbap= $_POST['OTH5_Baptism'];
$oth5comm= $_POST['OTH5_Communion'];
$oth5conf= $_POST['OTH5_Confirmation'];
$oth5sch= $_POST['OTH5_School'];
$oth5grd= $_POST['OTH5_Grade'];
$opnation= $_POST['Op_Nationality'];
$opspneed= $_POST['Op_SpecNeeds'];
$opsnhelp= $_POST['Op_SpecHelp'];
$ophandi= $_POST['Op_Handicap'];
$ophandhelp= $_POST['Op_HandHelp'];
$opnote= $_POST['Op_Note'];
/* Accessing SQL-server */
mysql_connect($server, $user, $_Password) or die ( "<H3>Server unreachable" . mysql_error() . "</H3>");
mysql_select_db($database) or die ( "<H3>Database non existent" . mysql_error() . "</H3>");
/* Entering the values */
$query = "INSERT INTO $table VALUES('','$FamLast', '$famphone', '$famlist', '$famaddy', '$famcity', '$famstate', '$famzip', '$hohfirst', '$hohmiddle', '$hohmaiden', '$hohdob', '$hohrelig', '$hohprac', '$hohbapt', '$hohcath', '$hohcomm', '$hohconf', '$hohpof', '$hohpofw', '$hohemp', '$hohtitle', '$hohgrade', '$hohemp', '$hohwkph', '$spfirst', '$spmiddle', '$spmaiden', '$spdob', '$sprelig', '$spprac', '$spbapt', '$spcath', '$spcomm', '$spconf', '$sppof', '$sppofw', '$spemp', '$sptitle', '$spgrade', '$spemp', '$spwkph', '$marstat', '$mardate', '$marcath', '$marnote', '$oth1name', '$oth1rel', '$oth1sex', '$oth1dob', '$oth1cathbap', '$oth1comm', '$oth1conf', '$oth1sch', '$oth1grd', '$oth2name', '$oth2rel', '$oth2sex', '$oth2dob', '$oth2cathbap', '$oth2comm', '$oth2conf', '$oth2sch', '$oth2grd', '$oth3name', '$oth3rel', '$oth3sex', '$oth3dob', '$oth3cathbap', '$oth3comm', '$oth3conf', '$oth3sch', '$oth3grd', '$oth4name', '$oth4rel', '$oth4sex', '$oth4dob', '$oth4cathbap', '$oth4comm', '$oth4conf', '$oth4sch', '$oth4grd', '$oth5name', '$oth5rel', '$oth5sex', '$oth5dob', '$oth5cathbap', '$oth5comm', '$oth5conf', '$oth5sch', '$oth5grd', '$opnation', '$opspneed', '$opsnhelp', '$ophandi', '$ophandhelp', '$opnote')";
mysql_query($query);
/* Display number of entries */
$result = mysql_query('select * from ' . $table) or die ('<p>select died: ' . mysql_error());
$number = mysql_num_rows($result);
if ($number <= 0){
echo "database empty";
} else {
echo "$number rows in database";
}
/* Close SQL-Connection */
mysql_close();
?>
man is that ever a lot of fields
I was messing around with creating a few tables and creating the relationships, but for what this is doing, I did not want to waste a bunch of time working with it. I know a bit about databases, but not enough to whip one out in an afternoon.
Well, I removed everything after the query to post the data into the db just to see if it would at lease create the record.
All that remains is
/* Close SQL-Connection */
mysql_close();
?>
I'm getting unexpected $ in line 116. Line 116 is?> to end the script.
[edited by: GordonEngquist at 5:07 pm (utc) on April 30, 2007]
but this throws no parse errors when I uploaded it to my server to test, it gives me lots of errors because the db doesn't exist but you should be able to sort that
/* Accessing SQL-server */
mysql_connect($server, $user, $_Password) or die ( "<H3>Server unreachable" . mysql_error() . "</H3>");
mysql_select_db($database) or die ( "<H3>Database non existent" . mysql_error() . "</H3>");
/* Entering the values */
$query = "INSERT INTO $table VALUES('','$FamLast', '$famphone', '$famlist', '$famaddy', '$famcity', '$famstate', '$famzip', '$hohfirst', '$hohmiddle', '$hohmaiden', '$hohdob', '$hohrelig', '$hohprac', '$hohbapt', '$hohcath', '$hohcomm', '$hohconf', '$hohpof', '$hohpofw', '$hohemp', '$hohtitle', '$hohgrade', '$hohemp', '$hohwkph', '$spfirst', '$spmiddle', '$spmaiden', '$spdob', '$sprelig', '$spprac', '$spbapt', '$spcath', '$spcomm', '$spconf', '$sppof', '$sppofw', '$spemp', '$sptitle', '$spgrade', '$spemp', '$spwkph', '$marstat', '$mardate', '$marcath', '$marnote', '$oth1name', '$oth1rel', '$oth1sex', '$oth1dob', '$oth1cathbap', '$oth1comm', '$oth1conf', '$oth1sch', '$oth1grd', '$oth2name', '$oth2rel', '$oth2sex', '$oth2dob', '$oth2cathbap', '$oth2comm', '$oth2conf', '$oth2sch', '$oth2grd', '$oth3name', '$oth3rel', '$oth3sex', '$oth3dob', '$oth3cathbap', '$oth3comm', '$oth3conf', '$oth3sch', '$oth3grd', '$oth4name', '$oth4rel', '$oth4sex', '$oth4dob', '$oth4cathbap', '$oth4comm', '$oth4conf', '$oth4sch', '$oth4grd', '$oth5name', '$oth5rel', '$oth5sex', '$oth5dob', '$oth5cathbap', '$oth5comm', '$oth5conf', '$oth5sch', '$oth5grd', '$opnation', '$opspneed', '$opsnhelp', '$ophandi', '$ophandhelp', '$opnote')";
mysql_query($query) or die ('<p>insert died: ' . mysql_error());
/* Display number of entries */
$query = 'select * from ' . $table;
$result = mysql_query($query) or die ('<p>select died: ' . mysql_error());
$number = mysql_num_rows($result);
if ($number <= 0){
echo "database empty";
} else {
echo "$number rows in database";
}
/* Close SQL-Connection */
mysql_close();
?>
usually if you get an error at the end of a script it is a missed {} or (), even sometimes a ;
brace being the most common
something like this
header('Lacation: thankyou.html');
obviously you have to make sure that your pagename is in there and the path is right
the most common mistake with using header is you get a 'headers already sent' error. There can be no output before you use header, even a blank line at the beginning of the file before your <?php tag is considered output.