Jump to content

Recommended Posts

Hi, freaks!

 

I have a problem that I thought is very small, but unfortunately when I started to edit the index.php all the content crashed.

 

I have to edit a game website in PHP. The game is sitiated on the page "Play". It contains 4 questions and when they are answered right, it redirects to a registration form where everyone can fill his data.

 

The problem is that now I don't want these questions and and what I want is when someone open page Play only the registration form to be loaded. The filled data is sent to a database.

 

When I remove some of the steps, the website brokes. When I remove one of the functions which check if the questions are answered, the button Send doesn't work, so now after 3 days work I'm really stuck.

 

I'm beginner in PHP coding and I will be very thankful if you can help me.

 

Here is the idex.php code:

<?
require_once('config.php');
   $names='';
   $first='';
   $last='';
   $dob='';
   $email='';
   $phone='';
   $error=0;
   $message='';
   $subject='';
   $content='';
   if(!empty($_POST['contact']) && (int)$_POST['contact']==1){
    $names=trim(strip_tags($_POST['names']));
    $email=trim(strip_tags($_POST['email']));
    $phone=trim(strip_tags($_POST['phone']));
    $subject=trim(strip_tags($_POST['subject']));
    $content=trim(strip_tags($_POST['content']));
    if(empty($names) || empty($email) || empty($content)){
	    $error=1;
	    $message.='Please, fill all the fields marked with *<br>';
    }
    elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)){
	    $error=1;
	    $message.='The email is wrong.<br>';
    }
    if(!$error){
	    $headers="From:".$email_from."\r\n";
	    $body = 'Name: '.$names."\n";
	    $body .= 'email: '.$email."\n";
	    $body .= 'Telephone: '.$phone."\n";
	    $body .= 'IP address: '.$_SERVER['REMOTE_ADDR']."\n\n";
	    $body .= 'Sent date: '.date('r')."\n\n";
	    $body .= 'about:\n'.$subject."\n\n";
	    $body .= 'message:\n'.$content."\n\n";
	    $sent=mail($email_to,($subject?$subject:'subject not entered'), $body, $headers);
	    if($sent){
		    header('Location: ?p=contacts&ok=1');
		    exit;
	    }
	    else {
		    $error=1;
		    $message.='An error has ocurred. Please, try again later.<br>';
	    }
    }

   }

   if(!empty($_POST['register']) && (int)$_POST['register']==1){
    $first=trim(strip_tags($_POST['first']));
    $last=trim(strip_tags($_POST['last']));
    $dob=trim(strip_tags($_POST['dob']));
    $email=trim(strip_tags($_POST['email']));
    $phone=trim(strip_tags($_POST['phone']));
    $subscribe=intval($_POST['subscribe']);
    if(empty($first) || empty($last) || empty($dob) || empty($email) || empty($phone)){
	    $error=1;
	    $message.='Please fill all the fields.<br>';
    }
    elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)){
	    $error=1;
	    $message.='The email is wrong.<br>';
    }
    elseif(mysql_result(mysql_query('select count(*) from _participants where email ="'.mysql_real_escape_string($email).'"'),0,0)){
	    $error=1;
	    $message.='The email is already used.<br>';
    }
    if(!$error){
	    $sql='insert into _participants
		    (created, first, last, bdate, email, phone, subscribe, ip)
		    values (
			    NOW(),
			    "'.mysql_real_escape_string($first).'",
			    "'.mysql_real_escape_string($last).'",
			    "'.mysql_real_escape_string($dob).'",
			    "'.mysql_real_escape_string($email).'",
			    "'.mysql_real_escape_string($phone).'",
			    '.$subscribe.',
			    INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
			    )';
	    $q=mysql_query($sql);
	    if($q){
		    $_SESSION['step']=6;
		    header('Location: ?p=play&s='.rand());
		    exit;
	    }
    }
   }

   $pages=array();
   $pages['index']='Home';
   $pages['terms']='Rules';
  $pages['play']='Play';
   $pages['awards']='Awards';
   $pages['contacts']='Contacts';
   // where are we
   $page='index';
   if(!empty($_GET['p']) && isset($pages[$_GET['p']])){
    $page=$_GET['p'];
   }
