Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

PHP/MYSQL MEmber System.


  • Please log in to reply

#1
jrm-hosting

jrm-hosting

    Member

  • Member
  • PipPip
  • 79 posts
I wnat to create a member system.

Scenario: I need to create a database system where I can store information such as Housing list for rent in a certain area. I want to create a page that will allow the individuals with the place for rent to be able to add information into the database. Then, have users go on another page to pull up these information and mainly give the users access to browse the database and even lookupp information by ZipCode.


Can I get some help or ideas on on how to start this?


If anyone knows where I could find a system like or provide some help in building this system, I would really appreciate that.
  • 0

Advertisements


#2
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
Hi there,

Do you have any experience with PHP or mySQL? If not I suggest you read some tutorials, there are thousands of them on the web.

To accomplish what you want, we first must set up a database. In the control panel in your website, look for the place where you can create a database. Fill in the required information and write down the database name, username, and password so we can connect to it later. Then open up the database in phpmyadmin. Create a new table and call it "housingrent". In the "fields" category, let's start with 3. We can add more fields later.

For the first field, let's name it "id". For the type set it to "INT" (which is short for integer). Length/values set to 10. Under extra select "autoincrement" and check the "primary" box.

The next field let's name "info". For the type set it to "text". Leave the rest of that field blank (ie no length, extras, etc).
For the last field let's name it "zip". Set the type to "INT" and length to 5 (number of numbers in a zip code).

Then click save.

The database part is done :)

Now let's create the PHP part. :tazz:

First things first, we need some basic things. Create a new document in NotePad and name it what ever you want, but make sure it has a ".php" extension. Now open up this file.

All php code has to go between <?php and ?> brackets. For example...

<?php

//your code here

?>

The first thing we want to do is connect to your database.

We can use this code, but make sure to replace the username, password, and hostname variables with the values you used when you created the database. I left the hostname as "localhost", as many web servers use it, but your host may use something else.

$username = "database username";
$password = "database password";
$dbname = "database name";
$hostname = "localhost";	
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL 1");
$selected = mysql_select_db($dbname,$dbh) or die("Unable to connect to MySQL");

Next let's get the results from the database. This code will select the results from the housingrent table and the code between the brackets will be executed for each entry in this table.

$result=mysql_query("SELECT * from housingrent");
while ($object = mysql_fetch_array($result)) {

This creates an array and we can get each of the fields from the database. For example, to get the info field we would use $object[info] and to get the zip code field we would use $object[zip].

So for each entry let's print the zip code and info.

echo "$object[zip]<br>$object[info]";

Now let's put all this code together:

<?php

$username = "database username";
$password = "database password";
$dbname = "database name";
$hostname = "localhost";	
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL 1");
$selected = mysql_select_db($dbname,$dbh) or die("Unable to connect to MySQL");

$result=mysql_query("SELECT * from housingrent");
while ($object = mysql_fetch_array($result)) {

echo "$object[zip]<br>$object[info]";

}

?>

This simply displays all the entries, once you have gotten this to work we can work on allowing users to add entries (for now you can just add entries in phpmyadmin with the insert button) and search for entries.

Let me know if there is anything I can clarify,

- Matt :)
  • 0

#3
jrm-hosting

jrm-hosting

    Member

  • Topic Starter
  • Member
  • PipPip
  • 79 posts
Thands Matt this is awesome. I'm not that good with PHP/MYSQL, however, I've been looking at it now for the past month so, hopefully, I'll get something.lol.

Anyhow, I host my own webserver with MYSQL and PHPMyAdmin.

Once Again I like what you wrote it is very helpful and no need to clarify.

I already have the database set up already for the system, now I mostly need help with the way the application look, login system for the renters, etc...

can I get some help with that?


It Worked fine..

http://rossu.jrm-hos.../php2/test2.php


Also, I wanted to know, when Fetch the data, how can I make every entry to be on a separate table with different color scheme?

Edited by jrm-hosting, 27 February 2006 - 06:49 AM.

  • 0

#4
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts

Also, I wanted to know, when Fetch the data, how can I make every entry to be on a separate table with different color scheme?


The code between the brackets ( { and } ) is going to appear for every entry. So just write some code for a table in there. To make each table a different color is a bit tricky, but can still be done. How many different color schemes do you want?

I already have the database set up already for the system, now I mostly need help with the way the application look, login system for the renters, etc...

can I get some help with that?


In order for us to help you we need some more info, like what exactly you are trying to do. Remember, we aren't here to write the code for you, just point you in the right directions and help you when your stuck :tazz:
  • 0

#5
jrm-hosting

jrm-hosting

    Member

  • Topic Starter
  • Member
  • PipPip
  • 79 posts
As Stated before, I want to build a user system data base system. So far, I have created the database, the table, input data into the table using php, a logon page, restricted access page, but now what I want to do is an edit page, with where a user can view only his/her account and make change to it as needed. Can I get some help with that?



Program Features:
1. The ability to Add New entries
a. Required Fields: email address, name
b. Easy Navigation Link on all Pages
2. The ability to View Entries
a. Default view is 15 entries at a time, but with option to view all
3. Ability to browse database for specific entry
a. Users, browse for information by Zip Code, City.
4. User and Adminstrator Administration
a. Editing data
b. Deleting data
e. Login and Authentication and Member system.
f. would want user to receive an email from the system to finalize the registration process.
  • 0

