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:
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
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:
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
should be
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
?>
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
?>
- 0useful
- 0not useful
#3. Posted:
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
- 0useful
- 0not useful
#4. Posted:
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>?
Which code do i need>?
- 0useful
- 0not useful
#5. Posted:
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
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)
?>
- 0useful
- 0not useful
#6. Posted:
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
- 0useful
- 0not useful
#7. Posted:
Status: Offline
Joined: Aug 16, 201212Year Member
Posts: 598
Reputation Power: 29
Grim, let him do his own homework, he'll learn nothing otherwise.
- 1useful
- 0not useful
#8. Posted:
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
Abbreviate wrote Grim, let him do his own homework, he'll learn nothing otherwise.:[ but a little assistance never hurt anyone
- 1useful
- 0not useful
#9. Posted:
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
- 0useful
- 0not useful
#10. Posted:
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Qual wroteGrin 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.
- 1useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.