?><!doctype html>
<html>
<head>
   <meta charset="UTF-8" />
   <meta name="viewport" content="width=device-width" />
   <title>Website Name</title>
   <link rel="stylesheet" type="text/css" media="all" href="style.css" />
   <script type='text/javascript' src='js/jquery.min.js'></script>
   <script type='text/javascript' src='js/site.js'></script>
</head>
<body class=<?=$page?>>
<div id=wrap>
   <div id=header>
    <div id=web_head>
	    <div id=web_logo>
		    Web
	    </div>
	    <div id=web_slogan>
		    Company Name
	    </div>
    </div>
    <div id=nav>
	    <?
		    foreach($pages as $p=>$title){
			    ?>
				    <a href="<?=($p=='index'?'index.php':'?p='.$p)?>" <?=($p=='index'?'class="first'.($p==$page?' active':'').'"' $p==$page?'class=active':''))?>><?=$title?></a>
			    <?
		    }
	    ?>
    </div>
   </div>
   <div id=main>
   <?
    switch($page){
	    case 'play':
		    echo page_play();
		    break;
	    case 'terms':
		    echo page_terms();
		    break;
	    case 'awards':
		    echo page_awards();
	    break;
	    case 'contacts':
		    echo page_contacts();
		    break;
	    case 'index':
	    default:
		    echo page_index();
		    break;
    }
   ?>
   </div>
   <div id=footer></div>
