jessicabo Posted June 19, 2007 Share Posted June 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/ Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-277858 Share on other sites More sharing options...
jessicabo Posted June 19, 2007 Author Share Posted June 19, 2007 Thanks that definitely helps. Any help on connecting the two pieces. The registration and login to the quiz results that need to be stored in a DB and emailed to the employer? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278017 Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278023 Share on other sites More sharing options...
jessicabo Posted June 20, 2007 Author Share Posted June 20, 2007 I have two databases set up. One for user information and one for the quiz. So I need to combine the two tables and put them into an email. Any chance you know the php code for that? The two databases are called users and quiz. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278645 Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278661 Share on other sites More sharing options...
jessicabo Posted June 20, 2007 Author Share Posted June 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278669 Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278680 Share on other sites More sharing options...
jessicabo Posted June 20, 2007 Author Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278692 Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278707 Share on other sites More sharing options...
jessicabo Posted June 20, 2007 Author Share Posted June 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278713 Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278721 Share on other sites More sharing options...
jessicabo Posted June 20, 2007 Author Share Posted June 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278734 Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 Well.. to check to see if there are connection issues do this: $db = mysql_connect("$hostname","$user","$pass") or die("Unable to connect to mysql server: " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278845 Share on other sites More sharing options...
jessicabo Posted June 20, 2007 Author Share Posted June 20, 2007 just what i needed and i got the connection working... finally. thanks Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278864 Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 Sweet! Quote Link to comment https://forums.phpfreaks.com/topic/56247-phpmysql-connection-problems/#findComment-278915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.