Jump to content

PHP/MySQL connection problems


Recommended Posts

Heres the project: I have to build a site where employees in training can go, register, login, watch a video, take a test and the results for that person, are stored in the database as well as emailed to the employer.

 

Registration needs to be very simple. No passwords or usernames. Simply their first name, last name and employee number.

 

The login would then be their last name and employee number.

 

After they login they are directed to the video.

 

After the video they are directed to the test. A simple ten question multiple choice test. That at the end sends the results to the employer along with the personal information of the person who just took the test.

 

I already have the quiz done and set up and working with the database. However I don't know how to get the results of the test combined with the employee information emailed off.

 

I have tried to no avial to set up a user system with SESSIONS but I believe I am having connection issues. I am fairly new to MySQL and PHP.

 

If anybody knows a simple way to create a user system, or can help me please, I could really use it.

Link to comment
Share on other sites

Hmm... there was a great PHP/MySQL user authentication tutorial on PHP freaks but I couldn't find it for some reason, so instead I found this one:

http://www.tutorialized.com/view/tutorial/Login-Logout-with-a-Session-in-1-file/20041

 

It uses sessions to so that you can see how the $_SESSION variable is used, hope this helps! :)

 

Link to comment
Share on other sites

Well, depending on your structure of your DB.  All you would have to do is when the user finishes the quiz, you can store the score for that quiz with the quiz taker's ID and use PHP's mail functionality to email your employer.  This can all be done as soon as the user's done with the quiz.

Link to comment
Share on other sites

There's other factor's that play into this.

  • Do you need to log the scores for the user for each quiz?
  • What is the structure of your 'quiz' table?
  • What is the structure of your 'user' table?

 

Can't really read your mind so I can't really give any PHP code without knowing the structure of your database tables.

Link to comment
Share on other sites

the quiz table is set up in the database direct-_ar13 set up as the following.

 

quiz (

id tinyint(4) NOT NULL auto_increment,

q text NOT NULL,

question text NOT NULL,

opt1 text NOT NULL,

opt2 text NOT NULL,

opt3 text NOT NULL,

answer text NOT NULL,

PRIMARY KEY (id)

) TYPE=MyISAM;

 

the table users is also in database direct-_ar13

 

users (

id tinyint(4) NOT NULL auto_increment,

firstname text NOT NULL,

lastname text NOT NULL,

employee text NOT NULL,

quiz text NOT NULL,

PRIMARY KEY (id)

) TYPE=MyISAM;

 

I need the results of the quiz to be added to the users table. Then be able to email off those results in some readable form.

 

Thanks a lot, this is a huge help

Link to comment
Share on other sites

What I would recommend is to add another table to map the quiz to a user with the result

 

So your table will look like this:

CREATE TABLE quiz_results (
uid tinyint(4) NOT NULL auto_increment,
qid tinyint(4) NOT NULL auto_increment,
result text NOT NULL
) TYPE=MyISAM;

 

Does that make sense? Or should I elaborate on the structure a little more?

Also, the result field doesn't necessarily have to be text, I just left it that way because I didn't know if the result was a string or a number.

Link to comment
Share on other sites

I guess the simpler way (maybe not)

 

I want to take the value $score (which is the total right) out of $total (which is the total number of questions) and add it to the quiz row of the users table. Then take the user info $firstname, $lastname and $employee with the results and email that.

 

How would I add $score to the users table? $score of course originating from the quiz table.

Link to comment
Share on other sites

Ok... so is this assuming a user will take only 1 quiz?  Or if the user takes another quiz the old result will be erased and a new one will put in there? If so, then all you have to do is this:

 

$query = "UPDATE `users` SET quiz='" . $score . "' WHERE id=" . $userid;
mysql_query($query);

 

This is assuming you have the user's id stored in the $userid variable.  You can replace it with whatever variable holds that value.

Link to comment
Share on other sites

Thanks thats exactly what i was looking for.

 

Another quick n00bie question.

 

Even though i see everything in dreamweaver, when i load it up to the server and check it, it's an empty page. Even View Source won't show anything. Is this because of a connection problem.

 

The database is direct-_ar13 and the table is users. I am using an include with all the mysql connection info. Is there a way to check the integrity of the connection? Or am a miss a bit of code because I am using a table within the database?

 

 

Link to comment
Share on other sites

Hmm... I'm not sure of how your setup is.  Do you test your changes locally (running your own webserver locally) and then upload your changes?  If so then there may be some configuration issues unless your server and your local server are configured exactly the same.

Link to comment
Share on other sites

It's all being tested on the webserver itself.

contentdb.php

<?

include("config.php")

$db = mysql_connect("$hostname","$user","$pass");

mysql_select_db("$database",$db);

?>

config.php

<?

$database = "direct-_ar13.quiz";

$user = "direct-_admin";

$pass = "password";

$hostname = "db.coolersites.com";

$table = "quiz";

?>

 

No matter what I do though I keep getting a blank page. I'm guessing it's because of connection issues, I don't know what else it would be though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.