zonobuzz12
New Member
- Messages
- 6
- Reaction score
- 0
- Points
- 0
I am getting trouble on connection of PHP to MYSQL.
I want to put Firstname, Lastname and Age into the Database.
I am using the following php code for connection and for inserting values .. :--
<?php
$con = mysql_connect("localhost","ultimo99_test","equal to my password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
In the second line there are three fields .. :--
localhost : what should i replace to localhost ??
ultimo99_test : it is a user of my database (ultimo99_store)
password : equal to my password and the password of the user ultimo99_test
After doing this code after when I submit the form, it says Database not selected, please correct my code and my database is " ultimo99_store "..
Thanks in advance for helping and for reading...
I want to put Firstname, Lastname and Age into the Database.
I am using the following php code for connection and for inserting values .. :--
<?php
$con = mysql_connect("localhost","ultimo99_test","equal to my password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
In the second line there are three fields .. :--
localhost : what should i replace to localhost ??
ultimo99_test : it is a user of my database (ultimo99_store)
password : equal to my password and the password of the user ultimo99_test
After doing this code after when I submit the form, it says Database not selected, please correct my code and my database is " ultimo99_store "..
Thanks in advance for helping and for reading...