Page 1 of 1

trouble with quiz script

Posted: Mon Sep 14, 2009 5:44 am
by Schedar
Greeting to you all!
This is my first post on this forum so i hope it will prove useful.
First of all I'm new to mysql and php, I've only coded in xhtml, css so far, now I'm trying to make a simple quiz, I did a little research, and found a simple quiz script(PHP-MySQL-Quiz 1.0) by widgetmonkey. Ever since(actually this morning :D ) I've been trying to make it work yet with little progress. I have easyphp installed, i followed the config steps, still I keep getting:
-------------
Notice: Undefined variable: table in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 7

Notice: Undefined variable: db in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 7

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 7

Notice: Undefined variable: submit in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 9

Notice: Undefined variable: PHP_SELF in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 12

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 15
--------------
in my browser. I think it does not connect properly to the database, maby you guys can help me out.
This are the db connection details:
config.php containing:

Code: Select all

 
<?
$database = "quiz_db";
$user = "quiz_usr";
$pass = "bauhaus";
$hostname = "localhost";
$table = "quiz";
?>
 
-----------
contentdb.php containing:

Code: Select all

 
<?
include("config.php");
 
$db = mysql_connect("$hostname", "$user","$pass");
mysql_select_db("$database",$db);
 
?>
 
------------
and then the actual php file containing the quiz:

Code: Select all

 
<?php
 
include("contentdb.php");
 
$display = mysql_query("SELECT * FROM $table ORDER BY id",$db);
 
--------------
I have only posted the code lines which I think contain the problem, If you need more details just ask.
I configured the usr and password in mysql, created the db, and imported the table quiz from the installation kit of the quiz.
Hope this is enough to make an idea.

Thanks in advance!

Re: trouble with quiz script

Posted: Mon Sep 14, 2009 9:54 am
by Eric!
Since you reposted your code as snips without telling us which lines the error messages are for, I assume the undefined variables it is referring to are $table and $db....

Your variables should be defined fine, even though they are unnessarily two layers down in an include. (You could combine those two includes into one if you wanted).

The only thing I noticed is you're using the short tags <? for the includes and long tags for your main file <?php. It could be that your server is not recognizing the short tags...?

Re: trouble with quiz script

Posted: Mon Sep 14, 2009 1:16 pm
by Schedar
You are right! it worked for most of errors, I replaced the short tags in all the php files yet 2 errors remain, in line 9 and 12:

Code: Select all

 
9: if (!$submit) {
 
12: echo "<form method=post action=$PHP_SELF>";
 
the browser says:

Notice: Undefined variable: submit in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 9

Notice: Undefined variable: PHP_SELF in C:\Program Files\EasyPHP 2.0b1\www\quizv1.0\quizv1.0\quiz1.php on line 12

note:this is only one of the php files, the rest show similar errors about undefined variables... and bottom line is: it's not working:(( help?

Re: trouble with quiz script

Posted: Mon Sep 14, 2009 1:25 pm
by jackpf
1. use isset()
2. use $_SERVER['PHP_SELF']

Re: trouble with quiz script

Posted: Mon Sep 14, 2009 11:57 pm
by Eric!
If you are trying to check the status of your submit button from your form, you need to do it via $_POST['submit_button_name'] and check it's value. If $submit is some other variable, it looks like it is not defined. It's hard to tell from the small bit of code you posted.

Re: trouble with quiz script

Posted: Tue Sep 15, 2009 5:23 am
by jackpf
I wouldn't do that since IE doesn't always send the submit button when you press enter in a text input...

Re: trouble with quiz script

Posted: Tue Sep 15, 2009 8:06 am
by Eric!
I have a feeling his $submit variable is supposed to be set to something from his form. Just a guess.

In IE if the form refreshes on return users automatically think to go hit the submit button when they are done. Sometimes this is a good thing because if you're filling out a lot of text fields it is natural to hit return and you don't want it to submit until your done with the text fields anyway.

Re: trouble with quiz script

Posted: Tue Sep 15, 2009 9:40 am
by jackpf
True...but I just thought I'd point this out anyway, since it had me baffled for a good while when my forms suddenly stopped working once upon a time ;)