PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello. i got a good login script with administrator rights, ban user giving more access to the user in the database. i was trying to create an online test. so i added a table in my database which is as follow:
[syntax="sql"]
DROP TABLE IF EXISTS users;
CREATE TABLE users (
username varchar(30) primary key,
password varchar(32),
userid varchar(32),
userlevel tinyint(1) unsigned not null,
email varchar(50),
timestamp int(11) unsigned not null
);
#
# Table structure for active users table
#
DROP TABLE IF EXISTS active_users;
CREATE TABLE active_users (
username varchar(30) primary key,
timestamp int(11) unsigned not null
);
#
# Table structure for active guests table
#
DROP TABLE IF EXISTS active_guests;
CREATE TABLE active_guests (
ip varchar(15) primary key,
timestamp int(11) unsigned not null
);
#
# Table structure for banned users table
#
DROP TABLE IF EXISTS banned_users;
CREATE TABLE banned_users (
username varchar(30) primary key,
timestamp int(11) unsigned not null
);
CREATE TABLE 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;
everytime i try to insert data it gives me an error column count does not match with row 1
for eg
insert into quiz(id, q, question, opt1, opt2, opt3, answer)
VALUES('0001', '1', 'who is the president of United States?', 'Clinton', 'Bush', 'Regan', 'Bush');
it gives me an error any idea y ? plus i have more question
Thanks
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Notice: Undefined variable: submit in c:\program files\easyphp1-7\www\quizv1.0\quiz1.php on line 9
Notice: Undefined variable: PHP_SELF in c:\program files\easyphp1-7\www\quizv1.0\quiz1.php on line 12
Admin area - edit the quiz
Notice: Undefined variable: submit in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 9
Notice: Undefined variable: update in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 16
Notice: Undefined variable: id in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 22
Maybe they feel that your answer is too obvious...?
Your PHP scripts are giving you the error "undefined variable." Therefore, you are attempting to use an undefined variable.
At no point do I see you assign a value to $submit.
$PHP_SELF should be $_SERVER['PHP_SELF'], and feyd will only tell you that PHP_SELF shouldn't be used.
You don't have your editquiz.php script up, but I'm sure you never assign a value to $submit, $update, or $id. The reason I hadn't responded till now is because I assumed you'd fix something so simple. Before I would need to explain it.
Also, for future reference, I'm sure bumping your post is against the rules. If you want to be noticed, make a single post and you'll be in the "Unanswered Questions" section.
allrite. i saw this undefined variable and yes i looked at it to so i changed my $php_self to quiz1.php. i guess i am new to this php that is y i can't understand how to assign a value to submit. yes you are rite its giving me the same error. i am still trying to fix it. i am able to fix php_self but now that submit is giving me error.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
superdesign you dont know how much i appreciate your patience and help and treating me as a noob. it worked. i made some changes to my quiz1.php file (php_self with _SERVER[PHP_SELF] works fine for me now and the isset submit you told me ) no more notice of warnings and etc. i am using easy php4.1 with mysql 4.1. People have given different ideas that its a bug in 4.0, etc. i got 2 more things to take care of it then once that is done i can play with my login script and put everything all together. when i click on (See how you did) the page does not display anything it just resets the fields. in my admin page i tried to add questions to the database it gives me a big error + a notice on a page. i read some articles regarding notice and they have said that you can ignore it if you want to because it is not an error.
Notice: Undefined variable: alternate in c:\program files\easyphp1-7\www\quizv1.0\editquizlist.php on line 23
there is a button in my editquizlist.php file by the name of (Enter information). i entered a question with the options and the rite answer but when i click on enter information button there is a big error.
You don't have permission to access /quizv1.0/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>c:/program files/easyphp1-7/www/quizv1.0/editquiz.php</b> on line <b>56</b><br /> on this server.
Once again i know its frustrating but if you would like to help that will be great if not then my search will still go on. appreciated.
INSERT INTO quiz(id, q, question, opt1, opt2, opt3, answer)
VALUES('0001', '1', 'who is the president of United States?', 'Clinton', 'Bush', 'Regan', 'Bush');
You dont enter a value for the ID as it is an auto_increment field, just miss it out in your insert statement
fastmike wrote:superdesign you dont know how much i appreciate your patience and help and treating me as a noob. it worked. i made some changes to my quiz1.php file (php_self with _SERVER[PHP_SELF] works fine for me now and the isset submit you told me ) no more notice of warnings and etc. i am using easy php4.1 with mysql 4.1. People have given different ideas that its a bug in 4.0, etc. i got 2 more things to take care of it then once that is done i can play with my login script and put everything all together. when i click on (See how you did) the page does not display anything it just resets the fields. in my admin page i tried to add questions to the database it gives me a big error + a notice on a page. i read some articles regarding notice and they have said that you can ignore it if you want to because it is not an error.
Notice: Undefined variable: alternate in c:\program files\easyphp1-7\www\quizv1.0\editquizlist.php on line 23
there is a button in my editquizlist.php file by the name of (Enter information). i entered a question with the options and the rite answer but when i click on enter information button there is a big error.
You don't have permission to access /quizv1.0/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>c:/program files/easyphp1-7/www/quizv1.0/editquiz.php</b> on line <b>56</b><br /> on this server.
Once again i know its frustrating but if you would like to help that will be great if not then my search will still go on. appreciated.
try using $_SERVER['PHP_SELF'] instead of $PHP_SELF. Also, if you want to avoid those Notice errors for undefined variables you can either turn them using the error_reporting(E_ALL ~ E_NOTICE) or simply define the variable before using it. It's just a basic concept that you can't use some that doesn't exist. So before calling for $submit or any other variable define it, $submit = ''; Another thing you might want to do is turn register_globals off in the php.ini and use php 4's super globals $_POST, $_GET, $_SESSION, $_SERVER. It tends to be a we bit of a security issue especially for beginners, it can complicate things.
Never ever ever turn off E_NOTICE. That does not get rid of the errors, which still happen and fire. They will slow your applications and seriously irritate other developers who have E_NOTICE on and use your application. isset(), empty() and array_key_exists() exist for a reason.
allrite. i did as you specified. well i checked the register_globals which were off already and the error_reporting was already set for what shawnky has wroted. Wow i got the first part working now no notices nothing in my quiz1.php but my question is there is a button by the name of (See How You DId). when a person clicks on it he/she should see the results if he/she did the quiz rite or wrong. but for some reason when i click on that button it just resets the field.
Do not use $_SERVER['PHP_SELF'] or $PHP_SELF, you can use "#" instead most often.
Do not look for the submit button, they aren't always submitted by browsers. Instead look for a field that is always submitted, or possibly $_SERVER['REQUEST_METHOD'] being "POST."
It is often good to always quote all html tag attribute values. This avoids errors, but also gets you closer to validating.
oh wow. i dont have a form field update. That is messed up. i got this script online and was trying to use it with my login script. works fine for the guy who made it http://www.widgetmonkey.com/quiz/quiz1.php
but when i download it it has so many errors which i fixed it and with devnetwork forum help. if i was that good in php i could have done it but i am a noob i have a book but not very helpful. now when you say i need to have an update field do you mean i need to define a variable ?
$update = "";
i dont see any $_SERVER['REQUEST_METHOD'] or "post" all i see is form method = 'post'. this script was really very simple and easy to use as i already have a database with user id, login and password and admin rights if this script worked then all i had to do is just give a link for a user who logs in to take the test and then later on some how store the test result in my database.
And the same thing is with my editquiz.php. there is a button by the name of(Enter Information) when the admin opens the form editquiz.php he/she will be able to add question with all the 3 options and the rite answer and when he/she clicks on enter information button the data should be added to my database, but it gives me a huge error.
You don't have permission to access /quizv1.0/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>c:/program files/easyphp1-7/www/quizv1.0/editquiz.php</b> on line <b>59</b><br /> on this server.