#6
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
Can I have a link to the current system? Also you say you want a user to be able to login and check their account. To do this you need to use either cookies or sessions, both can be easily accessed using PHP. Both fundamentally accomplish the same thing but are a bit different. Cookies are stored on a user's machine and can last as long as you set them ie, if a user logs on today when they come back tomorrow they can still be logged on tomorrow. Most forums and online games use this system so you don't have to relogin every time. Sessions are stored on the server and last until one closes their browser. Because it is stored on the server and not locally, users can't hack it and it is much more secure. Most shopping carts and other secure logins use sessions.

Cookie tutorial: http://www.w3schools...php_cookies.asp
Session Tutorial: http://www.zend.com/...tut/session.php

See if you can make a basic login and logout system using cookies or sessions (whichever you choose) and I will help you if you get stuck :tazz:
  • 0

#7
jrm-hosting

jrm-hosting

    Member

  • Topic Starter
  • Member
  • PipPip
  • 79 posts
Cool.

http://jrm-hosting.c...admin/logon.php



Well, I think I already have have a login and logout system.


Check it out!


it would ask for you to create a username and and a password.

Check it out!
  • 0

#8
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
Good work, but when you sign up it just refreshes. Redirect it to a page that says thank you for signing up yada yada. Now you need to write some scripts that allow the user to add, view, delete, and search for entries.
  • 0

#9
jrm-hosting

jrm-hosting

    Member

  • Topic Starter
  • Member
  • PipPip
  • 79 posts
that's the part I mostly need help in.
Can't seem to do that part!

Can I get some idea on how to start it!

And Also, how to send email back to New user Confirming?

Edited by jrm-hosting, 27 February 2006 - 11:41 PM.

  • 0

#10
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
Don't worry, I havent forgotten about ya.

And Also, how to send email back to New user Confirming?


You can use the PHP mail function to send an email to the user after signing up. The link above is pretty well explained.

that's the part I mostly need help in.
Can't seem to do that part!

Can I get some idea on how to start it!


Okay, like I said earlier, I'm not going to write the code from scratch for you. Look at some PHP/MySQL tutorials and you should be able to do the basics, and I can help you on the more advanced stuff. For example, to write an add, edit, or delete script, all you need to do is make a form with the necessary info (like you did for the login/sign up pages) and then on the part where the form is executed put in some if statements to make sure that the info is valid, and then do a mysql_query("insert, update, or delete...");.
  • 0

Advertisements


#11
jrm-hosting

jrm-hosting

    Member

  • Topic Starter
  • Member
  • PipPip
  • 79 posts
Ok, I went online and saw a tutorial and I don't know but it's not helping much.


$userid = mysql_insert_id();
// Let's mail the user!
$email_usr = "email_usr";
$subject = "Your Membership at MyWebsite!";
$message = "Dear $first_name $last_name,
Thank you for registering at our website, http://www.mydomain.com!

You are two steps away from logging in and accessing our exclusive members area.

To activate your membership,
please click here: http://www.mydomain....036;db_password

Once you activate your memebership, you will be able to login
with the following information:
Username: $username_usr
Password: $password_usr

Thanks!
The Webmaster

This is an automated response, please do not reply!";

mail($email_usr, $subject, $message);
echo 'Your membership information has been mailed to your email address!
Please check it and follow the directions!';



header ("Location:" . $MM_redirectLoginSuccess);
}


It'snot working, whenever I do the form, it adds the info to the database but I get a bounce back error message from my mailserver.









Your message did not reach some or all of the intended recipients.

Subject: Your Membership at MyWebsite!
Sent: 3/2/2006 7:38 PM

The following recipient(s) could not be reached:

email_usr@mydomain.com on 3/2/2006 7:38 PM
The e-mail account does not exist at the organization this message was sent to. Check the e-mail address, or contact the recipient directly to find out the correct address.
<mydomain.com #5.1.1>





Any idea?
  • 0

#12
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
$email_usr = "email_usr";

It's trying to send it to an invalid email addresss.
  • 0

#13
jrm-hosting

jrm-hosting

    Member

  • Topic Starter
  • Member
  • PipPip
  • 79 posts
That's the problem, how do I make the email sent to the user?
Because the email_usr is the field where the person would put the email address, how do I take that input and process it?

Edited by jrm-hosting, 02 March 2006 - 10:21 PM.

  • 0

#14
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
You know how to write PHP forms right? Here's a quick example:


<?php

if (isset($_POST[ifform])) {

$email_usr = $_POST[email];

//rest of your code goes here

}
else
{

echo "

<form method='POST' action='$_SERVER[PHP_SELF]'>
email:<br><input type='text' name='email'><br><br>
<input type='hidden' name='ifform' value='1'> 
<input type='submit' value='submit form'>
</form>";

}

?>

I didn't test this so there might be some parse errors but the general idea is there. It basically checks to see if the form is sent by using the isset function (just checks to see if a variable exists) for the hidden form input. If it does exist you can do your code, if not, it shows the form

- Matt :tazz:
  • 0

#15
jrm-hosting

jrm-hosting

    Member

  • Topic Starter
  • Member
  • PipPip
  • 79 posts
yeah I know how to write a form, visit: http://jrm-hosting.com/contact.html.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP