FreePgs.com Forum

FreePgs Related => Support Requests => Topic started by: Ries on April 21, 2006, 07:41:10 PM

Title: PHP Problem, Urgently Need Help!
Post by: Ries on April 21, 2006, 07:41:10 PM
On my index.php file i use the switch command so users can navagate to index.php?pg=register and ect. But recently it stopped working, I also tried using if ($pg == "register"){ which didn't work, whats wrong? Is anyone else having these problems
Title: Re: PHP
Post by: Guide on April 22, 2006, 03:36:40 PM
I use this kind of system without any problems...
Maybe you could put more of your code so we could see whether something is wrong.

Normally, with an URL of the form : index.php?pg=mypage :


if(isset($_GET['pg'])){
     $page = $_GET['pg'];}
else{
     $page = 'default_page';}

switch($page){
     case 'default_page':
     case 'mypage':
          $path = 'include/' . $page . '.php';
          break;
     default :
          $path = 'include/default_page.php';
          break;
}

include($path);


Something like that should work.
However, there are loads of possibilities... (For my site, I load all the texts from a database, and with a $lang variable added, so the code is a bit different)
Title: Re: PHP
Post by: Ries on April 26, 2006, 04:08:31 PM
well the problem is that the url changes but the page doesnt, here is the my code

<html>
      <head>
      <title>Red Winter :: Register</title>
      </head>

<style type='text/css'>
      input, textarea, select {
      color: black;
      background: #FFFFFF;
      border: solid CC0000 1px;
      }
      a {
      text-decoration: none;
      text-transform: none;
      color: black;
      font-family: verdana;
      font-size: 10px;
      }
      body {
      background: #FFFFFF;
      background-attachment: fixed;
      background-possition: center;
      font-family: verdana;
      color: black;
      font-size: 10px;
      }
      </style><center>
<?PHP
mysql_connect("localhost", "********", "********")or die(mysql_error());
mysql_select_db("gamedb");
$ref == $_GET['ref'];
       if(!isset($ref)){
                 echo "Here you can register for Red Winter<br />";
                 echo "<form action='register.php?action=add' method='post'>";
                 echo "email:<input type='text' name='remail' /><br />";
                 echo "user: <input type='text' name='ruser' /><br />";
                 echo "pass: <input type='password' name='rpass' /><br />";
                 echo "ref: <input type='text' name='rref' /><br /><br />";
                 echo "<input type='submit' value='Register' /></form>";
           }else{
                 echo "Here you can register for Red Winter<br />";
                 echo "<form action='register.php?action=add' method='post'>";
                 echo "email:<input type='text' name='remail' /><br />";
                 echo "user: <input type='text' name='ruser' /><br />";
                 echo "pass: <input type='password' name='rpass' /><br />";
                 echo "ref: $ref<br /><br />";
                 echo "<input type='submit' value='Register' /></form>";
}
if ($action == "add"){
       $_POST['remail'] == $remail;
       $_POST['ruser'] == $ruser;
       $_POST['rpass'] == $rpass;
 
       $remch  = mysql_query("SELECT * FROM members WHERE `email`='$remail' ")or die(mysql_error());
              if (mysql_num_rows($remch) > 0) {
                      $rerror == 1;
                      echo "Sorry, that email address is already in use<br />";
               }
       $rusch = mysql_query("SELECT * FROM members WHERE `user`='$ruser' ")or die(mysql_error());
               if (mysql_num_rows($rusch) > 0) {
                      $rerror == 1;
                      echo "Sorry, that username is already in use<br />";
               }
if ($rerror != "1"){
        mysql_query("INSERT INTO members ('user', 'pass', 'email') VALUES ('$ruser', '$rpass', '$remail') ")or die(mysql_error());
        echo "Well Done! You can now login!<br />";
}else{
        echo "<font color='red'>There was a error, check the error messages above and try again<br />";
     }
   }
?>


What happens is it shows the register but asking for the details which is fine but when you click submit the URL in my browser changes but whats displayed on the page stays the same. Please can someone help it's really confusing me :(
Title: Re: PHP Problem, Urgently Need Help!
Post by: GP™ on April 26, 2006, 10:04:11 PM
$ref == $_GET['ref'];
should be
$ref = $_GET['ref'];
Title: Re: PHP Problem, Urgently Need Help!
Post by: Ries on April 27, 2006, 04:09:31 PM
Thanks that fixed the Refferal Problem but not the main problem, I can't really explain whats going on check out http://www.icewire.org/register.php
To see my problem try and register and see what happens the page doesn't change.
Title: Re: PHP Problem, Urgently Need Help!
Post by: Guide on April 27, 2006, 07:39:59 PM
You did the same mistake with the POST variables :

$_POST['remail'] == $remail;
$_POST['ruser'] == $ruser;
$_POST['rpass'] == $rpass;

Should rather be :

$remail = $_POST['remail'];
$ruser = $_POST['ruser'];
$rpass = $_POST['rpass'];

"==" means "is equal to", and the expression "$a == $b" returns either TRUE or FALSE.
To assign value x to variable $a, you must use the "=" sign : "$a = b"