Hello again,
I'm having a problem and don't know what is causing it. I'm copying from a book. double checked and can't figure out why I'd be getting this error (below in quotes)
Link to live view of what is being accomplished (trying to be accomplished)
http://skywardz.com/address_book/addEntry.php

LINE 87 :

if(!$_POST['master_id']){

Notice: Undefined index: master_id in /hermes.../public_html/address_book/addEntry.php on line 87

Here is the script in full:

<?php

ini_set('display_errors',1);
error_reporting(E_ALL);

if((!$_POST)||(isset($_GET['master_id']))){

//Haven't seen form, so show it
$display_block ="<form method= \"POST\" action= \"".$_SERVER["PHP_SELF"]."\">";


if(isset($_GET['master_id'])){

//connect to database
$mysqli= mysqli_connect("someserverlocation.com","username","password","address_book");

//get first, last names for display/tests validity
$get_names_sql="SELECT CONCAT_WS(' ', f_name,l_name) AS display_name FROM master_name WHERE id='".$_GET['master_id']."'";
$get_names_res=mysqli_query($mysqli,$get_names_sql) or die(mysqli_error($mysqli));

if(mysqli_num_rows($get_names_res)==1){
while($name_info=mysqli_fetch_array($get_names_res)){
$display_name = stripslashes($name_info['display_name']);
}
}

}
if(isset($display_name)){

$display_block .= "<p>Adding information for: <strong>$display_name</strong></p>";
}else{
$display_block .="
<p><strong> First/Last Name:</strong><br/>
<input type=\"text\" name=\"f_name\" size=\"30\" maxlength=\"75\"><br />
<input type=\"text\" name=\"l_name\" size=\"30\" maxlength=\"75\"></p>";
}

$display_block.="<p><strong> Address:</strong><br/>
<input type=\"text\" name=\"address\" size=\"30\"></p>

<p><strong> City/State/Zip:</strong><br/>
<input type=\"text\" name=\"city\" size=\"30\" maxlength=\"50\">
<input type=\"text\" name=\"state\" size=\"5\" maxlength=\"2\">
<input type=\"text\" name=\"zipcode\" size=\"10\" maxlength=\"5\"></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=\"125\">
<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> Personal Note:</strong><br/>
<textarea name=\"note\" cols=\"35\" rows=\"3\" wrap=\"virtual\"></textarea></p>";

if($_GET){
$display_block .="<input type=\"hidden\" name=\"master_id\" value=\"".$_GET['master_id']."\">";

}$display_block.="<input type=\"submit\" name=\"submit\" value=\"Add Entry\"></form>";

}else if($_POST){
//time to add to tables, so check for required fields
if((($_POST["f_name"]=="")||($_POST["l_name"]==""))&&(!isset($_POST['master_id']))){
header("Loacation:addEntry.php");
exit;
}

//connect to database
$mysqli= mysqli_connect("someserverlocation.com","username","password","address_book");

if(!$_POST['master_id']){

//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"]."')";
$add_master_res = 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);
}else{
$master_id=$_POST['master_id'];
}


if(($_POST["address"])||($_POST["city"])||($_POST["state"])||($_POST["zipcode"])){
//something relevant, so add to address table
$add_address_sql="INSERT INTO address (master_id, date_added, date_modified, address, city, state, zipcode, type) VALUES('".$master_id."',now(),now(), '".$_POST["address"]."','".$_POST["city"]."','".$_POST["state"]."','".$_POST["zipcode"]."','".$_POST["add_type"]."')";
$add_address_res= mysqli_query($mysqli, $add_address_sql) or die (mysqli_error($mysqli));
}

if($_POST["tel_number"]){
$add_tel_sql="INSERT INTO telephone (master_id, date_added, date_modified, tel_number, type) VALUES('".$master_id."',now(),now(), '".$_POST["tel_number"]."','".$_POST["tel_type"]."')";
$add_tel_res= mysqli_query($mysqli, $add_tel_sql) or die (mysqli_error($mysqli));
}

if($_POST["fax_number"]){
$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"]."')";
$add_fax_res= mysqli_query($mysqli, $add_fax_sql) or die (mysqli_error($mysqli));
}

if($_POST["email"]){
$add_email_sql="INSERT INTO email (master_id, date_added, date_modified, email, type) VALUES('".$master_id."',now(),now(), '".$_POST["email"]."','".$_POST["email_type"]."')";
$add_email_res= mysqli_query($mysqli, $add_email_sql) or die ($mysqli_error($mysqli));
}

if($_POST["note"]){
$add_notes_sql="UPDATE INTO personal_notes set note='".$_POST['note']."' WHERE master_id= '".$master_id."'";
$add_notes_res= mysqli_query($mysqli, $add_notes_sql) or die (mysqli_error($mysqli));
}

mysqli_close($mysqli);
$display_block="<p>Your entry has been added.<br>Would you like to <a href=\"addEntry.php\">add another</a>?";
}