</div>
</body>
</html>
<?
   function check_step() {
    $step=(int)$_SESSION['step'];
    switch($step){
	    case 1:
		    if(!empty($_POST['q1']) && intval($_POST['q1'])==2){
			    $_SESSION['step']=2;
		    }
		    break;
	    case 2:
		    if(!empty($_POST['q2']) && intval($_POST['q2'])>0 && intval($_POST['q2'])<4){
			    $_SESSION['step']=3;
		    }
		    break;
	    case 3:
		    if(!empty($_POST['q3']) && intval($_POST['q3'])==3){
			    $_SESSION['step']=4;
		    }
		    break;
	    case 4:
		    if(!empty($_POST['q4']) && intval($_POST['q4'])==3){
			    $_SESSION['step']=5;
		    }
		    break;
    }
   }
   function play_step() {
    global $message, $first, $last, $dob, $email, $phone, $error;
    if(empty($_SESSION['step'])){
	    $_SESSION['step']=1;
    }
    if(!empty($_POST)){
	    check_step();
    }
    $step=(int)$_SESSION['step'];
    $r='';
    switch($step){
	    case 5:
		    $r.='
			    <div class=q id=success>
				    <h1>Congratulation!</h1>
				    <h2>You've answered all the questions. Fill the registration form to participate in the game.</h2>
				    '.(!empty($message)?'<div class=message>'.$message.'</div>':'').'
				    <div class=fields>
					    <label for=first>Name: *</label><input type=text name=first value="'.str_replace('"','"',$first).'"><br>
					    <label for=last>Family name: *</label><input type=text name=last value="'.str_replace('"','"',$last).'"><br>
					    <label for=dob>Date of birth: *</label><input type=text name=dob value="'.str_replace('"','"',$dob).'" placeholder="дд.мм.гггг"><br>
					    <label for=email>Email: *</label><input type=text name=email value="'.str_replace('"','"',$email).'"><br>
					    <label for=phone>Telephone: *</label><input type=text name=phone value="'.str_replace('"','"',$phone).'"><br>
					    <label class=long for=subscribe>I want to have news from you</label> <span class=radio_block><input type=radio value=0 name=subscribe '.( (isset($_POST['subscribe']) && (int)$_POST['subscribe']==0) || !isset($_POST['subscribe'])?' checked':'').'> No <input type=radio value=1 name=subscribe '.(isset($_POST['subscribe']) && (int)$_POST['subscribe']==1?' checked':'').'> Yes</span><br><br>
					    <label class=long>I agree with the Terms <a href="?p=terms" target="_blank">Terms</a></label><br><br><br>
					    <input type=hidden value=1 name=register>
					    <button>Send</button>
				    </div>
			    </div>
		    ';
		    break;
	    case 4:
		    $r.='
			    <div class=q id=q_4>
				    <h1>4. Question 4?</h1>
				    <label class="label_radio" for="q4"><input type=radio name=q4 value=1 data-check=3> A. Answer 1</label>
				    <label class="label_radio" for="q4"><input type=radio name=q4 value=2 data-check=3> B. Answer 2</label>
				    <label class="label_radio" for="q4"><input type=radio name=q4 value=3 data-check=3> C. Answer 3</label>
				    <div class=products></div>
				    <div class=comment id=q4_1 style="display:none">Your answer is wrong! </div>
				    <div class=comment id=q4_2 style="display:none">Your answer is wrong!</div>
				    <div class=comment id=q4_3 style="display:none">Correct answer!</div>
			    </div>
		    ';
		    break;
	    case 3:
		    $r.='
			    <div class=q id=q_3>
				    <h1>3. Question 3?</h1>
				    <label class="label_radio" for="q3"><input type=radio name=q3 value=1 data-check=3> A. Answer 1</label>
				    <label class="label_radio" for="q3"><input type=radio name=q3 value=2 data-check=3> B. Answer 2</label>
				    <label class="label_radio" for="q3"><input type=radio name=q3 value=3 data-check=3> C. Answer 3</label>
				    <div class=products></div>
				    <div class=comment id=q3_1 style="display:none">Your answer is wrong!</div>
				    <div class=comment id=q3_2 style="display:none">Your answer is wrong!</div>
				    <div class=comment id=q3_3 style="display:none">Correct answer!</div>
			    </div>
		    ';
		    break;
	    case 2:
		    $r.='
			    <div class=q id=q_2>
				    <h1>2. Question 2?</h1>
				    <label class="label_radio" for="q2"><input type=radio name=q2 value=1 data-check=1> A. Answer 1</label>
				    <label class="label_radio" for="q2"><input type=radio name=q2 value=2 data-check=2> B. Answer 2</label>
				    <label class="label_radio" for="q2"><input type=radio name=q2 value=3 data-check=3> C. Answer 3</label>
				    <div class=products></div>
				    <div class=comment id=q2_1 style="display:none">Your answer is wrong! </div>
				    <div class=comment id=q2_2 style="display:none">Your answer is wrong! </div>
				    <div class=comment id=q2_3 style="display:none">Correct answer!</div>
			    </div>
		    ';
		    break;
	    case 1:
	    default:
		    $r.='
			    <div class=q id=q_1>
				    <h1>1. Question 1?</h1>
				    <table>
					    <tr>
						    <td>
							    <h2>A. Answer 1<br><br></h2>
							    <label class="label_radio" for="q1"><input type=radio name=q1 value=1 data-check=2> </label>
						    </td>
						    <td>
							    <h2>B. Answer 2</h2>
							    <label class="label_radio" for="q2"><input type=radio name=q1 value=2 data-check=2> </label>
						    </td>
					    </tr>
				    </table>
				    <div class=products></div>
				    <div class=comment id=q1_1 style="display:none">Your answer is wrong!</div>
				    <div class=comment id=q1_2 style="display:none">Correct answer!</div>
			    </div>
		    ';
		    break;
    }
    return $r;
   }

   function page_play() {
    global $message, $first, $last, $dob, $email, $phone, $error;

    if(isset($_SESSION['step']) && $_SESSION['step']==6){
	    unset($_SESSION['step']);
	    $r='
		    <div class=q id=success>
			    <h1>Thanks for your participation</h1>
			    <h2>Wait for the winners next week</h2>
	    ';
    }
    else {
	    $r='<form id=player action="" method=post>';
	    $r.=play_step();
	    $r.='<div id=continue style="display:none"></div>';
	    $r.='<div id=try_again class=play_btn style="display:none">Try again</div>';
	    $r.='</form>';
    }
    return $r;
   }
   function page_contacts() {
    global $message, $names, $phone, $email, $subject, $content;
    if(!empty($_GET['ok'])){
	    $r='<div><h1>Your message was successfully sent.</h1></div>';
	    return $r;
    }
    $r='';
    $r.='<div><h1>Contact form:</h1>

    '.(!empty($message)?'<div class=message>'.$message.'</div>':'').'
    <form id=contact_form method=post>
	    <div class=long>
		    <label for="names">Name: *</label>
		    <input type=text name=names value="'.str_replace('"','"', $names).'">
	    </div>
	    <div class=short>
		    <label for="phone">Telephone: </label>
		    <input type=text name=phone value="'.str_replace('"','"', $phone).'">
	    </div>
	    <div class="short last">
		    <label for="email">E-mail: *</label>
		    <input type=text name=email value="'.str_replace('"','"', $email).'">
	    </div>
	    <div class=long>
		    <label for="subject">about: </label>
		    <input type=text name=subject value="'.str_replace('"','"', $subject).'">
	    </div>
	    <div class=long>
		    <label for="message">Free text: *</label>
		    <textarea name=content>'.str_replace('"','"', $content).'</textarea>
	    </div>
	    <input type=hidden value=1 name=contact>
	    <button class=play_btn>Send</button>
    </form>
    </div>
    ';
    return $r;
   }
   function page_awards() {
    $r='';
    $r.='<div><h1>Awards</h1>

<a href="?p=play" class=play_btn>play now</a>
</div>';
    return $r;
   }
   function page_terms() {
    $r='';
    $r.='<div><h1>Rules</h1>
Some rules
    return nl2br($r);
   }
   function page_index() {
/*
   $r='';
    $r.='<h1>Play and win</h1>';
    $r.='';
    $r.='<a href="?p=play" class=play_btn>play now</a>';
*/
$r='
<div style="font-size:14px;text-align:left;padding:10px"><h1 style="font-size:18px;padding:25px 0">Winners in the game
</div>
';
    return $r;
   }
