To all the PHP/MYSQL experts here

Congax

Fledgling Freddie
Joined
Aug 18, 2004
Messages
3,231
I need your help :(

Making memberlogin system and all that but I just can't seem to get it working. Anyone who can give me a clue on what I'm doing wrong?

Code:
 REGISTER.PHP

<?php
include "connect.php";
if (isset($_REQUEST["action"])){
	switch ($_REQUEST["action"])
	{
		case "AddUser":
                                      
 $sql_aanmelding = "INSERT INTO `members` (`naam`, `email`, `password`, `datum`) VALUES (' " . $_POST['naam'] . "', ' ". $_POST['email']. " ', ' ". $_POST['password']. " ', NOW()";
  $verzenden = mysql_query($sql_aanmelding);
  echo"Hello ".$_POST['naam'].", your application has been succesfully processed. You can now log in.";
                                     break;
                 }
}
?>

<form name="inloggen" action="register.php" method="post">
   <p>Name: 
     <input type="text" name="naam">
     E-mail: 
  <input type="text" name="email">
     Password: 
  <input type="password" name="password">
  <input type="hidden" name="action" value="AddUser">
   <input type="submit" name="submit" value="Submit">
   </p>
   </form>

Code:
 HOME.PHP 

<?php
include "login.php";
?>

Code:
 LOGIN.PHP

<?
include "connect.php";
    $sql = "SELECT * FROM `members` WHERE `email` = '".$_POST['email']."'"; //alle gebruikers met het ingevoerde e-mailadres ophalen
    $ophalen = mysql_query($sql) or die(mysql_error()); // query uitvoeren
    $aantal = mysql_num_rows($ophalen); // aantal records met verstuurd emailadres tellen
    if($aantal == 0){
        //blijkbaar komt het mailadres niet in de database voor!
        echo"<p>Error: No such email in the database</p>";
    }else{
        //mailadres staat in de database, we gaan verder!
        while($record = mysql_fetch_object($ophalen)){    
            $password_db = $record->password;
        }
        //password nu vergelijken met ingevoerd password
        if($password_db != $_GET['password']){
            echo"<p>Error: incorrect password</p>";
        }else{
        //email staat in database en password klopt, sessie starten!
            while($record = mysql_fetch_object($ophalen)){    
                $id = $record->id;}
			echo"<p>You've been succesfully logged in.</p>";
            //sessie opstarten
            $_SESSION['id-nummer'] = $id;

        }
    }

?>

 <form name="inloggen" method="post">

 <h2>Login</h2>
 <p>Email:<br /><input type="text" name="email" maxlength="40" /></p>
 <p>Password:<br /><input type="password" name="password" maxlength="20" /></p>
 <p><input name="cmdlogin" type="submit" id="cmdlogin" value="Login" />
 </p>
 </p>
 <p><input name="Register" type="button" onClick="document.location.href=('register.php')" value="register"></p>
</form>

Sorry about the dutch //comments but you can ignore them anyway. Any help would be wildly appreciated. Apologies for the long post/code etc
 

DocWolfe

Part of the furniture
Joined
Jan 3, 2005
Messages
2,855
what error are you getting? one thing I would do... do loads of echo statements to see what state the variables are in through out the various stages of the page.
 

Lamp

Gold Star Holder!!
Joined
Jan 16, 2005
Messages
23,347
Quite a big one evidently. He was trying to microwave a jacket potato
 

Congax

Fledgling Freddie
Joined
Aug 18, 2004
Messages
3,231
what error are you getting?
On the webserver, none. I'd wish I could test it with WAMP but unfortunately WAMP doesn't wanne function on my PC. :)()

I've noticed that my DB doesnt get updated - no matter how much I register, I won't be fucking added to the table Members. I'm guessing the problem is situated around the register.php then, seeing as the login cannot work without a valid user ofcourse.

Lamp said:
Quite a big one evidently. He was trying to microwave a jacket potato

wtf? :p
 

Jeremiah

Fledgling Freddie
Joined
Aug 10, 2004
Messages
1,131
I admit its been a while since I've done PHP, but are you actually commiting the new inserts to the database?
 

Congax

Fledgling Freddie
Joined
Aug 18, 2004
Messages
3,231
I admit its been a while since I've done PHP, but are you actually commiting the new inserts to the database?
Well no, I guess not. Database doesn't get updated. Table stays empty :(


(connect.php is properly configured in case someone was planning on asking :p)
 

DocWolfe

Part of the furniture
Joined
Jan 3, 2005
Messages
2,855
after this bit;

