Page 1 of 1

not conecting to database

Posted: Thu Jul 28, 2005 4:04 pm
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?

Posted: Thu Jul 28, 2005 4:24 pm
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

Posted: Thu Jul 28, 2005 4:25 pm
by gaogier
thanks now works

Posted: Thu Jul 28, 2005 4:30 pm
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?

Posted: Thu Jul 28, 2005 4:39 pm
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?

Posted: Thu Jul 28, 2005 4:58 pm
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

Posted: Thu Jul 28, 2005 5:10 pm
by gaogier
on what page do i put this?

Posted: Thu Jul 28, 2005 5:26 pm
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"];
}