0

I have only coded for a month, and less than 3 days with php. Thank-you for your any assistance I can get on this.

<?PHP
require_once("session.php");
require_once("./include/membersite_config.php");

if(isset($_POST['submitted']))
{
   if($fgmembersite->RegisterUser())
   {
        $fgmembersite->RedirectToURL("thank-you.html");
   }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
    <title>Contact us</title>
    <link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css" />
    <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
    <link rel="STYLESHEET" type="text/css" href="style/pwdwidget.css" />
    <script src="scripts/pwdwidget.js" type="text/javascript"></script>      
</head>
<body>

<!-- Form Code Start -->

<div id='fg_membersite'>

 <!-- I believe the problem is right in here. -->
<form action="session.php" method="post">        
<form id='register' action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
  </form>  
<fieldset >
<legend>Register</legend>

<input type='hidden' name='submitted' id='submitted' value='1'/>

<div class='short_explanation'>* required fields</div>
<input type='text'  class='spmhidip' name='<?php echo $fgmembersite->GetSpamTrapInputName(); ?>' />

<div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>

<div class='container'>
    <label for='name' >Your Full Name*: </label><br/>
    <input type='text' name='name' id='name' value='<?php echo $fgmembersite->SafeDisplay('name') ?>' maxlength="50" /><br/>
    <span id='register_name_errorloc' class='error'></span>
</div>
<FORM name ="form1" method ="post" action ="radioButton.php">

<Input type = 'Radio' Name ='gender' value= 'male' required value="1"
<?PHP print $male_status; ?>
>male

<Input type = 'Radio' Name ='gender' value= 'female' required value="2"
<?PHP print $female_status; ?>
>female

<P>
</FORM>
<div class='container'>
    <label for='email' >Email Address*:</label><br/>
    <input type='text' name='email' id='email' value='<?php echo $fgmembersite->SafeDisplay('email') ?>' maxlength="50" /><br/>
    <span id='register_email_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='username' >UserName*:</label><br/>
    <input type='text' name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
    <span id='register_username_errorloc' class='error'></span>
</div>
<div class='container' style='height:80px;'>
    <label for='password' >Password*:</label><br/>
    <div class='pwdwidgetdiv' id='thepwddiv' ></div>
    <noscript>
    <input type='password' name='password' id='password' maxlength="50" />
    </noscript>    
    <div id='register_password_errorloc' class='error' style='clear:both'></div>
</div>

<div class='container'>
    <input type='submit' name='Submit' value='Submit' />
</div>

</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->

<script type='text/javascript'>
// <![CDATA[
    var pwdwidget = new PasswordWidget('thepwddiv','password');
    pwdwidget.MakePWDWidget();

    var frmvalidator  = new Validator("register");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();
    frmvalidator.addValidation("name","req","Please provide your name");

    frmvalidator.addValidation("email","req","Please provide your email address");

    frmvalidator.addValidation("email","email","Please provide a valid email address");

    frmvalidator.addValidation("username","req","Please provide a username");

    frmvalidator.addValidation("password","req","Please provide a password");

// ]]>
</script>

<!--
Form Code End (see html-form-guide.com for more info.)
-->

</body>
</html>

This file does work well, but for the fact that the current setup does not show the "username" and "gender" in the url after submission.

<?php
session_start();
 if (isset($_POST['username']) && isset($_POST['gender'])) {
  $user = $_POST['username'];
  $gen = $_POST['gender'];

  echo 'Username: '. $username. ' - gender: '. $gender;
}
?>

This is the session.php file I have been trying to use.

  • 1
    You access session data via $_SESSION not $_GET. Is that what you are looking for? If you want data submitted from a form using method=post, then you need $_POST. You should read the php manual about SUPERGLOBALS. – mickmackusa Jan 18 '18 at 04:27
  • What do you mean `post` Post is a type of web request with parameters, usually done by forms, but sometimes using libraries like CURL. – ArtisticPhoenix Jan 18 '18 at 04:29
  • Ok, I fixed you Question, the misplaced `` comment was messing it all up. Where the form was not even showing. Anyway, I fixed it, yea. – ArtisticPhoenix Jan 18 '18 at 04:31
  • Thank-you ArtisticPhoenix. This is my first post here, and I am still trying to show where I believe the problem is in register.php. – chrisx2600 Jan 18 '18 at 04:40
  • 1
    Possible duplicate of [How can I access my session variable in a different page with php?](https://stackoverflow.com/questions/28403784/how-can-i-access-my-session-variable-in-a-different-page-with-php) – mickmackusa Jan 18 '18 at 04:41
  • First thing please have a look at get and post request type They both have different behaviour. So go ahead and have a look at https://stackoverflow.com/questions/3477333/what-is-the-difference-between-post-and-get. Secondly you should have a look at your html. Next thing is have a close look here : https://www.w3schools.com/php/php_forms.asp It is really a good starting point for forms and handling forms in php. – Manishh Jan 18 '18 at 04:54

2 Answers2

0

I didn't get what you are trying to do with session variables here, but just to keep your data in session, do this

$_SESSION["user"] = $user
$_SESSION["gender"] = $gender;

So that you can use $_SESSION["user"] and $_SESSION["gender"] throughout your project until session exists.

Don't forget to start the session.

UPDATE

As you recently changed form method to post, change variables in session.php to $_POST["user"] and so on.

NEXT

<FORM name ="form1" method ="post" action ="radioButton.php">

<Input type = 'Radio' Name ='gender' value= 'male' required value="1"
<?PHP print $male_status; ?>
>male

<Input type = 'Radio' Name ='gender' value= 'female' required value="2"
<?PHP print $female_status; ?>
>female

<P>
</FORM>

You don't need form here. remove form starting and closing tags.

Now as I see 'username' field name in register.php, change name to username inside session.php

Suresh Pokharel
  • 412
  • 1
  • 8
  • 21
0

Very simple Session using this way:----

session sets:--

session_start();

$_SESSION['value'] = 'tested';

session gets :--

echo $_SESSION['value'];

output:--tested