isset

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!

Moderator: General Moderators

Post Reply
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

isset

Post by nawhaley »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hey guys I'm using PhP 5 on apache, I'm having issues with the isset function and I was wondering if it was disabled or not heres the code I'm using.

Code: Select all

if(isset($_POST['bkquiz']))
{
print("hello to basics");
print("<BR>");
print("bkquiz");
}
now if I did this right this will take the bkquiz button through the post method of my form and see if its set or not. If its set it will do the rest of the code if not it does nothing. I know the buttons set since its doubling as a hyper link like so.

Code: Select all

<FORM METHOD ="POST">
<A HREF = "http://localhost/test.php"><INPUT TYPE ="button" NAME ="bkquiz" VALUE ="Practice"></A>
<A HREF = "http://localhost/test.php"><INPUT TYPE ="button" NAME ="bkquiz1" VALUE ="Timed"></A>
</FORM>
dont mind where the links are pointing thats simply for testing purposes Ideally they wil go to seperate links. What I'm overall trying to do here is send a named value to another part of my program that will then pull questions from a specific catagory for testing in this case the catagories are bkquiz and bkquiz1 for testing reasons. This section I made just to test the form and if the function I wrote is feasible at all for retrieving the catagory. The rest is simply tweaking my SQL code which is way easier.


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hmmm... I've never seen button wrapped within <A HREF>

try this

Code: Select all

<FORM METHOD ="POST" ACTION="test.php"> 
<INPUT TYPE ="submit" NAME ="bkquiz" VALUE ="Practice">

<INPUT TYPE ="submit" NAME ="bkquiz1" VALUE ="Timed">
</FORM>
Instead of two buttons, i'd probably suggesst using radio buttons for user to pick option.

Code: Select all

<form name="form1" id="form1" method="post" action="test.php">
  <input name="bkquiz" type="radio" value="practice" />
  <input name="bkquiz" type="radio" value="timed" />
  <input type="submit" name="Submit" value="Submit" />
</form>

Code: Select all

if(isset($_POST['bkquiz']) && $_POST['bkquiz'] == 'basic') 
{ 
print("hello to basics"); 
print("<BR>"); 
print("bkquiz"); 
}

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

problem with that solution is I would need customized pages for each catagory rather than one generic one with a variable containing the catagory which is what I'm trying to accomplish. What I have right now is a "timed" quiz php file and a "practice" quiz php file. What I want to do is submit a variable to one or the other of these pages and pull the right questions from there. thats why the buttons are encapsulated in hyperlinks when its finished each will take you to a different page and then pull the right data. I'm trying to keep from having like a dozen pages of repetative code if possible.
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

if(isset($_POST['bkquiz']) && $_POST['bkquiz'] == 'basic')  { 
   header("Location: practicequiz.php");
} 
...

or

Code: Select all

if(isset($_POST['bkquiz']) && $_POST['bkquiz'] == 'basic')  { 
   include("practicequiz.php");
} 
.....

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

that might work the underlying problem remains isset dosent "do" anything atm. I"ve never been able to get this function to enter into the condtions statements.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

because with the <a href> buttons you are not POSTING anything, therefor, POST will not have any values. you have to submit the form to make the POST values there, that is why you should make them submit buttons and not link buttons.

<input type="submit" <--- this is what you want. have the form action goto the test.php page or whatever
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

Well....this is an interesting error with the isset function again.

Code: Select all

<HTML>
<FORM METHOD ="POST" ACTION ="http://localhost/relay.php">
<INPUT TYPE ="radio" NAME ="bkquiz" VALUE ="Practice">Practice
<INPUT TYPE ="radio" NAME ="bkquiz" VALUE ="Timed">Timed
<INPUT TYPE ="submit" NAME ="submit" VALUE ="Submit">
</FORM>
</HTML>
thats my HTML obviously

Code: Select all

<?
if(isset($_POST['bkquiz']){
 print("hello");
}
?>
very basic PhP to see if the function even works

Code: Select all

[client 127.0.0.1] PHP Parse error:  syntax error, unexpected '{' in C:\\Web\\relay.php on line 2
the above error when running the code....so....does this funciton "ever" work right?
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

You're missing one closing )

Code: Select all

<? 
if( isset( $_POST['bkquiz'] ) ){ 
print("hello"); 
} 
?>
Post Reply