You are viewing our Forum Archives. To view or take place in current topics click here.
Need help with sql database in php
Posted:

Need help with sql database in phpPosted:

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
Hey guys,

For school I need to make a website and it has to include a sql database.
We also need to use php for that

So...
I need to make a login field and a account creator on the site but how can i do that with that database?
I need to refer to that database in the php file

Which code do i need?
I already have a sql database


Last edited by Cax ; edited 1 time in total
#2. Posted:
Vivi
  • TTG Addict
Status: Offline
Joined: Jun 26, 201112Year Member
Posts: 2,581
Reputation Power: 131
Status: Offline
Joined: Jun 26, 201112Year Member
Posts: 2,581
Reputation Power: 131
should be
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
?>
#3. 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
Grin wrote should be
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
?>


Thanks man!
I will test it
#4. 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
i also need a code to make accounts on the site that will be displayed in the database

Which code do i need>?
#5. Posted:
Vivi
  • TTG Addict
Status: Offline
Joined: Jun 26, 201112Year Member
Posts: 2,581
Reputation Power: 131
Status: Offline
Joined: Jun 26, 201112Year Member
Posts: 2,581
Reputation Power: 131
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)
?>
#6. 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
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
#7. Posted:
7en
  • Wise One
Status: Offline
Joined: Aug 16, 201211Year Member
Posts: 598
Reputation Power: 29
Status: Offline
Joined: Aug 16, 201211Year Member
Posts: 598
Reputation Power: 29
Grim, let him do his own homework, he'll learn nothing otherwise.
#8. Posted:
Vivi
  • TTG Addict
Status: Offline
Joined: Jun 26, 201112Year Member
Posts: 2,581
Reputation Power: 131
Status: Offline
Joined: Jun 26, 201112Year Member
Posts: 2,581
Reputation Power: 131
Abbreviate wrote Grim, let him do his own homework, he'll learn nothing otherwise.
:[ but a little assistance never hurt anyone
#9. 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
Abbreviate wrote Grim, let him do his own homework, he'll learn nothing otherwise.


If i got the codes i could see what the code is for a command.
I can learn from this codes he gave me
#10. 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
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.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.