Jump to content

Unset isnt working like I want it to


jdock1

Recommended Posts

I am using an if statement. If the user has a credit value of 1 or more it echos a variable thats a form. When the user submits the form, it takes a credit away, so the credit value is -1. I need the form to dissapear, because the form has a button that will execute a query that I dont want to execute.

 

So, usually unset() fixes this, but its not in my case.

 

Heres the code

$a='<strong></strong>';
					if ($hintcredit<1)
						$a.='<font style="color: #cc0000;">You have already requested a hint! Once you guess the correct number, you will be able to get another hint. </font>';
					else
$form= "<form action='blablabla' method='post'>blablablabla</form>";
						$a.=$form;
					$a.='<strong></strong>';
                        echo $a;
					if ($_POST['request'] == "Retrieve Hint")
					{
						unset($form);
						$form= '<b>One of the digits in your number is '.substr($num, -1).'</b>';
						$newquery= "UPDATE userinfo SET hint_credits = '-1' WHERE username = '".$_SESSION['login_name']."'";
						echo $form;

						mysql_query($newquery,$link);

					}

 

In this case, the form is still being shown.

 

I need the form completely removed after the form has been submitted.

 

This is simple and idk why its not working for me!?

Link to comment
https://forums.phpfreaks.com/topic/234413-unset-isnt-working-like-i-want-it-to/
Share on other sites

You define $form, then unset it after concatenating it to $a, then you define $form again after you unset it? The logic in that code isn't the easiest to follow. What exactly are you trying to make it do?

Seems like you could just use a "$showform" variable that's is changed if processing doesn't validate.  For example.

IF ($_POST['Submit']=='Submit){
$showform=false;
IF (!empty($_POST['name'])){
$ckname=('good');
}
Else{
$ckname=('bad');
$showform=true;
}
//ect through the rest of the processing

IF anything doesn't pass, $showform will be true and you can use this to show the form.  Hey, just an idea.

Seems like you could just use a "$showform" variable that's is changed if processing doesn't validate.  For example.

IF ($_POST['Submit']=='Submit){
$showform=false;
IF (!empty($_POST['name'])){
$ckname=('good');
}
Else{
$ckname=('bad');
$showform=true;
}
//ect through the rest of the processing

IF anything doesn't pass, $showform will be true and you can use this to show the form.  Hey, just an idea.

 

Thanks for the idea. Yeah, that seems like itd be easier.

 

And yes, I know, I have the shittiest code. I can code, but its very messy!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.