Jump to content

PHP/SQL Registration


davidknag

Recommended Posts

Could Anyone tell me what's wrong with this besides the fact that it is not connect to any database?

it does not do anything when i click the button.

 

<?php
if ($_GET['register'] == 'true') {
   registerUser();
	}
function registerUser() {
   mysql_connect('server', 'username', 'password', 'database');
   $username = $_POST['username'];
   $password = md5($_POST['password']);

   $sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES ($username, $password, $email, 0, 24);";

   mysql_query($sql);
}
?>

<div class="form">
       <form action="<?php $_SERVER['PHP_SELF']."?register=true" ?>" method="post">
           Username: <input type="text" name="username">
	<br></br>
	<br></br>
           Email: <input type="text" name="email">
	<br></br>
	<br></br>
           Password: <input type="password" name="password">
	<br></br>
	<br></br>
           <input type="submit" value="Register!">
       </form>

 

thanks if you can help :)

Link to comment
https://forums.phpfreaks.com/topic/208364-phpsql-registration/
Share on other sites

String values need to be surrounded by quotes

 

So, it should be:

 

$sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES ('$username', '$password', '$email', 0, 24);";

 

or, doing it your way:

 

$sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES ('" .$username . "','" . $password . "','" . $email . "', 0, 24');";

Link to comment
https://forums.phpfreaks.com/topic/208364-phpsql-registration/#findComment-1088936
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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