$sql_aanmelding = "INSERT INTO `members` (`naam`, `email`, `password`, `datum`) VALUES (' " . $_POST['naam'] . "', ' ". $_POST['email']. " ', ' ". $_POST['password']. " ', NOW()";


do echo($sql_aanmelding);

your SQL query string doesn't look right. I dont think you need the `. I would more likely do something like the following;

Code:
<?php
include "connect.php";

if($_GET['form'] == "filled")
{
  $name = $_POST['naam'];
  $email = $_POST['email'];
  $password = $_POST['password'];
  $date = date();

  $sql_aanmelding = "INSERT INTO members 
                            (naam, email, password, datum)
                            VALUES ('$name', '$email', '$password', '$date'");

  $verzenden = mysql_query($sql_aanmelding);

  echo("Hello $name, your application has been succesfully processed. You can now log in.");

}
?>

<form name="inloggen" action="register.php?form=filled" method="post">
   <p>Name: 
     <input type="text" name="naam">
     E-mail: 
  <input type="text" name="email">
     Password: 
  <input type="password" name="password">
   <input type="submit" name="submit" value="Submit">
   </p>
</form>
 

DocWolfe

Part of the furniture
Joined
Jan 3, 2005
Messages
2,855
Its been a while since I've done any php so forgive me if its not 100% correct :p You have to narrow down the problem... so if that doesn't work I would suggest starting even more simpler.

Code:
<?php
include "connect.php";

  $name = "DocWolfe";
  $email = "docwolfe@freddyshouse.com";
  $password = "pr0";
  $date = date();

  $sql_aanmelding = "INSERT INTO members 
                            (naam, email, password, datum)
                            VALUES ('$name', '$email', '$password', '$date'");

  $verzenden = mysql_query($sql_aanmelding);

  echo("Hello $name, your application has been succesfully processed. You can now log in.");

?>
 

Congax

Fledgling Freddie
Joined
Aug 18, 2004
Messages
3,231
Fucking ace Docwolfe, that seems to have done it! Table has an entry now so the login should be working and all.

(btw: "INSERT INTO members
(naam, email, password, datum)
VALUES ('$name', '$email', '$password', '$date'"); should've been '$date')"; ofcourse!)

Anywho, thanks. I'll make sure to bump this when I encounter more problems/have questions.

edit: I can't rep u :<
 

Naffets

Can't get enough of FH
Joined
Nov 25, 2004
Messages
1,913
Fucking ace Docwolfe, that seems to have done it! Table has an entry now so the login should be working and all.

(btw: "INSERT INTO members
(naam, email, password, datum)
VALUES ('$name', '$email', '$password', '$date'"); should've been '$date')"; ofcourse!)

Anywho, thanks. I'll make sure to bump this when I encounter more problems/have questions.

edit: I can't rep u :<


repped on your behalf, it was good advice :)
 

Congax

Fledgling Freddie
Joined
Aug 18, 2004
Messages
3,231
So, here I am with another pair of questions. (Just recently started with php/mysql so forgive my noobness :D)

Code:
 <?php
include "connect.php";

if($_GET['form'] == "filled")
{
  $name = $_POST['naam'];
  $email = $_POST['email'];
  $password = $_POST['password'];
  $date = date();

  $sql_aanmelding = "INSERT INTO members 
                            (naam, email, password, datum)
                            VALUES ('$name', '$email', '$password', '$date')";

  $verzenden = mysql_query($sql_aanmelding);

  echo("Hello $name, your application has been succesfully processed. You can now log in.");

}
?>

Somehow, the last line (echo("Hello etc ..) doesn't seem to appear after a succesful registration? Also, I was wondering if it possible to do a redirect to (for example) succesful.php after a succesful registration?
 

DocWolfe

Part of the furniture
Joined
Jan 3, 2005
Messages
2,855
Somehow, the last line (echo("Hello etc ..) doesn't seem to appear after a succesful registration? Also, I was wondering if it possible to do a redirect to (for example) succesful.php after a succesful registration?

You need to buy a book :p

Code:
$url = "http://www.google.co.uk";
header("Location: $url");
exit;

What value does $verzenden return? IIRC it should be true/false 1/0.

Try doing an if statement.

Code:
if ($verzeden)
{
  $url = "http://www.sucessful.com";
  header("Location: $url");
  exit;
}
else
{
  $url = "http://www.unsucessful.com";
  header("Location: $url");
  exit;
}
 

Users who are viewing this thread

Top Bottom