Straightforward MySQL / PHP Script required for Contact Management information

Hello.

I am currently working on a project that now requires the ability for members to update/add their contact information to include NAME, TITLE, COMPANY, ADDRESS (1,2,3, TOWN, CITY, COUNTY, POSTCODE), PHONE, EMAIL, WEB ADDY to a database.  I am thinking MySQL.  A seperate script is also required to display this information (all of it) to a web page.  This script should include an option to search on the aforementioned fields and span the results across multiple pages.

I am very new to PHP / MySQL and am therefore not in a position to write the script.

Can anyone advise on a good 'out of the box' script to use or would you say this is something that requires a custom write?
andrewmilnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nicholassolutionsCommented:
I am having trouble posting to this question. This is a test. If it works I will post my real comment
0
nicholassolutionsCommented:
This is simple enough that I would suggest just writing your own script -- it will be a good way for you to learn the languages in any event. Some simple example code is below to help you along; I have not tested it, and it definitely needs some more work, but if you look it over you should be able to see what to do.

First, I would make the MySQL table as follows:

----------------------------------begin mysql code---------------------------------

CREATE TABLE contact_info (
 user_id INT(50) NOT NULL AUTO_INCREMENT PRIMARY KEY,
 name VARCHAR(50),
 title VARCHAR(40),
 company VARCHAR(35),
 address_1 VARCHAR(30),
 address_2 VARCHAR(30),
 address_3 VARCHAR(30),
 town VARCHAR(30),
 city VARCHAR(30),
 county VARCHAR(30),
 postcode VARCHAR(20),
 phone VARCHAR(20),
 email VARCHAR(50),
 web_addy VARCHAR(70)
);

------------------------end mysql code--------------------------------
0
nicholassolutionsCommented:
Then, you need a page for users to input their data. This is a page that prints a simple form, and then inputs the page into your database table created above. You might want to add some kind of password protection so that users can only update their own data. You can do this by adding a password field to your table, and only updating data if the password the user inputs is the same as the password you have stored. If you want to be really fancy, you can even encrypt the stored password. This is just a matter of how much you trust your users and how secure you need this to be.

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

nicholassolutionsCommented:
---------------------begin php code ||||||| filename: "update.php" -------------------------------------
<?php
//we will use the variable $func to sort out what the script needs to do
 //not 1, 2, 3, 4--> add new user info, part 1
 // 1 --> add new user info, part 2
 // 2 ---> update current user info, part 1
 // 3 ---> update current user info, part 2
 // 4 ---> update current user info, part 3

