Jump to content

[SOLVED] Register/Login Script


whiteboikyle

Recommended Posts

Okay well i have a register form setup.. and i have a process.php setup as well..

Well when it goes to process it fails in the isset.

 

Register.php

<?php 
include("header.inc");
?>
<form method="POST" action="process.php">
<div align="center">
  <table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="154" style="border-width: 1px; border-style:solid; border-color:#000000"><div align="right">Username:</div></td>
      <td width="146" style="border-width: 1px; border-style:solid; border-color:#000000"><input type="text" name="username" /></td>
    </tr>
    <tr>
      <td style="border-width: 1px; border-style:solid; border-color:#000000"><div align="right">Password:</div></td>
      <td style="border-width: 1px; border-style:solid; border-color:#000000"><input type="text" name="password" /></td>
    </tr>
    <tr>
      <td style="border-width: 1px; border-style:solid; border-color:#000000"><div align="right">Email:</div></td>
      <td style="border-width: 1px; border-style:solid; border-color:#000000"><input type="text" name="email" /></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
  	<input type="hidden" name"register" value="1">
        <input type="submit" name="Submit" value="Submit" />
        <input type="reset" name="reset" value="Reset" />
      </div></td>
    </tr>
  </table>
</div>
</form>
<?php 
include("footer.inc");
?>

 

Process.php

<?php
require("include/constants.php");
class Process
{

function Process(){

	if(isset($_POST['register'])) {
    	$this->register();
     	}
	else {
	header("Location: main.php");
	}
}

function register(){
	$username = $_POST["username"];
	$password = $_POST["password"];
	$email = $_POST["email"];
	$query = "INSERT INTO members (ID, username, password, email) VALUES (NULL, '$username', '$password', '$email')";
	mysql_query($query, @mysql_connect(DB_SERVER, DB_USER, DB_PASS)) or die(mysql_error());
	echo("<center><font size='4'><font color='red'>Post has been submitted! Will redirect in 2 seconds</center></font>");
	echo("<META HTTP-EQUIV='refresh' CONTENT='2;news.php'>");
}
};

$process = new Process;
?>

 

When it submits it goes to Main.php instead of going to news.php like i wanted it to.

Link to comment
Share on other sites

isset() return true and false (1 or 0)

isset check both if and else condition

 

I Think

becouse you have given 2 second to redirect the page and else section excuted before thats why it gose to  main.php

for better result u use if then else condition

Link to comment
Share on other sites

<input type="hidden" name"register" value="1">

 

You are missing the = for the name parameter, which would not let that value show up in the $_POST array

 

<input type="hidden" name="register" value="1">

 

That should work

Link to comment
Share on other sites

First of all, add error_reporting(E_ALL); to the top of your script so you can find out where the actual problem lies. Secondly, you don't need the hidden field. You can check if the POST data is set on the submit button. Use some indication about whether it was successful or not rather than executing some more code, or re-directing. You forgot the '=' on the name parameter also.

 

EDIT: Sorry, eldorik got there before me.

 

<?php
class MyClass {
  function MyClass() {

    if(isset($_POST['submit']))
      print 'Successful';
    else
      print 'Failed';

  }
}

$class = new MyClass(); // Note the parenthesis.
?>

Link to comment
Share on other sites

First of all, add error_reporting(E_ALL); to the top of your script so you can find out where the actual problem lies. Secondly, you don't need the hidden field. You can check if the POST data is set on the submit button. Use some indication about whether it was successful or not rather than executing some more code, or re-directing. You forgot the '=' on the name parameter also.

 

EDIT: Sorry, eldorik got there before me.

 

<?php
class MyClass {
  function MyClass() {

    if(isset($_POST['submit']))
      print 'Successful';
    else
      print 'Failed';

  }
}

$class = new MyClass(); // Note the parenthesis.
?>

 

i am using process.php for more then just 1 submit... so that is why i will be using the Hidden Variable

Link to comment
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.