?>

Recommended Answers

All 13 Replies

hello
try this instead of your 87th line:

if(!empty($_POST['master_id']))

Doesn't pull up that error anymore BUT
(should this be another post?)

This error comes up. I don't see anything wrong with the coding, but I'm new. Frustrated because it appears who ever edited this book I'm learning from didn't appear to do a very good job.

Notice: Undefined index: f_name in /hermes/.../public_html/address_book/addEntry.php on line 79

Notice: Undefined index: f_name in /hermes/.../public_html/address_book/addEntry.php on line 90

Notice: Undefined index: l_name in /hermes/.../public_html/address_book/addEntry.php on line 90
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO personal_notes set note='w' WHERE master_id= '22'' at line 1

there isn't an update into

modify your update into personal_notes to just be

update personal_notes

That stopped the SQL syntax error but why wouldn't I be able to see 'f_name' and 'l_name' values?

where are you wanting to see them at?

errors, or just something with the display?

This error still comes up. I've looked through everything. and don't see any errors.

BUT when I try to update my contacts say with a 'work' number it adds it to my contact list as a new person with a comma as the name.

Notice: Undefined index: f_name in /hermes/.../public_html/address_book/addEntry.php on line 79

Notice: Undefined index: f_name in /hermes/.../public_html/address_book/addEntry.php on line 90

Notice: Undefined index: l_name in /hermes/.../public_html/address_book/addEntry.php on line 90

it thinks f_name and l_name are one field, and l_name isn't supplied

do an echo to see what you're query looks like, you'll see why whenever you see what the query really is

echo $add_master_sql;

do this before you set $add_master_res

it comes back as : Array

it appears to have a problem reading the $_POST

Notice: Undefined index: master_id in /hermes/bosweb/web185/b1859/sl.mavedog21/public_html/address_book/addEntry.php on line 99

lines 97 -100:

$master_id=mysqli_insert_id($mysqli);
}else{
$master_id=$_POST['master_id'];
}

any idea?

double quotes

$master_id=mysqli_insert_id($mysqli);
}else{
$master_id=$_POST["master_id"];
}

it didn't change anything.

Here's where the problems seem to be occuring but I can't find anything wrong with it.

if($_GET){
$display_block .="<input type=\"hidden\" name=\"master_id\" value=\"".$_GET['master_id']."\">";
}
$display_block.="<input type=\"submit\" name=\"submit\" value=\"Add Entry\"></form>";

}else if($_POST){

//time to add to tables, so check for required fields
if((($_POST["f_name"]=="")||($_POST["l_name"]==""))&&(!isset($_POST["master_id"]))){
header("Location:addEntry.php");
exit;

}
//connect to database
$mysqli= mysqli_connect("server","username","password","address_book");

if(!empty($_POST['master_id'])){

//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']."')";
$add_master_res = 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);
}else{
$master_id=$_POST["master_id"];
}

I changed your suggestion from

if(!empty($_POST["master_id"])){

to

if(!isset($_POST["master_id"])){

and now i only get this error

Notice: Undefined index: f_name in /hermes/.../public_html/address_book/addEntry.php on line 79

LINE 79: if((($_POST["f_name"]=="")||($_POST["l_name"]==""))&&(!isset($_POST["master_id"]))){

any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.