?>

 

 

index.php

Edited by mayabrazil
Link to comment
https://forums.phpfreaks.com/topic/273907-php-game-code-help/
Share on other sites

Actually I have a mistake in one of the text strings but the point is the same: How to bypass the qusetions (steps/cases 1,2,3,4) and on page Play only the registration form (case 5) to be loaded.

 

Thanks in advance!

 

<?
require_once('config.php');
$names='';
$first='';
$last='';
$dob='';
$email='';
$phone='';
$error=0;
$message='';
$subject='';
$content='';
if(!empty($_POST['contact']) && (int)$_POST['contact']==1){
$names=trim(strip_tags($_POST['names']));
$email=trim(strip_tags($_POST['email']));
$phone=trim(strip_tags($_POST['phone']));
$subject=trim(strip_tags($_POST['subject']));
$content=trim(strip_tags($_POST['content']));
if(empty($names) || empty($email) || empty($content)){
$error=1;
$message.='Please fill all the fields with *<br>';
}
elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)){
$error=1;
$message.='The email is not valid.<br>';
}
if(!$error){
$headers="From:".$email_from."\r\n";
$body = 'Name: '.$names."\n";
$body .= 'email: '.$email."\n";
$body .= 'telephone: '.$phone."\n";
$body .= 'IP address: '.$_SERVER['REMOTE_ADDR']."\n\n";
$body .= 'sent on: '.date('r')."\n\n";
$body .= 'about:\n'.$subject."\n\n";
$body .= 'message:\n'.$content."\n\n";
$sent=mail($email_to,($subject?$subject:'subject not entered'), $body, $headers);
if($sent){
header('Location: ?p=contacts&ok=1');
exit;
}
else {
$error=1;
$message.='An error has occurred. Please, try later.<br>';
}
}

}

