Hello everyone:
Once again I need help. I'm trying to make a address book and it's not working. The data is not displaying and is not going to the db. I think it has to do with the id, master_id or the date_added, date_modified fields
Here is my code for the address -
<?php
-
if (($_POST[op] != "add") || ($_GET[master_id] != "")) {
-
//haven't seen the form, so show it
-
$display_block = "
-
<h1>Add an Entry</h1>
-
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">";
-
-
if ($_GET[master_id] != "") {
-
//connect to database
-
$conn = mysql_connect("localhost", "nomad", "nomad")
-
or die(mysql_error());
-
mysql_select_db("teamvelo",$conn) or die(mysql_error());
-
-
//get first, last names for display/tests validity
-
$get_names = "select concat_ws(' ', f_name, l_name) as
-
display_name from master_name where id = $_GET[master_id]";
-
$get_names_res = mysql_query($get_names) or die(mysql_error());
-
-
if (mysql_num_rows($get_names_res) == 1) {
-
$display_name = mysql_result($get_names_res,0,'display_name');
-
}
-
}
-
-
if ($display_name != "") {
-
$display_block .= "<P>Adding information for
-
<strong>$display_name</strong>:</p>";
-
} else {
-
$display_block .= "
-
<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>";
-
}
-
$display_block .= "<P><strong>Address:</strong><br>
-
<input type=\"text\" name=\"address\" size=30>
-
-
<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><strong>Telephone Number:</strong><br>
-
<input type=\"text\" name=\"tel_number\" size=30 maxlength=25>
-
-
<P><strong>Cell Number:</strong><br>
-
<input type=\"text\" name=\"cell_number\" size=30 maxlength=25>
-
-
<P><strong>Email Address:</strong><br>
-
<input type=\"text\" name=\"email\" size=30 maxlength=150>
-
-
<P><strong>Emergency Name:</strong><br>
-
<input type=\"text\" name=\"contact_name\" size=30 maxlength=75>
-
<P><strong>Emergency Phone:</strong><br>
-
<input type=\"text\" name=\"contact_phone\" size=25 maxlength=25>
-
-
<p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p>
-
</FORM>";
-
-
} else if ($_POST[op] == "add") {
-
//time to add to tables, so check for required fields
-
if ((($_POST[f_name] == "") || ($_POST[l_name] == "")) && ($_POST[master_id] == "")) {
-
header("Location: addentry2.php");
-
exit;
-
}
-
-
//connect to database
-
$conn = mysql_connect("localhost", "nomad", "nomad") or die(mysql_error());
-
mysql_select_db("teamvelo",$conn) or die(mysql_error());
-
-
if ($_POST[master_id] == "") {
-
//add to master_name table
-
$add_master = "insert into master_name values ('', now(), now(), '$_POST[f_name]', '$_POST[l_name]')";
-
mysql_query($add_master) or die(mysql_error());
-
-
//get master_id for use with other tables
-
$master_id = mysql_insert_id();
-
} else {
-
$master_id = $_POST[master_id];
-
}
-
-
if (($_POST[address]) || ($_POST[city]) || ($_POST[state]) || ($_POST[zipcode])) {
-
//something relevant, so add to address table
-
$add_address = "replace into address values ('', $master_id, now(), now(), '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zipcode]')";
-
mysql_query($add_address) or die(mysql_error());
-
}
-
-
if ($_POST[tel_number]) {
-
//something relevant, so add to telephone table
-
$add_tel = "replace into telephone values ('', $master_id, now(), now(), '$_POST[tel_number]')";
-
mysql_query($add_tel) or die(mysql_error());
-
}
-
-
if ($_POST[cell_number]) {
-
//something relevant, so add to fax table
-
$add_cell = "replace into cell values ('', $master_id, now(), now(), '$_POST[cell_number]')";
-
mysql_query($add_cell) or die(mysql_error());
-
}
-
-
if ($_POST[email]) {
-
//something relevant, so add to email table
-
$add_email = "replace into email values ('', $master_id, now(), now(), '$_POST[email]')";
-
mysql_query($add_email) or die(mysql_error());
-
}
-
-
if ($_POST[emergency]) {
-
//something relevant, so add to notes table
-
$add_emergency = "replace into emergency values ('', $master_id, now(), now(), '$_POST[contact_name]', '$_POST[contact_phone]')";
-
mysql_query($add_emergency) or die(mysql_error());
-
}
-
-
$display_block = "<h1>Entry Added</h1>
-
<P>Your entry has been added. Would you like to
-
<a href=\"addentry2.php\">add another</a>?</p>";
-
}
-
?>
-
<HTML>
-
<HEAD>
-
<TITLE>Add an Entry</TITLE>
-
</HEAD>
-
<BODY>
-
<?php echo $display_block; ?>
-
</BODY>
-
</HTML>
-
-
Here are my tables - CREATE TABLE `teamvelo`.`master_name` (
-
`id` INT NOT NULL AUTO_INCREMENT ,
-
`date_added` DATETIME NOT NULL ,
-
`date_modified` DATETIME NOT NULL ,
-
`f_name` VARCHAR( 75 ) NOT NULL ,
-
`l_name` VARCHAR( 75 ) NOT NULL ,
-
PRIMARY KEY ( `id` )
-
) ENGINE = MYISAM ;
-
-
-
CREATE TABLE `teamvelo`.`address` (
-
`id` INT NOT NULL AUTO_INCREMENT ,
-
`user_id` INT( 11 ) NOT NULL ,
-
`date_added` DATETIME NOT NULL ,
-
`date_modified` DATETIME NOT NULL ,
-
`address` VARCHAR( 255 ) NOT NULL ,
-
`city` VARCHAR( 50 ) NOT NULL ,
-
`state` CHAR( 2 ) NOT NULL ,
-
`zipcode` VARCHAR( 10 ) NOT NULL ,
-
`enum` ENUM( 'home', 'work', 'other' ) NOT NULL ,
-
PRIMARY KEY ( `id` )
-
-
-
CREATE TABLE `teamvelo`.`telephone` (
-
`id` INT NOT NULL AUTO_INCREMENT ,
-
`master_id` INT( 11 ) NOT NULL ,
-
`date_added` DATETIME NOT NULL ,
-
`date_modified` DATETIME NOT NULL ,
-
`tel_number` VARCHAR( 25 ) NOT NULL ,
-
`type` ENUM( 'home', 'work', 'other' ) NOT NULL ,
-
PRIMARY KEY ( `id` )
-
) ENGINE = MYISAM ;
-
-
CREATE TABLE `teamvelo`.`cell` (
-
`id` INT NOT NULL AUTO_INCREMENT ,
-
`master_id` INT( 11 ) NOT NULL ,
-
`date_added` DATETIME NOT NULL ,
-
`date_modified` DATETIME NOT NULL ,
-
`cell_number` VARCHAR( 25 ) NOT NULL ,
-
`type` ENUM( 'home', 'work', 'other' ) NOT NULL ,
-
PRIMARY KEY ( `id` )
-
) ENGINE = MYISAM ;
-
-
CREATE TABLE `teamvelo`.`emergency` (
-
`id` INT NOT NULL AUTO_INCREMENT ,
-
`master_id` INT( 11 ) NOT NULL ,
-
`date_added` DATETIME NOT NULL ,
-
`date_modified` DATETIME NOT NULL ,
-
`contact_name` VARCHAR( 75 ) NOT NULL ,
-
`contact_phone` VARCHAR( 25 ) NOT NULL ,
-
`type` ENUM( 'home', 'work', 'other' ) NOT NULL ,
-
PRIMARY KEY ( `id` )
-
) ENGINE = MYISAM ;
Any help or direction would be great.
Thanks
Damon
4 1737
Hello
you have entered a big program. I didnt read it. I will suggest you, if connecting and database choosing is success full but db read or write is making trouble. Then
first echo the query to the browser then copy the output and directly try from database client. see if it work other wise if there is a error you will be able to figure it out.
Regards,
Johny
no echo return I even deleted all the input fields to just to fields f_name and l_names, I know the info is to going to the db.
damon
Atli 5,058
Expert 4TB
Hey.
On line #58 you check for the value of $_POST[op], but I don't see a op field in your form. Did you forget to add a hidden field there?
Also, a couple of things that you should check out: - Your code is wide open to SQL Injection. You should never use raw user input in SQL queries, or you make it easy for malicious users to do all sorts of nasty things to your database. (And yes, they are out there, and they will attack you. Be paranoid, be veeery paranoid!)
- You should always quote the names of array indexes. That is:
-
// This is INCORRECT. Will cause a notice.
-
$value = $_POST[value]
-
-
// It should be:
-
$value = $_POST['value'];
-
Associative array elements; elements that have a name, rather than a number; should always be quoted. They are strings, and strings need to be quoted. Otherwise PHP will consider them constants. - PHP does give you a bit of rope here, and converts non-existing constant names into strings when called, but that does not mean it is OK to do so. (It's sloppy! :P)
- When you check the value of an array element that may not exist - which includes ALL values in the $_POST and $_GET arrays - you should make sure they exist before you check their values. Otherwise you may get an error notice. (Production servers suppress them, but they are still there.)
-
// To check for an empty value do:
-
if(isset($_POST['elem']) && empty($_POST['elem']));
-
-
// To check for a specific value do:
-
if(isset($_POST['elem']) && $_POST['elem'] == 'my value');
-
The main thing here is to always use the isset function on an unknown array element before using it.
A somewhat questionable, yet sometimes useful, alternative is to manually suppress the error by prepend the value with @. - $value = @$_POST['value'];
You should go very carefully about using this, and only do so when absolutely needed
- You should always try to have an else clause on if statements that are crucial to how the page is displayed. In your case, if both the if and else if are false, then nothing is displayed.
-
/** Instead of doing **/
-
if(!isset($_POST['op']) || empty($_POST['op'])) {
-
// Show form
-
}
-
else if($_POST['op'] == 'add') {
-
// Add stuff
-
}
-
else if($_POST['op'] == 'edit') {
-
// Edit stuff
-
}
-
-
/** It would be better to do **/
-
if(isset($_POST['op']) && $_POST['op'] == 'add') {
-
// Add stuff
-
}
-
else if(isset($_POST['op']) && $_POST['op'] == 'edit') {
-
// Edit stuff
-
}
-
else {
-
// Show form
-
}
As always Atli you are a great help
damon
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Zap |
last post by:
Widespread opinion is that public data members are evil, because if you
have to change the way the data is stored in your class you have to
break the code accessing it, etc.
After reading this...
|
by: sandSpiderX |
last post by:
Hi,
I have to develop a program to compute range of all data types at run
time...
meaning say char c;
now I have to see how many characters char can represent,,
one logic i think is to...
|
by: Neil Ginsberg |
last post by:
I'm having some problems with an Access 2000 MDB file with a SQL Server 7
back end, using ODBC linked tables. I previously wrote about this, but am
reposting it with some additional information and...
|
by: Johnny Google |
last post by:
Here is an example of the type of data from a file I will have:
Apple,4322,3435,4653,6543,4652
Banana,6934,5423,6753,6531
Carrot,3454,4534,3434,1111,9120,5453
Cheese,4411,5522,6622,6641
The...
|
by: hoopsho |
last post by:
Hi Everyone,
I am trying to write a program that does a few things very fast
and with efficient use of memory...
a) I need to parse a space-delimited file that is really large,
upwards fo a...
|
by: Sam Berry |
last post by:
I am in need of some guidance on asscessing the same data from multiple
forms. I tried using a collection, but everytime that I try to access the
collection, I have to use the new word.
colStuff...
|
by: George Durzi |
last post by:
I have a company form that I need to web-enable. The form has about 50 data
items with some of these data items able to have N sub data items. I'm
considering ways to store this form in my...
|
by: tshad |
last post by:
Is there a way to carry data that I have already read from the datagrid from
page to page?
I am looking at my Datagrid that I page through and when the user says get
the next page, I have to go...
|
by: Hannibal111111 |
last post by:
I found this code on a site for doing string encryption/decryption.
The string will encrypt fine, but I get this error when I try to
decrypt. Any idea why? I posted the code below.
The error...
|
by: TC |
last post by:
I need an automated procedure to copy data from an Access table to a
SQL Server table. Speed is important. What is the recommended
technique?
I can export the data from Access, copy it via FTP,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |