not conecting to database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

not conecting to database

Post by gaogier »

how can i make something that will conect to mysql database?

when you sign up it seems like its connected but it dosent, then when you sign in it says "Name and password not found or not matched"

the code for "make.php"

Code: Select all

<?
$conn = mysql_connect(&quote;localhost&quote;,&quote;gaogier&quote;,&quote;*********&quote;);

$db = mysql_select_db(&quote;gaogier_javelincontrols&quote;);

$username = $_POST&#1111;&quote;username&quote;];
$password = $_POST&#1111;&quote;password&quote;];
$email = $_POST&#1111;&quote;email&quote;];

$result= MYSQL_QUERY(&quote;INSERT INTO users (id, username, password, email)&quote;.
   &quote;VALUES ('NULL', '$username', '$password', '$email')&quote;);
   
echo &quote;Your name and password have been submitted into our database :)&quote;;
?>
the code for "getin.php"

Code: Select all

<?
$conn = mysql_connect(&quote;localhost&quote;,&quote;gaogier&quote;,&quote;*******&quote;);
$db = mysql_select_db(&quote;gaogier_javelincontrols&quote;);

$username = $_POST&#1111;&quote;username&quote;];
$password = $_POST&#1111;&quote;password&quote;];

$result = MYSQL_QUERY(&quote;SELECT * from users WHERE username='$username'and password='$password'&quote;)
   or die (&quote;Name and password not found or not matched&quote;);

$worked = mysql_fetch_array($result);

$username = $worked&#1111;username];
$password = $worked&#1111;password];
$email = $worked&#1111;email];

if($worked)
   echo &quote;Welcome $user! Your e-mail address is $email&quote;; 
?>

what should i do to make it connect?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

do mysql_connect($stuff_here_whatever) or die(mysql_error());

well do the or die(mysql_error()) for mysql_connect, mysql_select_db, and mysql_query and you might get some better answers
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

thanks now works
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

how can i make it so that when they sign up it sends them an email saying what there pass and user is? and how can i make this go further? so people can see there info that nobody else can see?
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

instead, i need this to do something else first, i need this to make people who sign up can see info my using the same id how could i do this?
User avatar
farid
Forum Commoner
Posts: 54
Joined: Thu Nov 11, 2004 4:20 pm
Location: Mexico

Post by farid »

What I always do and it always works is:

Code: Select all

@$link_id = mysql_connect("IP", "USER", "PASSWORD") or die("Connection Failed");
// Make sure that the user has the priveleges necessary

$select_db = mysql_select_db("DATABASE",$link_id) or die("Connection Failed");

$variable=("SELECT phone FROM TABLE WHERE user='$USER' AND password='$PASSWORD'");
while ($query_data=mysql_fetch_array($variable)){

	echo $query_data["phone"];
}
Keep in mynd that $user and $password must have a certain value that you bring with $_POST or $_SESSION :D
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

on what page do i put this?
User avatar
farid
Forum Commoner
Posts: 54
Joined: Thu Nov 11, 2004 4:20 pm
Location: Mexico

Post by farid »

In the page where you want to obtain certain information of the table, according to the user and password to make any kind of validation, I put the phone there as an example with mysql_fetch_array. but you can use mysql_fetch_row, but in order to print it is different.

if you want to obtain more info you have to modify the query and the way you call the variables, that is:

Code: Select all

$variable=("SELECT phone,id FROM TABLE WHERE user='$USER' AND password='$PASSWORD'");
while ($query_data=mysql_fetch_array($variable)){
echo $phone=$query_data["phone"];
echo $id=$query_data["id"];
}
Post Reply