Jump to content

[SOLVED] Unknown '???_type' in 'field list'


jmr3460

Recommended Posts

I have checked this more that 2 or 3 times. I am rather new to php/mysql and I am trying to get this address book going. I hate to post such a large file but here is the addentry.php file I am working on. Can someone help me with this.

<?php
include("include.php");

if (!$_POST) {
//haven't seen the form, so show it
$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/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=\"10\"></p>

<p><strong>Address Type:</strong><br/>
<input type=\"radio\" name=\"add_type\" value=\"home\"> 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\"> 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\"> 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\"> 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>

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

} else if ($_POST) {
//time to add to tables, so check for required fields
if (($_POST["f_name"] == "") || ($_POST["l_name"] == "")) {
	header("Location: addentry.php");
	exit;
}

//connect to database
include ('include.php');

//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 = mysql_query($add_master_sql) or die(mysql_error());

//get master_id for use with other tables
$master_id = mysql_insert_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 = mysql_query($add_address_sql) or die(mysql_error());
}

if ($_POST["tel_number"]) {
	//something relevant, so add to telephone table
	$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 = mysql_query($add_tel_sql) or die(mysql_error());
}

if ($_POST["fax_number"]) {
	//something relevant, so 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"]."')";
	$add_fax_res = mysql_query($add_fax_sql) or die(mysql_error());
}

if ($_POST["email"]) {
	//something relevant, so 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"]."')";
	$add_email_res = mysql_query($add_email_sql) or die(mysql_error());
}

if ($_POST["note"]) {
	//something relevant, so add to notes table
	$add_notes_sql = "INSERT INTO personal_notes (master_id, date_added, date_modified,
	                  note)  VALUES ('".$master_id."', now(), now(), '".$_POST["note"]."')";
	$add_notes_res = mysql_query($add_notes_sql) or die(mysql_error());
}
mysql_close();
$display_block = "<p>Your entry has been added.  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>

I have been looking for the problem in the INSERT statements am I on the right track. All of the table fields corresponds with the INSERT statements as well as the VALUES. 

 

I was just looking at my code. I have an id field in every table that is primary key auto_increment. Does it have to be added in the query?

Link to comment
https://forums.phpfreaks.com/topic/153773-solved-unknown-_type-in-field-list/
Share on other sites

I just noticed that everything I am trying to insert into my DB's are going to the DB's. There is a lot of entries I am getting the Unknown statement at the top of my result page. Humm Maybe that is what is happening.

 

Has it got something to do with the fact that I have my mysql_error() empty?

It appears that this error happens when I use my selentry.php file. Here is is:

<?php
include("include.php");


