Jump to content


This topic is now archived and is closed to further replies.


Really Basic Mysql Database

Recommended Posts

Hi there.... In order to ask this question effectivly, i will give you my testing webserver so you can see what im talking about [url=http://cbmanagment.co.nr/]http://cbmanagment.co.nr/[/url]

If you navigate to the CV services section, and then click on the link to the Form that is what im talking about here.

(and yes i know the navigation bar sucks, im working on it  ;D)

Ok, so in the last 3 months ive learnt enough to create this little form you see, It uses hidden fields to pass data between the pages, and then sends all the gathered info as an email to my inbox.

Im quite please with this ..... but, im afraid it needs to go further.

I need to be able to do the following;

1) Restrict access to the form to those people who have paid a fee for the service (membership system)

2) Store the information entered by each member so that they can come back and change it at a later date... or in fact take  there time over filling it out... at the moment it all must be filled and submitted in a oner, and the form is unforgiving of mistakes.

3)related to above, I need to allow the user to freely navigate back and forth within there form, and modify as they see fit.

Further more i need this to be supported on both firefox and IE V 6 and above.

Now i'm pretty sure i need to set up a MySql database in order to accomplish this, however this is my first contact with MySql... and to be honest im finding it difficult to find solid advice on getting started.

I am using Dreamweaver MX2004 for my design, but am quite happy (and prefer even) to code by hand where possible.

I also have WAMP installed and running nicley.... Ive looked at PhpMyadmin, but im not really sure where to start.

Im not looking for anyone to do this for me.... i want and in fact need to learn..... but someone to nudge me in the right direction would be most satisfactory.

You have my greatest thanks for any and all of your help  :)

Share this post

Link to post
Share on other sites
I'm actually trying to make a user management system too,
so im not an expert.. yet ( hopefully lol ).

but at least some basics,
you can use session with php.
when you use session_start(), php will give the viewer a random unique session id.
and when your session is started you can user $_SESSION['var'] variables.
(i think using $_SESSION['var'] starts one automatically.. not sure).

so lets say you have
You create a login form that will set this variable...
and a logout  page that will unset it.
( since you can have many many more session variables,
you should use session_destroy() so you dont have to unset one by one each variables
it does it all at once ).

now for your session to carry out to other page,
along with its variables, you have 2 choices.
within the url ( http://urDomain/?PHPSESSID=the session id )
or with a cookie.
using cookie is much safer... read your php.ini at session section.
you either need to session_start() on every page, or
you can set session_auto_start in php.ini so every page
retrieve the session variables..

ex for something you want to registered members only:
if (!isset ($_SESSION['username']))
    echo "Please login/register to access this";
    //show the form you reserved to registered users

2 ) now for user information to be edited
// if the user is not even logged in...
if (!isset ($_SESSION['username']))
    echo "You shouldnt even be here! Shoo";
    //you can redirect to login page too
// else if the logged user has not wished to edit yet.
elseif (!isset ($_POST ['edit']))
    //you simple list the information you have in your database
// else means the logged users wishes to edit this time.
  //now's the biggest part.... the form, the validation and entering in database
  //if you unset $_POST['edit'] once the data is saved you can redirect to the same page too.

for your 3)
dunno if thats what you need but... if your getting started you should use mysqli right away..
( enable the extension and get the files at mysql.com i think )
with mysqli there's an oop available and much easier/safer i think
//you first need to know the info about your database
$username = "username";
$password = "password";
$db_host  = "the address to your database server"; // ip, url, localhost...
$db_schema = "the schema where you'll be able to create view alter you tables";

//then you create a mysql connection as a mysqli object
$mysqli = new mysqli ($db_host, $username, $password, $db_schema);

//if you have a INSERT or ALTER query then simply
//you can then check for errors with mysqli_error() or mysqli_errno()
$mysqli->query ($urQuery);

//if you have a SELECT query then it will give you another object to handle results
$result = $mysqli->query ("SELECT...FROM..");

//then you get
$result->num_rows; // which is the number of rows returns by the query

//each time you call this, you pass to the next row, first time getting first row.
$row = $result->fetch_assoc(); // you get an array of eacg colym of you query by colum name $row['column_name1'], etc..
//so you can either do
while ($i < $result->num_rows)
    $row = $result->fetch_array(); // you get an array of each column of your query order in $row[0], $row[1] etc
//or do
while ($row = $result->fect_both())
    // do whatever you want with data accessible by $row['0'] or $row['column_name1'] etc...
alright.. its late i need sleep :)
I too in fact hope to get feedback of my use of php..

so i hope it does help you, and if you need some thing clarified,
seen how im tired i wont be surprised..

good luck

alright... if it helps... or if i can clarify some things for you, itll be my pleasure...
im hoping to get comments on my comment too lol


Share this post

Link to post
Share on other sites
Thanks for your time and help mate......... but i think im even more confused now (if possible).

1) where is all this username info stored?

2) how is it retrieved?

3) how do i get a mysql database that i create at localhost onto my webserver?

basic question i know.... but im not even at the code writing stage yet :(

Share this post

Link to post
Share on other sites
hehe well sorry for confusing..

1) - when you use session_start(), php sends the session id to the viewing browser/user
    - with this id , every different user will have his own set
      of session variable as in $_SESSION['name of the var']
      for example, user A with his unique session id gets $_SESSION['username'] = "john";
      while user B with another unique session id gets $_SESSION['username'] = "smith";

2) when u use session_start() it ONLY assign the id...
    to check if it exist first, you should have if (isset ($_SESSION['username'])) before.
    and you can retrieve it with: $username = $_SESSION['username'];
    if you make sure to unset/destroy session variables when user log off...
    and dont set your session variable until the user has provided info to log in...
    the if it is not set... the user is simply guest... otherwise.. you can retrieve any session variables you might need.

3) if you follow all steps in [url=http://www.adcommcepts.com/wamp-install.pdf]http://www.adcommcepts.com/wamp-install.pdf[/url]
    (found on from apache lounge) you should then have a workin
    apache 2.2.2 php 5.1.4 and mysql 5.0.22 installation.
    i recommend installing mysql administrator and query browser which you can get from

finally, if you are starting, let me recommend once more using mysqli extension instead of mysql...
mysqli being mysql improved extension
if not in you php.ini simply copy paste the mysql extension line, uncomment and add a 'i' to make mysqli

alright... cya next break if i have time :) lol
sorry again for confusing... i hope the guide
[url=http://www.adcommcepts.com/wamp-install.pdf]http://www.adcommcepts.com/wamp-install.pdf[/url]  is clearer than me :)
and it will get you the latest released version working...
and be sure to check www.apache-lounge.com dedicated to apache under windows,
but many information, they too provide the php 5.1.4 apache2.2.2 connector.
(for you server to understand the last version of php code)... read the guide, and tell me

Share this post

Link to post
Share on other sites
1. The username and password should be stored in a table in your database. When the user logs in it checks to see if the record exists in that table with a valid password. Then if it is correct, store the username as a session varible, or run queries to get the information needed based on the user that logged in.

2. The SQL statement that is used to retrieve client information will be custom depending on what information you need and how your database is set up. Google some SQL tutorials to see how to retrieve data thru SQL statements.

3. To move your db from your local machine to your web server, you create a .sql backup of your database on you local computer. Their should be a operations section under MySQL Administrator if your using that. Anyway that created a .sql file this contains a bunch of create table commands and insert commands. Copy and paste this into a SQL window within phpmyadmin for your web server database and run it. It will create your tables and populate them for you, (if you have any data yet that is).

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.