if(!empty($_POST['register']) && (int)$_POST['register']==1){
$first=trim(strip_tags($_POST['first']));
$last=trim(strip_tags($_POST['last']));
$dob=trim(strip_tags($_POST['dob']));
$email=trim(strip_tags($_POST['email']));
$phone=trim(strip_tags($_POST['phone']));
$subscribe=intval($_POST['subscribe']);
if(empty($first) || empty($last) || empty($dob) || empty($email) || empty($phone)){
$error=1;
$message.='Please, fill all the fields.<br>';
}
elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)){
$error=1;
$message.='The email is wrong.<br>';
}
elseif(mysql_result(mysql_query('select count(*) from _participants where email ="'.mysql_real_escape_string($email).'"'),0,0)){
$error=1;
$message.='The email is already used.<br>';
}
if(!$error){
$sql='insert into _participants
(created, first, last, bdate, email, phone, subscribe, ip)
values (
 NOW(),
 "'.mysql_real_escape_string($first).'",
 "'.mysql_real_escape_string($last).'",
 "'.mysql_real_escape_string($dob).'",
 "'.mysql_real_escape_string($email).'",
 "'.mysql_real_escape_string($phone).'",
 '.$subscribe.',
 INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
 )';
$q=mysql_query($sql);
if($q){
$_SESSION['step']=6;
header('Location: ?p=play&s='.rand());
exit;
}
}
}

$pages=array();
$pages['index']='Home';
$pages['terms']='Rules';
$pages['play']='Play';
$pages['awards']='Awards';
$pages['contacts']='Contacts';

$page='index';
if(!empty($_GET['p']) && isset($pages[$_GET['p']])){
$page=$_GET['p'];
}
?><!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Website</title>
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
<script type='text/javascript' src='js/jquery.min.js'></script>
<script type='text/javascript' src='js/site.js'></script>
</head>
<body class=<?=$page?>>
<div id=wrap>
<div id=header>
<div id=web_head>
<div id=web_logo>
Website
</div>
<div id=web_slogan>
Slogan
</div>
</div>
<div id=nav>
<?
foreach($pages as $p=>$title){
 ?>
 <a href="<?=($p=='index'?'index.php':'?p='.$p)?>" <?=($p=='index'?'class="first'.($p==$page?' active':'').'"'$p==$page?'class=active':''))?>><?=$title?></a>
 <?
}
?>
</div>
</div>
<div id=main>
<?
switch($page){
case 'play':
echo page_play();
break;
case 'terms':
echo page_terms();
break;
case 'awards':
echo page_awards();
break;
case 'contacts':
echo page_contacts();
break;
case 'index':
default:
echo page_index();
break;
}
?>
</div>
<div id=footer></div>
</div>
</body>
</html>
<?
function check_step() {
$step=(int)$_SESSION['step'];
switch($step){
case 1:
if(!empty($_POST['q1']) && intval($_POST['q1'])==2){
 $_SESSION['step']=2;
}
break;
case 2:
if(!empty($_POST['q2']) && intval($_POST['q2'])>0 && intval($_POST['q2'])<4){
 $_SESSION['step']=3;
}
break;
case 3:
if(!empty($_POST['q3']) && intval($_POST['q3'])==3){
 $_SESSION['step']=4;
}
break;
case 4:
if(!empty($_POST['q4']) && intval($_POST['q4'])==3){
 $_SESSION['step']=5;
}
break;
}
}
function play_step() {
global $message, $first, $last, $dob, $email, $phone, $error;
if(empty($_SESSION['step'])){
$_SESSION['step']=1;
}
if(!empty($_POST)){
check_step();
}
$step=(int)$_SESSION['step'];
$r='';
switch($step){
case 5:
$r.='
 <div class=q id=success>
 <h1>Congratulations!</h1>
 <h2>You have answered all the 4 questions correct. Please, fill the registration form.</h2>
 '.(!empty($message)?'<div class=message>'.$message.'</div>':'').'
 <div class=fields>
 <label for=first>Name: *</label><input type=text name=first value="'.str_replace('"','"',$first).'"><br>
 <label for=last>Family name: *</label><input type=text name=last value="'.str_replace('"','"',$last).'"><br>
 <label for=dob>Date of birth: *</label><input type=text name=dob value="'.str_replace('"','"',$dob).'" placeholder="дд.мм.гггг"><br>
 <label for=email>E-mail: *</label><input type=text name=email value="'.str_replace('"','"',$email).'"><br>
 <label for=phone>Telephone: *</label><input type=text name=phone value="'.str_replace('"','"',$phone).'"><br>
 <label class=long for=subscribe>Do you wish to send you news?<br>
 from Web </label> <span class=radio_block><input type=radio value=0 name=subscribe '.( (isset($_POST['subscribe']) && (int)$_POST['subscribe']==0) || !isset($_POST['subscribe'])?' checked':'').'> No <input type=radio value=1 name=subscribe '.(isset($_POST['subscribe']) && (int)$_POST['subscribe']==1?' checked':'').'> Yes</span><br><br>
 <label class=long>I agree with the Terms<a href="?p=terms" target="_blank">Terms</a></label><br><br><br>
 <input type=hidden value=1 name=register>
 <button>Send</button>
 </div>
 </div>
';
break;
case 4:
$r.='
 <div class=q id=q_4>
 <h1>4. Question 4?</h1>
 <label class="label_radio" for="q4"><input type=radio name=q4 value=1 data-check=3> A. Answer 1</label>
 <label class="label_radio" for="q4"><input type=radio name=q4 value=2 data-check=3> B. Answer 2</label>
 <label class="label_radio" for="q4"><input type=radio name=q4 value=3 data-check=3> C. Answer 3</label>
 <div class=products></div>
 <div class=comment id=q4_1 style="display:none">Wrong answer! </div>
 <div class=comment id=q4_2 style="display:none">Wrong answer! </div>
 <div class=comment id=q4_3 style="display:none">Correct answer! </div>
 </div>
';
break;
case 3:
$r.='
 <div class=q id=q_3>
 <h1>3. Qustion 3?</h1>
 <label class="label_radio" for="q3"><input type=radio name=q3 value=1 data-check=3> A. Answer 1</label>
 <label class="label_radio" for="q3"><input type=radio name=q3 value=2 data-check=3> B. Answer 2</label>
 <label class="label_radio" for="q3"><input type=radio name=q3 value=3 data-check=3> C. Answer 3</label>
 <div class=products></div>
 <div class=comment id=q3_1 style="display:none">Wrong answer! </div>
 <div class=comment id=q3_2 style="display:none">Wrong answer! </div>
 <div class=comment id=q3_3 style="display:none">Correct answer!</div>
 </div>
';
break;
case 2:
$r.='
 <div class=q id=q_2>
 <h1>2. Question 2?</h1>
 <label class="label_radio" for="q2"><input type=radio name=q2 value=1 data-check=1> A. Answer 1</label>
 <label class="label_radio" for="q2"><input type=radio name=q2 value=2 data-check=2> B. Answer 2</label>
 <label class="label_radio" for="q2"><input type=radio name=q2 value=3 data-check=3> C. Answer 3</label>
 <div class=products></div>
 <div class=comment id=q2_1 style="display:none">Wrong answer!</div>
 <div class=comment id=q2_2 style="display:none">Wrong answer!</div>
 <div class=comment id=q2_3 style="display:none">Correct answer!</div>
 </div>
';
break;
case 1:
default:
$r.='
 <div class=q id=q_1>
 <h1>1. Question 1?</h1>
 <table>
 <tr>
 <td>
	 <h2>A. Answer 1<br><br></h2>
	 <label class="label_radio" for="q1"><input type=radio name=q1 value=1 data-check=2> </label>
 </td>
 <td>
	 <h2>B. Answer 2</h2>
	 <label class="label_radio" for="q2"><input type=radio name=q1 value=2 data-check=2> </label>
 </td>
 </tr>
 </table>
 <div class=products></div>
 <div class=comment id=q1_1 style="display:none">Wrong answer!</div>
 <div class=comment id=q1_2 style="display:none">Correct answer!</div>
 </div>
';
break;
}
return $r;
}

