You are viewing our Forum Archives. To view or take place in current topics click here.
#11. Posted:
Vivi
  • TTG Addict
Status: Offline
Joined: Jun 26, 201113Year Member
Posts: 2,581
Reputation Power: 131
Status: Offline
Joined: Jun 26, 201113Year Member
Posts: 2,581
Reputation Power: 131
iyop45 wrote
Qual wrote
Grin wrote Of course whatever you don't want to be registered ex: if you don't want emails or sex remove ,'$_POST[email]','$_POST[sex]

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Website", $con);

$sql="INSERT INTO users (firstname, lastname, username, password, birthdate, email, sex)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[username]','$_POST[password]','$_POST[birthdate]','$_POST[email]','$_POST[sex]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your account has been created!";

mysql_close($con)
?>


THANK YOU!!!!
Im gonna rep you as much as i can
You have helped me alot

That whole approach to connecting to and querying a mysql database has been pretty much obsolete for the past couple of years and I'm almost certain the most recent php versions have officially declared it deprecated.

I'm not flaming for your assistance or "help" but frankly you're explaining how to use an extension which is widely frowned upon. Qual: you should look at the mysqli or PDO extensions as they're the only ones available in the latest php versions.
I won't argue about it rather because last time I've used PHP and SQL was in about 2009 so if you could be more of assistance feel free I don't keep too informed when things like this change
#12. Posted:
iyop45
  • Prospect
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Grin wrote
iyop45 wrote
Qual wrote
Grin wrote Of course whatever you don't want to be registered ex: if you don't want emails or sex remove ,'$_POST[email]','$_POST[sex]

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Website", $con);

$sql="INSERT INTO users (firstname, lastname, username, password, birthdate, email, sex)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[username]','$_POST[password]','$_POST[birthdate]','$_POST[email]','$_POST[sex]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your account has been created!";

mysql_close($con)
?>


THANK YOU!!!!
Im gonna rep you as much as i can
You have helped me alot

That whole approach to connecting to and querying a mysql database has been pretty much obsolete for the past couple of years and I'm almost certain the most recent php versions have officially declared it deprecated.

I'm not flaming for your assistance or "help" but frankly you're explaining how to use an extension which is widely frowned upon. Qual: you should look at the mysqli or PDO extensions as they're the only ones available in the latest php versions.
I won't argue about it rather because last time I've used PHP and SQL was in about 2009 so if you could be more of assistance feel free I don't keep too informed when things like this change

Along these lines:

define("HOST", "localhost");
define("USER", "username");
define("PASSWORD", "password");
define("DATABASE", "db"); //

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if (mysqli_connect_errno()) {
    printf("DB error: %s", mysqli_connect_error());
    exit();
}
$salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
$password = hash('sha512', $_POST['password'].$salt);
if($stmt = $mysqli->prepare(INSERT INTO `users` (`firstname`, `lastname`, `username`, `password`, `salt`) VALUES(?,?,?,?,?)){
     $stmt->bind_param('sssss',$_POST['fname'],$_POST['lname'],$_POST['username'],$password,$salt);
     $stmt->execute();
     $stmt->close();
}else{
     die('failed to prepare query');
}


The login would just perform a select on the username and compare the hashed input password with the hashed password on the database. Though Qual, I'm not going to spoon feed you .
http:/ /lmgtfy . com/?q=php+login+script

I'm not being rude qual but you should have the decency to google this yourself instead of expecting someone else to do it for you. This question has been answered countless times on the web.
#13. Posted:
Cax
  • Wise One
Status: Offline
Joined: Apr 25, 201212Year Member
Posts: 546
Reputation Power: 22
Status: Offline
Joined: Apr 25, 201212Year Member
Posts: 546
Reputation Power: 22
iyop45 wrote
Grin wrote
iyop45 wrote
Qual wrote
Grin wrote Of course whatever you don't want to be registered ex: if you don't want emails or sex remove ,'$_POST[email]','$_POST[sex]

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Website", $con);

$sql="INSERT INTO users (firstname, lastname, username, password, birthdate, email, sex)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[username]','$_POST[password]','$_POST[birthdate]','$_POST[email]','$_POST[sex]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your account has been created!";

mysql_close($con)
?>


THANK YOU!!!!
Im gonna rep you as much as i can
You have helped me alot

That whole approach to connecting to and querying a mysql database has been pretty much obsolete for the past couple of years and I'm almost certain the most recent php versions have officially declared it deprecated.

I'm not flaming for your assistance or "help" but frankly you're explaining how to use an extension which is widely frowned upon. Qual: you should look at the mysqli or PDO extensions as they're the only ones available in the latest php versions.
I won't argue about it rather because last time I've used PHP and SQL was in about 2009 so if you could be more of assistance feel free I don't keep too informed when things like this change

Along these lines:

define("HOST", "localhost");
define("USER", "username");
define("PASSWORD", "password");
define("DATABASE", "db"); //

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if (mysqli_connect_errno()) {
    printf("DB error: %s", mysqli_connect_error());
    exit();
}
$salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
$password = hash('sha512', $_POST['password'].$salt);
if($stmt = $mysqli->prepare(INSERT INTO `users` (`firstname`, `lastname`, `username`, `password`, `salt`) VALUES(?,?,?,?,?)){
     $stmt->bind_param('sssss',$_POST['fname'],$_POST['lname'],$_POST['username'],$password,$salt);
     $stmt->execute();
     $stmt->close();
}else{
     die('failed to prepare query');
}


The login would just perform a select on the username and compare the hashed input password with the hashed password on the database. Though Qual, I'm not going to spoon feed you .
http:/ /lmgtfy . com/?q=php+login+script

I'm not being rude qual but you should have the decency to google this yourself instead of expecting someone else to do it for you. This question has been answered countless times on the web.


Yes i know you're right...
But i didnt know how to search that because every code i had didnt work for me
#14. Posted:
GazerCinema
  • Challenger
Status: Offline
Joined: Feb 20, 201212Year Member
Posts: 102
Reputation Power: 3
Status: Offline
Joined: Feb 20, 201212Year Member
Posts: 102
Reputation Power: 3
Grin wrote Of course whatever you don't want to be registered ex: if you don't want emails or sex remove ,'$_POST[email]','$_POST[sex]

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Website", $con);

$sql="INSERT INTO users (firstname, lastname, username, password, birthdate, email, sex)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[username]','$_POST[password]','$_POST[birthdate]','$_POST[email]','$_POST[sex]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your account has been created!";

mysql_close($con)
?>


Note: this code is good for beginners but its very bad code. It is insanely vulnerable and mysql is now deprecated so if you're going to learn mysql I suggest you stop everything and learn Sqli/PDO. Learning mysql is setting yourself up for disaster.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.