if (!$_POST)  {
//haven't seen the selection form, so show it
$display_block = "<h1>Select an Entry</h1>";

//get parts of records
$get_list_sql = "SELECT id,
                 CONCAT_WS(', ', l_name, f_name) AS display_name
                 FROM master_name ORDER BY l_name, f_name";
$get_list_res = mysql_query($get_list_sql) or die(mysql_error());

if (mysql_num_rows($get_list_res) < 1) {
	//no records
	$display_block .= "<p><em>Sorry, no records to select!</em></p>";

} else {
	//has records, so get results and print in a form
	$display_block .= "
	<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
	<p><strong>Select a Record to View:</strong><br/>
	<select name=\"sel_id\">
	<option value=\"\">-- Select One --</option>";

	while ($recs = mysql_fetch_array($get_list_res)) {
		$id = $recs['id'];
		$display_name = stripslashes($recs['display_name']);

		$display_block .= "<option value=\"".$id."\">".$display_name."</option>";
	}

	$display_block .= "
	</select>
	<p><input type=\"submit\" name=\"submit\" value=\"View Selected Entry\"></p>
	</form>";
}
//free result
mysql_free_result($get_list_res);

} else if ($_POST) {
//check for required fields
if ($_POST["sel_id"] == "")  {
	header("Location: selentry.php");
	exit;
}

//get master_info
$get_master_sql = "SELECT concat_ws(' ', f_name, l_name) as display_name
                   FROM master_name WHERE id = '".$_POST["sel_id"]."'";
$get_master_res = mysql_query($get_master_sql) or die(mysql_error());

while ($name_info = mysql_fetch_array($get_master_res)) {
	$display_name = stripslashes($name_info['display_name']);
}

$display_block = "<h1>Showing Record for ".$display_name."</h1>";

//free result
mysql_free_result($get_master_res);

//get all addresses
$get_addresses_sql = "SELECT address, city, state, zipcode, type
                      FROM address WHERE master_id = '".$_POST["sel_id"]."'";
$get_addresses_res = mysql_query($get_addresses_sql) or die(mysql_error());

	if (mysql_num_rows($get_addresses_res) > 0) {

	$display_block .= "<p><strong>Addresses:</strong><br/>
	<ul>";

	while ($add_info = mysql_fetch_array($get_addresses_res)) {
		$address = stripslashes($add_info['address']);
		$city = stripslashes($add_info['city']);
		$state = stripslashes($add_info['state']);
		$zipcode = stripslashes($add_info['zipcode']);
		$address_type = $add_info['type'];

		$display_block .= "<li>$address $city $state $zipcode ($address_type)</li>";
	}

	$display_block .= "</ul>";
}

//free result
mysql_free_result($get_addresses_res);

//get all tel
$get_tel_sql = "SELECT tel_number, type FROM telephone
                WHERE master_id = '".$_POST["sel_id"]."'";
$get_tel_res = mysql_query($get_tel_sql) or die(mysql_error());

if (mysql_num_rows($get_tel_res) > 0) {

	$display_block .= "<p><strong>Telephone:</strong><br/>
	<ul>";

	while ($tel_info = mysql_fetch_array($get_tel_res)) {
		$tel_number = stripslashes($tel_info['tel_number']);
		$tel_type = $tel_info['type'];

		$display_block .= "<li>$tel_number ($tel_type)</li>";
	}

	$display_block .= "</ul>";
}

//free result
mysql_free_result($get_tel_res);

//get all fax
$get_fax_sql = "SELECT fax_number, fax_type FROM fax
                WHERE master_id = '".$_POST["sel_id"]."'";
$get_fax_res = mysql_query($get_fax_sql) or die(mysql_error());

if (mysql_num_rows($get_fax_res) > 0) {

	$display_block .= "<p><strong>Fax:</strong><br/>
	<ul>";

	while ($fax_info = mysql_fetch_array($get_fax_res)) {
		$fax_number =  stripslashes($fax_info['fax_number']);
		$fax_type = $fax_info['type'];

		$display_block .= "<li>$fax_number ($fax_type)</li>";
	}

	$display_block .= "</ul>";
}

//free result
mysql_free_result($get_fax_res);

//get all email
$get_email_sql = "SELECT email, email_type FROM email
                  WHERE master_id = '".$_POST["sel_id"]."'";
$get_email_res = mysql_query($get_email_sql) or die(mysql_error());

 if (mysql_num_rows($get_email_res) > 0) {

	$display_block .= "<p><strong>Email:</strong><br/>
	<ul>";

	while ($email_info = mysql_fetch_array($get_email_res)) {
		$email = stripslashes($email_info['email']);
		$email_type = $email_info['type'];

		$display_block .= "<li>$email ($email_type)</li>";
	}

	$display_block .= "</ul>";
}

//free result
mysql_free_result($get_email_res);

//get personal note
$get_notes_sql = "SELECT note FROM personal_notes
                  WHERE master_id = '".$_POST["sel_id"]."'";
$get_notes_res = mysql_query($get_notes_sql) or die(mysql_error());

if (mysql_num_rows($get_notes_res) == 1) {
	while ($note_info = mysql_fetch_array($get_notes_res)) {
		$note = nl2br(stripslashes($note_info['note']));
	}

	$display_block .= "<p><strong>Personal Notes:</strong><br/>$note</p>";
}

//free result
mysql_free_result($get_notes_res);

$display_block .= "<br/>
<p align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."\">select another</a></p>";
}
//close connection to MySQL
mysql_close();
?>
<html>
<head>
<title>My Records</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>

Sorry everything seems to get so frantic on my end I am testing and retesting and I get lost sometimes when I am searching for a solution to my problems. Thanks for your patience.

I found the problem. I had changed some types in my queries from type to fax_type and did not change back. It took me reading line by line for me to see the issue. I did the same to my email type.

I know that I did not get any replies but it helps me see possible issues when I read it in English on this forum. I am learning slowly but surely. 

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.