I'm in my third week ever of writing in PHP for school. Last week we had to make a PHP RSVP form that validated every field. I got a B despite my form not functioning properly. This week we need to take the info from the form and input it into a database. I keep getting this error:
Parse error: syntax error, unexpected T_STRING in ....../test/test.php on line 77
Here is the code.... I feel like it's horrible, but the professor isn't much help. Any idea why I am getting that error?
This is line 77 & 78:
$connectID = mysql_connect($host, $username, $password) or die(mysql_error(Sorry, cannot connect to the database.));
mysql_select_db('mverminski', $connectID) or die(mysql_error(Unable to connect to database.));
Code:<?php // show form fields when submitted if ($_POST['submitted']) { $first_name = @$_POST['first_name']; $last_name = @$_POST['last_name']; $address = @$_POST['address']; $city = @$_POST['city']; $state = @$_POST['state']; $postal_code = @$_POST['postal_code']; $phone_number = @$_POST['phone_number']; $rsvp = @$_POST['rsvp']; $image = @$_POST['image']; // validate $error_msg=array(); if ($first_name=="") { $error_msg[] ="You must enter your first name<br />"; } if ($last_name=="") { $error_msg[] ="You must enter your last name<br />"; } if ($address=="") { $error_msg[] ="You must enter your address<br />"; } if ($city=="") { $error_msg[] ="You must enter your city<br />"; } if ($state=="") { $error_msg[] ="You must enter your state<br />"; } if (strlen($state)>2) { $error_msg[] ="State must contain only two letters<br/>"; } if (!strlen($postal_code)<5) { $error_msg[] ="You must enter a valid 5 digit postal code<br />"; } if (!eregi('^[[:digit:]]+$',$postal_code)) { $error_msg[] ="You must enter a valid postal code<br />"; } if (eregi('^([[:digit:]]| |-)+$', $phone_number)) { $error_msg[] = ("Please enter a valid phone number"); } if ($image=="") { $error_msg[] ="You must upload an image.<br />"; } foreach ($error_msg as $err) { echo ("$err <br />"); if (!error_msg) { header ('Location: thanks.php'); exit(); } } //database variables $host="mverminski.db.3327979.hostedresource.com"; $username="xxxxxxxxx"; $password="xxxxxxxx"; $db_name="xxxxxxxx"; $tbl_name="Christmas Party"; //Connect to database $connectID = mysql_connect($host, $username, $password) or die(mysql_error(Sorry, cannot connect to the database.)); mysql_select_db('mverminski', $connectID) or die(mysql_error(Unable to connect to database.)); //insert data into database $query="INSERT INTO $tbl_name (first name, last name, address, city, state, postal code, phone number, rsvp, image) VALUES ('$first_name', '$last_name', '$address', '$city', '$state', '$postal_code', '$phone_number', '$rsvp', '$image')"; If ($result) { echo "Success!"; echo "<br>"; echo "<a href='data.php'>View your form</a>"; } else echo "ERROR"; } mysql_close(); } ?> <html> <head> <title>Christmas Party</title> </head> <body> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST"> <h4>Company Christmas Party!</h4> <?php if ($error_msg) { echo "<ul>\n"; foreach ($error_msg as $err) { echo "<li>".$err."</li>\n"; } echo "</ul>\n"; } ?> <label for="first_name">First Name*</label><br /> <input name="first_name" type="text" size="20" id="first_name" value="<?php echo $first_name ?>"/><br/> <label for="last_name">Last Name*</label><br /> <input name="last_name" type="text" size="20" id="last_name" value="<?php echo $last_name ?>" /><br/> <label for="first_name">Address*</label><br /> <input name="address" type="text" size="40" id="address" value="<?php echo $address ?>" /><br/> <label for="first_name">City*</label><br /> <input name="city" type="text" size="20" id="city" value="<?php echo $city ?>" /><br/> <label for="first_name">State*</label><br /> <input name="state" type="text" size="2" id="state" value="<?php echo $state ?>" /><br/> <label for="first_name">Postal Code*</label><br /> <input name="postal_codee" type="text" size="5" id="postal_code" value="<?php echo $postal_code ?>" /><br/> <label for="first_name">Phone Number*</label><br /> <input name="phone_number" type="text" size="10" id="phone_number" value="<?php echo $phone_number ?>" /> <form action="./result.php" method="post"> <p>Will you be attending?<br/> <label for="rsvp_yes">Yes</label> <input type="radio" name="rsvp_yes" value="yes" /><br /> <label for="rsvp_no">No</label> <input type="radio" name="rsvp_no" value="no" /><br /> <form action="./upload.php" method="post" enctype="multipart/form-data"> <p> <label for="image">Select an image:</label> <input name="image" type="file" id="image" value="<?php echo $image ?>"> <br /> <p> </form> <input type="hidden" name="submitted" value="1" /> <input type="submit" value="Submit" /> </form> </body> </html>



Reply With Quote






Bookmarks