function page_play() {
global $message, $first, $last, $dob, $email, $phone, $error;

if(isset($_SESSION['step']) && $_SESSION['step']==6){
unset($_SESSION['step']);
$r='
<div class=q id=success>
 <h1>Thank you for your registration!</h1>

';
}
else {
$r='<form id=player action="" method=post>';
$r.=play_step();
$r.='<div id=continue style="display:none"></div>';
$r.='<div id=try_again class=play_btn style="display:none">try again</div>';
$r.='</form>';
}
return $r;
}
function page_contacts() {
global $message, $names, $phone, $email, $subject, $content;
if(!empty($_GET['ok'])){
$r='<div><h1>Your message was sent successfully.</h1></div>';
return $r;
}
$r='';
$r.='<div><h1>Contacts</h1>

'.(!empty($message)?'<div class=message>'.$message.'</div>':'').'
<form id=contact_form method=post>
<div class=long>
<label for="names">Name: *</label>
<input type=text name=names value="'.str_replace('"','"', $names).'">
</div>
<div class=short>
<label for="phone">Telephone: </label>
<input type=text name=phone value="'.str_replace('"','"', $phone).'">
</div>
<div class="short last">
<label for="email">E-mail: *</label>
<input type=text name=email value="'.str_replace('"','"', $email).'">
</div>
<div class=long>
<label for="subject">about: </label>
<input type=text name=subject value="'.str_replace('"','"', $subject).'">
</div>
<div class=long>
<label for="message">Free text: *</label>
<textarea name=content>'.str_replace('"','"', $content).'</textarea>
</div>
<input type=hidden value=1 name=contact>
<button class=play_btn>Send</button>
</form>
</div>
';
return $r;
}
function page_awards() {
$r='';
$r.='<div><h1>Awards</h1>
</div>';
return $r;
}
function page_terms() {
$r='';
$r.='<div><h1>Rules/Terms</h1>
Some rules.</div>';
return nl2br($r);
}
function page_index() {

$r='';
$r.='<h1>Play</h1>';
$r.='Answer all the 4 questions';
$r.='<a href="?p=play" class=play_btn>play now</a>';
/*$r='
<div style="font-size:14px;text-align:left;padding:10px"><h1 style="font-size:18px;padding:25px 0">Winners
</div>
';
*/

return $r;
}
?>

index.php

Edited by mayabrazil
Link to comment
https://forums.phpfreaks.com/topic/273907-php-game-code-help/#findComment-1409696
Share on other sites

Instead of initializing $_SESSION['step'] to a one, set it to 5 -

 

if(empty($_SESSION['step'])){
$_SESSION['step']=5; // start at step 5 (was a 1)
}

 

You can then of course eliminate all the logic for steps 1-4 and even the switch/case statement logic and the check_step() function and logic to call it.

Edited by PFMaBiSmAd
Link to comment
https://forums.phpfreaks.com/topic/273907-php-game-code-help/#findComment-1409702
Share on other sites

Instead of initializing $_SESSION['step'] to a one, set it to 5 -

 

if(empty($_SESSION['step'])){
$_SESSION['step']=5; // start at step 5 (was a 1)
}

 

You can then of course eliminate all the logic for steps 1-4 and even the switch/case statement logic and the check_step() function and logic to call it.

 

Thank you, PFMaBiSmAd! It works!!! I really appreciate your help!!!

 

Actually i tried this way but may be I have had too many other changes in the code, so it didn't work then.

 

If I can help you, please feel free to tell me! I promise to learn PHP and not to ask questions like these! :)

 

Have a nice day!

Link to comment
https://forums.phpfreaks.com/topic/273907-php-game-code-help/#findComment-1409719
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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