Click to See Complete Forum and Search --> : PHP MySQL Address book


crypto
12-18-2003, 10:34 PM
Ok I'v made a database in MySQL with all my address book in it and I'm trying to make the address book in PHP to easily be able to search it but my code isnt working my page with the form on works but the PHP page that searches the database and prints the resalts in the browser dosnt work below I have included my 'search.php'

<?php

require_once ('connect.php');
$query = "select concat(LAST_NAME, FIRST_NAME, INITIALS) as Name, concat(HOUSE_NO, STREET, POST_TOWN, POST_ZIP_CODE) as Address, concat(PHONE1, PHONE2, MOB1, MOB2) as Phone from names";
$result = @mysql_query ($query);

if ($result) {
echo '<table align="center" cellspacing="2" cellpadding="2">
<tr><td align="left"><b>Name</b></td><td align="left"><b>Address</b></td><td align="left"><b>Phone</b></td></tr>';

while ($row = mysql_fetch_array($result, YSQL_NUM)) {
echo "<tr><td align=\"left\">$row[0]</td><td align=\"left\">$row[1]</td></tr>\n";
}
echo '</table>';

mysql_free_result ($result);

} else {
echo '<p>The address list could not be found due to a system error. Sorry for any inconvenience.</p><p>' . mysql_error() . '</p>';
}

mysql_close();


?>

One thing i hope the code came up so you can see it. And can anyone please help me and tell me where I am going wrong.
Thankyou.

crypto
12-18-2003, 10:50 PM
Sorry I forgot to tell you what i see when i open it up.

I get the table headders come up(Name Address Phone) but no address list.

crypto
12-18-2003, 11:21 PM
ok my connect.php is
my username and my password are the username and password to get into the database and yes they are the right ones before you ask.

<?php

define ('user', 'my username');
define ('password', 'my password');
define ('host', 'localhost');
define ('name', 'addresses');
//echo (user),' ',(password),' ',(host),' ',(name);

$page_title = 'Address Book';
//include_once ('header.html');

$dbc = mysql_connect(host, user, password);
mysql_select_db (name);

//include_once ('footer.html');

?>

crypto
12-18-2003, 11:24 PM
ok and my index.php is here just so you know all i do so you can help.

<?php

echo '<form action="search.php" method="get" name="search_form"><p>First Name <input name="fn" type="text"></p>
<p>Secomd Name <input name="sn" type="text"></p>
<p><input name="search" type="submit" value="Search"></p></form>';


?>

this one just brings up the form with the input boxes and the search button. this one i know works.

crypto
12-21-2003, 11:56 AM
Ok i'v got that working now like it should it brings up all the names in my mysql database address book but now i want to enable a search that you type in on my index.php and desplay the results in the browser using search.php to do the search.

Can anyone help please.

JustKIDn
12-21-2003, 10:22 PM
O.k. a couple of things,

I would recomend you include; . mysql_error()
with your connect statements so it's easier to see what problems your having and where it's failing.

I don't see you using a WHERE statement. Something like;


"WHERE LAST_NAME=" . $_GET['id']


I may not have that just right, but you get the idea.

Also, your data isn't normalized.
example, if you had a name in there like;

Paul A Henry
123 street
My Town, My ZIP
Phone1, Phone2
Mob1, Mob2

Now if Paul Henry takes a wife say;
Mary A Henry

They will probably want to live together. Maybe even share the same phones.

Now you'll have to re-enter all the same data again (duplicated data);

123 street
My Town, My ZIP
Phone1, Phone2
Mob1, Mob2

It would be much better to break this into two or three tables something like;

tbl_names
-nid (primary, autonumber)
-aid (id from tbl_address)
-pid (id from tbl_phone)
-last
-first
-mid

tbl_address
-aid (primary, autonumber)
-nid (id from tbl_names)
-house
-street
-town
-zip

tbl_phone
-pid (primary, autonumber)
-nid (id from tbl_names)
-phone
-type (type of phone - ie. Mobile)

Now you can just add in Mary's name and connect the tables by the id's and MAH and PAH are married and living together without duplicate data.

just my .02 cents

bhavins18
11-15-2005, 03:19 AM
My Case Study is I have a CSV Format File Address Book with different Fields for every contact. For Ex. A Person having full name or only with First Name and Email address, Few with Address and with Personal Information.
How do i create a MySQL Database for the same?
Regards
Bhavin Shah