0
nicholassolutionsCommented:
if ($_POST['func']>0 AND $_POST['func']<5){      //print the form

print <<<EOF
  Enter new user info below:
 <form method="post">
Name<input type="text" name="name"><br>
Title<input type="text" name="title"><br>
Company<input type="text" name="comp"><br>
Address Line 1<input type="text" name="add1"><br>
Address Line 2<input type="text" name="add2"><br>
Address Line 3<input type="text" name="add3"><br>
Town<input type="text" name="town"><br>
City<input type="text" name="city"><br>
0
nicholassolutionsCommented:

County<input type="text" name="county"><br>
Post Code<input type="text" name="postcode"><br>
Phone<input type="text" name="phone"><br>
Email<input type="text" name="email"><br>
Web Address<input type="text" name="webadd"><br>
<input type="hidden" name="func" vlaue="1">
 <input type="submit" value="submit">
 </form><br><br>

EOF;

echo 'If you want to update a current record, <a href="update.php?func=2">Click Here</a>';

}
0
nicholassolutionsCommented:
elseif ($_POST['func'] == 1){   //insert the data
  //possibly do some checks here so that you are sure the inputs are valid

  $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  mysql_select_db('mysql_db', $link);
  $query = "INSERT INTO contact_info (name, title, company, address_1, address_2,  address_3,  town, ";
  $query .= "city,  county, postcode, phone, email, web_addy) VALUES ('$_POST['name']', '$_POST['title']', ";        
  $query .= "'$_POST['comp']', '$_POST['add1']', '$_POST['add2']', '$_POST['add3']', '$_POST['town']', ";
  $query .= "'$_POST['city']', '$_POST['county']', '$_POST['postcode']', '$_POST['phone']', '$_POST['email']', ";
  $query .= "'$_POST['webadd']')";
  mysql_query($query, $link) or die(mysql_error());
  mysql_close($link);

  echo "THANKS FOR ENTERING YOUR INFORMATION";
}
0
nicholassolutionsCommented:
elseif($_POST['func'] == 2){ //update a current user -- get the user name to update
  echo 'Please enter your name and phone number below to update your information:<br>
          <form method="post">
          Name<input type="text" name="name"><br>
          Phone<input type="text" name="pnum"><br>
         <input type="hidden" name="func" value="3">
         <input type="submit" value="submit">
         </form>';

}
0
nicholassolutionsCommented:
elseif($_POST['func'] == 3){  // update current user -- get user info from DB
   $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  mysql_select_db('mysql_db', $link);
  $query = "SELECT * FROM contact_info WHERE name='$_POST['name']' AND phone=$_POST['pnum']";
  $results =  mysql_query($query, $link) or die(mysql_error());
  $resultarray = mysql_fetch_array($results);
  mysql_close($link);
0
nicholassolutionsCommented:
print <<<EOF

 <form method="post">
 Name<input type="text" name="name" value="$resultarray['name']"><br>
Title<input type="text" name="title"  value="$resultarray['title']"><br>
Company<input type="text" name="comp"  value="$resultarray[company']"><br>
Address Line 1<input type="text" name="add1"  value="$resultarray['address_1']"><br>
Address Line 2<input type="text" name="add2" value="$resultarray['address_2']><br>
Address Line 3<input type="text" name="add3" value="$resultarray['address_3']><br>
Town<input type="text" name="town" value="$resultarray['town]><br>
City<input type="text" name="city" value="$resultarray['city']><br>
0
nicholassolutionsCommented:
County<input type="text" name="county" value="$resultarray['county']><br>
Post Code<input type="text" name="postcode" value="$resultarray['postcode']><br>
Phone<input type="text" name="phone" value="$resultarray['phone']><br>
Email<input type="text" name="email" value="$resultarray['email']><br>
Web Address<input type="text" name="webadd" value="$resultarray['web_addy']><br>
<input type="hidden" name="func" vlaue="4">
 <input type="submit" value="submit">
 </form>

 
 EOF;      
0
nicholassolutionsCommented:

}

elseif($_POST['func'] == 4){
   $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  mysql_select_db('mysql_db', $link);
  $query = "UPDATE contact_info SET name = '$_POST['name']', title = '$_POST['title']', ";        
  $query .= "company = '$_POST['comp']', address_1 = '$_POST['add1']', ";
  $query .= "address_2 = '$_POST['add2']', address_3 = '$_POST['add3']', town = '$_POST['town']', ";
  $query .= "city ='$_POST['city']', county='$_POST['county']', postcode= '$_POST['postcode']', ';
  $query .= "phone = '$_POST['phone']', email='$_POST['email']', ";
  $query .= "web_addy = '$_POST['webadd']')";
0
nicholassolutionsCommented:


  mysql_query($query, $link) or die(mysql_error());
  mysql_close($link);

  echo "YOUR INFO IS UPDATED!";

}

?>

---------------------end php code------------------------------------------
0
nicholassolutionsCommented:
I actually do not have time to finish this right now, but here is the general idea for what you would do to post the results:

use the mysql query SELECT COUNT(user_id) FROM contact_info
to get the total number of records, then create a loop that displays 10-20 results at a time
you can choose the results returned by using the LIMIT flag in mysql. For example, to get results 10-20, you could do something like this:

SELECT * FROM contact_info LIMIT 10,20;

Sorry to not be able to finish this right now. I or someone else should be able to help you work thorugh any problems you encounter.

Cheers,
Matt
0
nicholassolutionsCommented:
sorry for all the posts -- just regard them as one long one. For some reason I could not make an even moderately long post, and had to chop my comments up into smaller sections.

Cheers,
Matt
0
andrewmilnerAuthor Commented:
Many thanks for that Matt.  I will give that a go later and let you know how I get on.  Seems to be a most comprehensive reply.  Let's just hope I can implement the script :-)
0
andrewmilnerAuthor Commented:
I have entered all of the above into one update.php file and uploaded to the server.  When the file is executed, I get a:

Parse error: parse error, unexpected T_ELSEIF in [FILEPATH/LOCATION] on line 44

I dont know what the buggery this means as I am very new to PHP.  I can only assume its a problem with the script or an incompatibility with the current installed version of PHP but I'm sure you experts will be able to advise, please :-)

Many Thanks,

