Jump to content

Help with php mysql and html forms


shalli

Recommended Posts

Hi

 

I am new to php and have been using sams teach yourself php and mysql book to build a basic address book. I keep getting this error which for the life of me I cant figure out what the problem is?  :confused: :confused: :confused: Can anyone help!!

 

The error I keep getting is: Parse error: syntax error, unexpected '{'

 

on the following snippet of code:

 

} else if ($_POST) {

// Time to add to tables, check for required fields

if (($_POST["f_name"] == "") || (($_POST["l_name"] == "") || (($_POST["tel_number"] == "") || (($_POST["email"] == "") {

header("location: addentry.php");

exit;

}

 

If anyone requires it I am also posting my source code for the whole page below:

thanks for your time in advance

 

shalli

 

 

<?php

 

include("dbconnect.php");

if  (!$_POST) {

 

$display_block = "

<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">

<p><strong>First/Last Names:</strong></br>

<input type=\"text\" name=\"f_name\" size=\"30\" maxlength=\"75\">

<input type=\"text\" name=\"l_name\" size=\"30\" maxlength=\"75\">

</p>

 

<p><strong>Address:</strong></br>

<input type=\"text\" name=\"address\" size=\"30\">

</p>

 

<p><strong>City/County/Postcode:</strong></br>

<input type=\"text\" name=\"City\" size=\"30\" maxlength=\"75\">

<input type=\"text\" name=\"County\" size=\"30\" maxlength=\"75\">

<input type=\"text\" name=\"Postcode\" size=\"30\" maxlength=\"7\">

</p>

 

<p><strong>Address Type:</strong></br>

<input type=\"radio\" name=\"add_type\" value=\"home\" checked> home

<input type=\"radio\" name=\"add_type\" value=\"work\"> work

<input type=\"radio\" name=\"add_type\" value=\"other\"> other

</p>

 

<p><strong>Telephone Number:</strong></br>

<input type=\"text\" name=\"tel_number\" size=\"30\" maxlength=\"25\">

<input type=\"radio\" name=\"tel_type\" value=\"home\" checked> home

<input type=\"radio\" name=\"tel_type\" value=\"work\"> work

<input type=\"radio\" name=\"tel_type\" value=\"other\"> other

</p>

 

<p><strong>Fax Number:</strong></br>

<input type=\"text\" name=\"fax_number\" size=\"30\" maxlength=\"25\">

<input type=\"radio\" name=\"fax_type\" value=\"home\" checked> home

<input type=\"radio\" name=\"fax_type\" value=\"work\"> work

<input type=\"radio\" name=\"fax_type\" value=\"other\"> other

</p>

 

<p><strong>Email Address:</strong></br>

<input type=\"text\" name=\"email\" size=\"30\" maxlength=\"150\">

<input type=\"radio\" name=\"email_type\" value=\"home\" checked> home

<input type=\"radio\" name=\"email_type\" value=\"work\"> work

<input type=\"radio\" name=\"email_type\" value=\"other\"> other

</p>

 

<p><strong>Account Names:</strong></br>

<input type=\"text\" name=\"account_name\" size=\"30\" maxlength=\"75\">

</p>

 

<p><strong>Personal Note:</strong></br>

<textarea name=\"note\" cols=\"35\" rows=\"3\" wrap=\"virtual\"></textarea>

</p>

 

<p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p>

</form>";

 

} else if ($_POST) {

// Time to add to tables, check for required fields

if (($_POST["f_name"] == "") || (($_POST["l_name"] == "") || (($_POST["tel_number"] == "") || (($_POST["email"] == "") {

header("location: addentry.php");

exit;

}

 

//connect to database

doDB();

 

//add to master_name table

$add_master_sql = "INSERT INTO master_name (date_added, date_modified, f_name, l_name) VALUES (now(), now(),'".$_POST["f_name"]."','".$_POST["l_name"]."')";

 

//show the data parsed to add_master_sql

$add_master_result = mysqli_query($mysqli, $add_master_sql) or die(mysqli_error($mysqli));

 

 

 

 

//get master_id for use with other tables

$master_id = mysqli_insert_id($mysqli);

 

if (($_POST["address"]) || ($_POST["city"]) || ($_POST["county"]) || ($_POST["postcode"])) {

 

//add to address table

$add_address_sql = "INSERT INTO address (master_id, date_added, date_modified, address, city, county, postcode, type) VALUES ('".$master_id."', now(), now(),'".$_POST["address"]."','".$_POST["city"]."','".$_POST["county"]."','".$_POST["postcode"]."','".$_POST["add_type"]."',)";

 

//show the data parsed to add_address_sql

$add_address_result = mysqli_query($mysqli, $add_address_sql) or die(mysqli_error($mysqli));

 

}

 

 

if ($_POST["tel_number"]) {

//add to telephone table

$add_telephone_sql = "INSERT INTO telephone (master_id, date_added, date_modified, tel_number, type) VALUES ('".$master_id."', now(), now(),'".$_POST["tel_number"]."','".$_POST["tel_type"]."')";

 

//show the data parsed to add_telephone_sql

$add_telephone_result = mysqli_query($mysqli, $add_address_sql) or die(mysqli_error($mysqli));

 

}

 

if ($_POST["fax_number"]) {

//add to fax table

$add_fax_sql = "INSERT INTO fax (master_id, date_added, date_modified, fax_number, type) VALUES ('".$master_id."', now(), now(),'".$_POST["fax_number"]."','".$_POST["fax_type"]."')";

 

//show the data parsed to add_fax_sql

$add_fax_result = mysqli_query($mysqli, $add_address_sql) or die(mysqli_error($mysqli));

 

}

 

if ($_POST["email"]) {

//add to email table

$add_email_sql = "INSERT INTO email (master_id, date_added, date_modified, email, type) VALUES ('".$master_id."', now(), now(),'".$_POST["email"]."','".$_POST["email_type"]."')";

 

//show the data parsed to add_email_sql

$add_email_result = mysqli_query($mysqli, $add_address_sql) or die(mysqli_error($mysqli));

 

}

 

if ($_POST["account_name"]) {

//add to account_name table

$add_accountname_sql = "INSERT INTO account_name (master_id, date_added, date_modified, account_name) VALUES ('".$master_id."', now(), now(),'".$_POST["account_name"]."')";

 

//show the data parsed to add_accountname_sql

$add_accountname_result = mysqli_query($mysqli, $add_address_sql) or die(mysqli_error($mysqli));

 

}

 

if ($_POST["note"]) {

//add to note table

$add_note_sql = "INSERT INTO personal_notes (master_id, date_added, date_modified, note) VALUES ('".$master_id."', now(), now(),'".$_POST["note"]."')";

 

//show the data parsed to add_note_sql

$add_note_result = mysqli_query($mysqli, $add_address_sql) or die(mysqli_error($mysqli));

 

}

 

mysqli_close($mysqli);

$display_block = "Your entry has been added successfully. Would you like to <a href=\"addentry.php\"> add another</a>?</p>";

 

  }

?>

<html>

<head>

<title>Add an entry</title>

</head>

<body>

<h1>Add an Entry</h1>

<?php echo $display_block; ?>

</body>

</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/178408-help-with-php-mysql-and-html-forms/
Share on other sites

there are code tags you should put code in by the way

 

if (($_POST["f_name"] == "") || (($_POST["l_name"] == "") || (($_POST["tel_number"] == "") || (($_POST["email"] == "") {

 

should be

 

if (($_POST["f_name"] == "") || (($_POST["l_name"] == "") || (($_POST["tel_number"] == "") || (($_POST["email"] == "")) {

 

simple syntax error. missing a closing ')' at the end of the if statement

Hi mikesta707

 

thank you for your response

 

I am a little confused as I have put a closing tag two lines below after exit you see:

 

  if (($_POST["f_name"] == "") || (($_POST["l_name"] == "") || (($_POST["tel_number"] == "") || (($_POST["email"] == "") {

      header("location: addentry.php");

      exit;

  }

 

I am still doing something wrong?? :confused:

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.