I am trying to slowly learn how to create a membership database for my association site www.oata.org.
I am on Mac OSX and have a hosting through imhosted.com which gives me MySQL databases and PHP admin access, etc... i have setup my database, it is a small table with 26 fields in one table... basic membership information stuff...

SO.... now i'm trying to get the web interface PHP together so that the user can view his or her membership information, edit it right there in the text boxes, and the submit it to be updated or to be new information...

I also want a place where folks can go (Php page) to search the database and sort it by district (5 of them), individual name (first or last), or just view the entire list (about 2000 members)... hopefully placing 20 or so members per page...

I figured out how to do the php coding so that they can enter their information on a form and submit it to the database... but that's about as far as i've gotten...

any suggestions on any of these topics? sorry to be total newbie on everyone but i'mneeding some deperate help here!!!

thanks,
Jonathan Willey
email me at jwilley@oata.org

    i would do something like this

    make a login for your members set there login in a session cookie.

    When a member is logged in you can always use that variable.

    example

    login niels
    pass niels123

    ---------> goes to member info (or something else)

    then simply make a query

    select * from members where loginname = $login_name

    hope this helps
    niels

      Wow,
      ok i guess that sounds simple enough but i have NO CLUE how to do any of that... sorry to sound like an idiot but i am on about day 2 of my PHP knowledge...

      i just figured out how to create a form that will allow me to enter fields into a database table.... thats about as far as i've gone.

      The next step i would like to do is to be able to search that database and present the data on a seperate page that they searched for...(ex. search by last name, first name, city, district and then show those results on another page... or the same one)... i'll take it one step at a time... any suggestions code wise?

      I know PHP myadmin makes SQL code for those queries, just not sure how to implement it into my page...
      Jon

        get yourself a PHP manual... since u are new
        i recommend u to download it from http://www.php.net

        if u are on winbox.. get the chm version...

        u can find almost everything inside the manual... 😃

          Thanks all for your help... i went through webmonkey's tutorial and it helped me greatly! Now i can create, update, edit, delete and so on my database fields...

          the next thing i need to do is make it so that not everyone in the association can edit anyone's fields... so i think i need to setup a login like described? any good tutorials off hand that anyone has? then i'll really have to work with the code agian i guess and change it up for that specific user who logged in...

          any more thoughts?
          Jon

            For login use some tutorial with session cookies

            i use the login for 2 things

            1: to restrict acces
            2: as a reference

            now that your logged in.
            u can do something like this

            //----get the id of the user that logged in
            select member_id
            from members
            where username == $loginname

            $db_member_id = member_id;

            then

            //---- simple update statement

            update * values (your fields go here)
            from member
            where member_id = $db_member_id

            this will allow only the user that logged in to change his/het data.

            hope this helps
            will be back tommorow
            grtz niels

              Ok, i understand theoretically what you are saying to do... code wise though i will have some work to do to get it... webmonkey has a session tutorial...

              I am going to need to validate the user against 2 fields in the database though... so basically they have a lastname and a membership number that i could use as their username and password... that would be the easiest for me as the database is already setup... i don't know if i want them creating thier own passwords and such... may make it harde for me...

              will this still work for sessions?

              man, this is all still over my head...

              jon

                6 days later

                here is my code:

                
                <html><title>newmemupdate</title>
                
                <body>
                
                
                
                <?php
                
                
                
                $db = mysql_connect("localhost", "oataorg_ohioata","atmedical");
                
                mysql_select_db("oataorg_memdb",$db);
                
                
                
                if ($submit) {
                
                  // here if no ID then adding else we're editing
                
                  if ($id) {
                
                $sql = "UPDATE membinfo SET firstname='$firstname',lastname='$lastname',address1='$address1',membernumber='$membernumber',license_number='$license_number',certification_number='$certification_number',address1='$address1',address2='$address2',address3='$address3',city='$city',state='$state',zip='$zip',workplace='$workplace',workaddress='$workaddress', workcitystatezip='$workcitystatezip',class='$class',district='$district',job_description='$job_description', addschool='$addschool',pager='$pager',cell='$cell',home='$home',work='$work',fax='$fax', email='$email' WHERE id=$id";
                
                  } else {
                
                $sql = "INSERT INTO membinfo (firstname,lastname,membernumber,license_number,certification_number,address1,address2,address3,city,state,zip,workplace,workaddress,workcitystatezip,class,district,job_description,addschool,pager,cell,home,work,fax,email) VALUES ('$firstname','$lastname','$address1','$membernumber','$license_number','$certification_number','$address1','$address2','$address3','$city','$state','$zip','$workplace','$workaddress','$workcitystatezip','$class','$district', '$job_description', addschool='$addschool','$pager','$cell','$home','$work','$fax','$email')";
                
                  }
                
                  // run SQL against the DB
                
                  $result = mysql_query($sql);
                
                  echo "Record updated/edited!<p>";
                
                } elseif ($delete) {
                
                // delete a record
                
                $sql = "DELETE FROM membinfo WHERE id=$id";	
                
                $result = mysql_query($sql);
                
                echo "$sql Record deleted!<p>";
                
                } else {
                
                  // this part happens if we don't press submit
                
                  if (!$id) {
                
                // print the list if there is not editing
                
                $result = mysql_query("SELECT * FROM membinfo",$db);
                
                while ($myrow = mysql_fetch_array($result)) {
                
                  printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["lastname"], $myrow["firstname"]);
                
                  printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
                
                }
                
                  }
                
                
                
                  ?>
                
                  <P>
                
                  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
                
                  <P>
                
                  <form method="post" action="<?php echo $PHP_SELF?>">
                
                  <?php
                
                
                
                  if ($id) {
                
                // editing so select a record
                
                $sql = "SELECT * FROM membinfo WHERE id=$id";
                
                $result = mysql_query($sql);
                
                $myrow = mysql_fetch_array($result);
                
                $id = $myrow["id"];
                
                $firstname = $myrow["firstname"];
                
                $lastname = $myrow["lastname"];
                
                $membernumber = $myrow["membernumber"];
                
                $license_number = $myrow["license_number"];
                
                $certification_number = $myrow["certification_number"];
                
                $address1 = $myrow["address1"];
                
                $address2 = $myrow["address2"];
                
                $address3 = $myrow["address3"];
                
                $city = $myrow["city"];
                
                $state = $myrow["state"];
                
                $zip = $myrow["zip"];
                
                $workplace = $myrow["workplace"];
                
                $workaddress = $myrow["workaddress"];
                
                $workcitystatezip = $myrow["workcitystatezip"];
                
                $class = $myrow["class"];
                
                $district = $myrow["district"];
                
                $job_description = $myrow["job_description"];
                
                $addschool = $myrow["addschool"];
                
                $pager = $myrow["pager"];
                
                $cell = $myrow["cell"];
                
                $home = $myrow["home"];
                
                $work = $myrow["work"];
                
                $fax = $myrow["fax"];
                
                $email = $myrow["email"];
                
                // print the id for editing
                
                
                
                ?>
                
                <p>
                <input type=hidden name="id" value="<?php echo $id ?>">
                
                <?php
                
                  }
                
                
                
                  ?>
                
                  First name:
                  <input type="Text" name="firstname" value="<?php echo $firstname ?>">
                  Last name:
                  <input type="Text" name="lastname" value="<?php echo $lastname ?>">
                  <br>
                
                  Member Number:
                  <input type="Text" name="membernumber" value="<?php echo $membernumber ?>">
                  <br>
                
                   License Number:
                   <input name="license_number" type="Text" id="license_number" value="<?php echo $license_number ?>">
                   <br>
                
                Certification Number:
                <input name="certification_number" type="Text" id="certification_number" value="<?php echo $certification_number?>">
                </p>
                <p>Address 1:
                  <input type="Text" name="address1" value="<?php echo $address1 ?>">
                  <br>
                
                  Address 2:
                  <input name="address2" type="Text" id="address2" value="<?php echo $address2 ?>">
                  <br>
                
                   Address 3:
                   <input name="address3" type="Text" id="address3" value="<?php echo $address3?>">
                   <br>
                
                    City:
                    <input name="city" type="Text" id="city" value="<?php echo $city?>">
                  State (XX):
                	 <input name="state" type="Text" id="state" value="<?php echo $state?>" size="4" maxlength="2">
                	 Zip:
                	  <input name="zip" type="Text" id="zip" value="<?php echo $zip ?>">
                </p>
                <p>Work Place:
                       <input name="workplace" type="Text" id="workplace" value="<?php echo $workplace ?>" size="40">
                       <br>
                
                	    Work Address:
                	    <input name="workaddress" type="Text" id="workaddress" value="<?php echo $workaddress ?>" size="40">
                	    <br>
                
                		 Work (city, state, zip):
                		 <input name="workcitystatezip" type="Text" id="workcitystatezip" value="<?php echo $workcitystatezip ?>" size="40">
                </p>
                <p>Class:
                	      <input name="class" type="Text" id="class" value="<?php echo $class?>" size="2" maxlength="1">
                	      District:
                		   <input name="district" type="Text" id="district" value="<?php echo $district ?>" size="4" maxlength="2">
                		   <br>
                
                		    Job Description:
                		    <input name="job_description" type="Text" id="job_description" value="<?php echo $job_description?>">
                		    <br>
                
                			 High School (if outreach):
                			 <input name="addschool" type="Text" id="addschool" value="<?php echo $addschool ?>" size="40">
                </p>
                <p>Pager:
                		      <input name="pager" type="Text" id="pager" value="<?php echo $pager ?>">
                		      Cell Phone:
                			   <input name="cell" type="Text" id="cell" value="<?php echo $cell ?>">
                			   <br>
                
                			    Home Phone:
                			    <input name="home" type="Text" id="home" value="<?php echo $home ?>">
                			    Work Phone:
                			     <input name="work" type="Text" id="work" value="<?php echo $work ?>">
                			     <br>
                
                			    Fax Number:
                			     <input name="fax" type="Text" id="fax" value="<?php echo $fax ?>">
                			     Email Address:
                			     <input name="email" type="Text" id="email" value="<?php echo $email?>" size="40">
                </p>
                <p>
                  <input type="Submit" name="submit" value="Enter information">
                
                        </p>
                  </form>
                
                
                
                <?php
                
                
                
                }
                
                
                
                ?>
                
                
                
                </body>
                
                </html>
                

                This will basically give me a list of the ENTIRE database in a list with lastname, firstname and the if i click on one of those names it will let me update that person's field... i basically want to have a specific user login using their lastname and certification_number and this will give ONLY that person the abilty to update only his or her field.... i understand what you said above neils but am not sure code wise how to implement it into this...
                Any help and code greatly appreciated!
                Jonathan

                  2 years later

                  <?php # Script from Oliver Bob Lagumen- register.php

                  // Set the page title and include the HTML header.
                  $page_title = 'Register';
                  include ('templates/header.inc'); // you will need to create your own header. I think you are familiar with this.

                  if (isset($_POST['submit'])) { // Handle the form.

                  // Register the user in the database.
                  require_once ('your_mysql_connect_page_which_is_a_separate_file.php'); // Connect to the db.
                  
                  // Create a function for escaping the data.
                  function escape_data ($data) {
                  	global $dbc; // Need the connection.
                  	if (ini_get('magic_quotes_gpc')) {
                  		$data = stripslashes($data);
                  	}
                  	return mysql_real_escape_string($data, $dbc);
                  } // End of function.
                  
                  $message = NULL; // Create an empty new variable.
                  
                  // Check for a first name.
                  if (empty($_POST['first_name'])) {
                  	$fn = FALSE;
                  	$message .= '<p>You forgot to enter your first name!</p>';
                  } else {
                  	$fn = escape_data($_POST['first_name']);
                  }
                  
                  // Check for a last name.
                  if (empty($_POST['last_name'])) {
                  	$ln = FALSE;
                  	$message .= '<p>You forgot to enter your last name!</p>';
                  } else {
                  	$ln = escape_data($_POST['last_name']);
                  }
                  
                  // Check for an email address.
                  if (empty($_POST['email'])) {
                  	$e = FALSE;
                  	$message .= '<p>You forgot to enter your email address!</p>';
                  } else {
                  	$e = escape_data($_POST['email']);
                  }
                  
                  // Check for a username.
                  if (empty($_POST['username'])) {
                  	$u = FALSE;
                  	$message .= '<p>You forgot to enter your username!</p>';
                  } else {
                  	$u = escape_data($_POST['username']);
                  }
                  
                  // Check for a password and match against the confirmed password.
                  if (empty($_POST['password1'])) {
                  	$p = FALSE;
                  	$message .= '<p>You forgot to enter your password!</p>';
                  } else {
                  	if ($_POST['password1'] == $_POST['password2']) {
                  		$p = escape_data($_POST['password1']);
                  	} else {
                  		$p = FALSE;
                  		$message .= '<p>Your password did not match the confirmed password!</p>';
                  	}
                  }
                  
                  if ($fn && $ln && $e && $u && $p) { // If everything's OK.
                  
                  	$query = "SELECT user_id FROM users WHERE username='$u'";		
                  	$result = @mysql_query ($query); // Run the query.
                  	if (mysql_num_rows($result) == 0) {
                  		// Make the query. This code is what you will use to prevent duplicate of usernames
                  		$query = "INSERT INTO users (username, first_name, last_name, email, password, registration_date) VALUES ('$u', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";		
                  		$result = @mysql_query ($query); // Run the query.
                  		if ($result) { // If it ran OK.
                  
                  			// Send an email, if desired.
                  			echo '<p><b>You have been registered!</b></p>';
                  			include ('templates/footer.inc'); // Include the HTML footer.
                  			exit(); // Quit the script.
                  
                  		} else { // If it did not run OK.
                  			$message = '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>'; 
                  		}		
                  	} else {
                  		$message = '<p>That username is already taken.</p>'; 
                  	}
                  	mysql_close(); // Close the database connection.
                  
                  } else {
                  	$message .= '<p>Please try again.</p>';		
                  } 

                  } // End of the main Submit conditional.

                  // Print the error message if there is one.
                  if (isset($message)) {
                  echo '<font color="red">', $message, '</font>';
                  }
                  ?>

                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                  <fieldset><legend>Enter your information in the form below:</legend>

                  <p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($POST['first_name'])) echo $POST['first_name']; ?>" /></p>

                  <p><b>Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($POST['last_name'])) echo $POST['last_name']; ?>" /></p>

                  <p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($POST['email'])) echo $POST['email']; ?>" /> </p>

                  <p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($POST['username'])) echo $POST['username']; ?>" /></p>

                  <p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /></p>

                  <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
                  </fieldset>

                  <div align="center"><input type="submit" name="submit" value="Register" /></div>

                  </form><!-- End of Form -->

                  <?php // You will have to create your own footer file
                  include ('templates/footer.inc'); // Include the HTML footer.
                  ?>

                  So you are excited ha.... May be, But you will need to code or to build the following in mysql or in phpmyadmin fields:
                  user_id, username, first_name, email and password and registration_date in order for this script to work for you. You can call your tabale "users" and your database "any_thing_you_like"

                  Now the login.php is here and I do not have to go to the details, but I wanted to help you to the codes you need:

                  <?php # - login.php

                  include ('nocache.php');
                  ob_start(); // Start output buffering.

                  $page_title = 'Login';
                  include ('templates/header.inc'); // Require the page header.

                  if (isset($_POST['submit'])) { // Check if the form has been submitted.

                  require_once ('your_mysql_connect_page_which_is_a_separate_file.php'); // Connect to the database.
                  
                  function escape_data ($data) { // Function for escaping data.
                  	global $dbc;
                  	if (ini_get('magic_quotes_gpc')) {
                  		$data = stripslashes($data);
                  	}
                  	return mysql_real_escape_string(trim($data), $dbc);
                  }
                  
                  if (empty($_POST['username'])) { // Validate the username.
                  	$u = FALSE;
                  	echo '<p>You forgot to enter your username!</p>';
                  } else {
                  	$u = escape_data($_POST['username']);
                  }
                  
                  if (empty($_POST['password'])) { // Validate the password.
                  	$p = FALSE;
                  	echo '<p>You forgot to enter your password!</p>';
                  } else {
                  	$p = escape_data($_POST['password']);
                  }
                  
                  if ($u && $p) { // If everything's OK.
                  
                  	// Query the database.
                  	$query = "SELECT user_id, first_name FROM users WHERE username='$u' AND password=PASSWORD('$p')";		
                  	$result = @mysql_query ($query);
                  	$row = mysql_fetch_array ($result, MYSQL_NUM); 
                  
                  	if ($row) { // A match was made.
                  
                  			// Start the session, register the values & redirect.
                  			session_start();
                  			$_SESSION['first_name'] = $row[1];
                  			$_SESSION['user_id'] = $row[0];
                  
                  			ob_end_clean(); // Delete the buffer.
                  
                  			header ("Location:  [url]http://[/url]" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php"); //this part of the code brings you to loggedin.php before or to your index.php if it is successful which means that I will have to code that here for you.
                  			exit();
                  
                  	} else { // No match was made.
                  		echo '<p>The username and password entered do not match those on file.</p>'; 
                  	}
                  
                  	mysql_close(); // Close the database connection.
                  
                  } else { // If everything wasn't OK.
                  	echo '<p>Please try again.</p>';		
                  }

                  } // End of SUBMIT conditional.
                  ?><center>
                  <form action="<?php echo $SERVER['PHP_SELF']; ?>" method="post">
                  <fieldset><legend><div align ="center">Enter your information in the form below:</div></legend>
                  <p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($
                  POST['username'])) echo $_POST['username']; ?>" /></p>
                  <p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" /></p>
                  <div align="center"><input type="submit" name="submit" value="Login" /></div>
                  </form><!-- End of Form --></center>
                  <?php include ('http://www.sharesiteph.com/index.htm');
                  include ('templates/footer.inc'); // Include the footer.

                  ob_end_flush(); // Send everything to the Web browser.
                  ?>

                  Now be careful here (that code above), since you will need to be able to copy this without spaces so that your code will not report an error.

                  Now it is time for this last code:

                  <?php # - loggedin.php

                  ob_start(); // Start ouput buffering.

                  session_start(); // Start the session.

                  // Set the page title and include the HTML header.
                  $page_title = 'Logged In!';
                  include ('templates/include/header.inc');

                  // Check for a first name value.
                  if (isset($SESSION['first_name'])) {
                  echo "<center><p>You are now logged in, {$
                  SESSION['first_name']}!</p></center>"; $g = "include_once ('myprofile.php')"; echo $g; echo 'this part is your assignment';
                  } else {
                  ob_end_clean(); // Delete the buffer.
                  header ("Location: [url]http://[/url]" . $SERVER['HTTP_HOST'] . dirname($SERVER['PHP_SELF']) . "/index.php");
                  exit(); // Quit the script.
                  }
                  include ('http://www.sharesiteph.com/newphp/');
                  include ('templates/include/footer.inc'); // Include the HTML footer.

                  ob_end_flush(); // Send everything to the Web browser.
                  ?>

                  Hey remember that when you will use include(); or require functions(); you will need to really make sure to have those things exist in your directory where you want it. If you want that this will work properly for you or need to email me do so or, please visit here: www.sharesiteph.com/newphp/database

                  Note: Do not forget to notify me of your success.

                    14 days later

                    I have posted the answers to you. It seems that you did not reply. To make another thread, you can go to my own forum found at www.sharesiteph.com/forum or go to www.sharesiteph.com/newphp/database and find how you can update your personal info after you register. I will teach you that code also. Lets work together. This is just an offer. It is up to you to decide. My forum deals mainly and primarily about php and basically for beginners. You are welcome to visit, register and post. No joke

                      Write a Reply...