Andrew Milner.
0
nicholassolutionsCommented:
Unfortunately I don;t have time to look at this just now; someone else may be able to get to it before me. What this means is that on or around line 44 of the script, I made a syntax error of some kind (perhaps I did not enclose something in quotes the way I should have, forgot a line terminator ';', etc).

Sorry to not be of more help (and to have given you some fairly rough code). If you're having a lot of trouble, I can probably find you a canned script that does almost what you want...like I said before, though, working through this, especially with some help, is a great way to learn PHP.

I'll try to have a look at this again later on tonight.

-Matt
0
andrewmilnerAuthor Commented:
Thanks Matt.

I am keen to get to grips with the PHP stuff as there are other projects for the site so I would much apprecitate any help you can give.  I'm going to bump this up to max points (if thats any consolation to you), although I am personally most grateful for your help.  It seems you have put a lot of time and effort into the script.

Thanks once again.
0
psgroveCommented:
Try PHPmyEdit available at http://platon.sk/projects/main_page.php?project_id=5 . This is an excellent tool that is easy to configure and set up, and has powerful advanced options. For the most part it creates add, change, view record, view list, and search capabilities using a PHP class.

"PhpMyEdit generates PHP code for displaying/editing MySQL tables in HTML. All you need to do is to write a simple calling program (a utility to do this is included). It includes a huge set of table manipulation functions (record adition, change, view, copy, and remove), table sorting, filtering, table lookups, and more."

It has an autogenerator to get you started, which works great. You can then just make customizations and adjustments to the application as needed. Just build a simply database in mySql with the fields set up how you want. Extract phpMyEdit to a folder on your webserver w/ php Installed. Run the "phpMyEditSetup.php" page in your web browser, point it to the server and database. It will ask you to identify the primary key, and generate a page of php code.

The code is an array that is then fed into the phpMyEdit class that generates the forms for you. It's easy to add HTML around it, as well as strong support for CSS.

However, out of the box... it works pretty well for simple applications.

Good luck.
0
andrewmilnerAuthor Commented:
Thank you for that psgrove.  I will give that a go tomorrow evening.  It sounds, on the face of it very good.

Eitherway I will split the points between the two current responders as Matt has clearly put a lot of effort into his script.

Thanks again.
0
nicholassolutionsCommented:
Hi again,

I took a minute to look that code I sent you over. First of all, my apologies -- it was full of little errors, and knowing that you're new to PHP I should have waited to post it. Anyhow, I updated it so that it at least does the limited tasks it should. It still is not pretty, but I hope it will help you get a handle on the basic approach to this type of problem. You can at least intsall it, try changing stuff, adding stuff, etc, and hopefully you'll learn a thing or two.

I dont want to flood this message with code again, so you can go here to see it:

http://www.nicholassolutions.com/update.txt

0
nicholassolutionsCommented:
put it in a file called update.php and you should be ready to go. Dont forget to put in your own values everywhere it connects to the DB.

I should also add that this is by far not the best code I've ever written. For example, it would make a lot more sense to make a db connection function like this:

function db_connect(){
$link = mysql_connect('localhost', 'username', 'password');
  mysql_select_db('db_name', $link);
}

that you call each time you need to connect than to keep writing the same section of code.

Anyways, hope that helps...I may have more time later tonight to answer any questions you have

-Matt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andrewmilnerAuthor Commented:
This looks very promising.  Thanks Matt.  I will give this a go tonight. FYI - I am indeed learning PHP as I go, I managed to get a simpler script working last night although there were no search functions, just a total display which is no good for me.  Does your script have a search function?, I ideally could do with being able to search on 'city' and 'county'.  Is this easy to implement?

Also, I am going to need to wrap this script within my current HTML so may need to seek your advice once again on this to inlcude HTML table style parameters.

Best Regards,

Andrew Milner.
0
andrewmilnerAuthor Commented:
Matt.

I have performed some tests with your code this evening.  It's looking very good on the face of things but I have a few issues with the code and wonder if you can help?

As far as initially adding information to the database is concerned - all is well.  The problems seem to lie with updating the DB.  This only seems to work if only the name is updated but only on a contact that simply contains a name.  I have tried the full scope quite a few times, i.e. entering all initial info for all fields and then attempting to update only 1,2, a few and so on but the result is the same information in the database over and over.

I've taken a thorough look over the code you have written and the concept seems to be clear however my skills are not yet developed enough to be able to pinpoint the section at fault.

Could you give this a look over for me ?

I think I need to get myself on a course, could prove useful!

Many Thanks once again.

- Andrew
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.