Sign up & SQL table problem - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Sign up & SQL table problem (/showthread.php?tid=50570)
Sign up & SQL table problem by zaher1988 on 09-16-2005 at 12:42 PM
Hey!
i'm working on a simple sign up form. that's consisted to 4 pages, 2 html and 2 php
signup.htm make.php login.htm getin.php
and using a server running PHP, mySQL, and phpMyAdmin. i have created a mySQL table which will store the user's name and password when they create it. and, logged on to phpMyAdmin, and select the database. My database is called "easyflas_testdb". Inside the database, i made a table, called it "users" and have 4 columns for it.
id - INT (auto increment, primary)
username - text
password - text
email - text
so i made the user and password, i setup the host and the database!. all are fine till now
and then i went ahead and start making my signup form which starts with the page signup.htm and has this code:
<form action="make.php" method="post">
Username Desired: <input type="text" name="username" size="10">
Password Desired: <input type="password" name="password" size="10">
E-mail: <input type="text" name="email" size="10">
<input type="submit" value="submit" name="submit">
</form>
then i started with my make.php page which will post the info to the SQL data base, make.php has this code:
<?
$conn = mysql_connect("localhost","MYUSER","PASSWORD");
$db = mysql_select_db("easyflas_testdb");
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$result= MYSQL_QUERY("INSERT INTO users (id, username, password, email)".
"VALUES ('NULL', '$username', '$password', '$email')");
echo "Your name and password have been submitted into our database ";
?>
ok done from this test it and no errors it says "Your name and password have been submitted into our database"
but these info are not submited into the TABLE! i checked it times and times, and still telling me that it was submited , but it's not actually.
now i tried anyway to signin using info i used in the signup page using this page login.htm which has this code:
<form action="getin.php" method="post">
Username: <input type="text" name="username" size="10">
Password: <input type="password" name="password" size="10">
<input type="submit" value="submit" name="submit">
</form>
and followed by the page getin.php which is :
<?
$conn = mysql_connect("localhost","MYUSER","PASSWORD");
$db = mysql_select_db("easyflas_testdb");
$username = $_POST["username"];
$password = $_POST["password"];
$result = MYSQL_QUERY("SELECT * from users WHERE username='$username'and password='$password'")
or die ("Name and password not found or not matched");
$worked = mysql_fetch_array($result);
$username = $worked[username];
$password = $worked[password];
$email = $worked[email];
if($worked)
echo "Welcome $user! Your e-mail address is $email";
?>
but it's telling"Name and password not found or not matched" me though i also tried to enter these info manually from inside the phpAdmin page! not using the form , so in both cases it's not working .
so please if anybody knows what may be happening i will be thankfull for him
thanks in advance
RE: Sign up & SQL table problem by WDZ on 09-16-2005 at 02:32 PM
Maybe you should add the "or die()" error handling to the mysql_connect() and mysql_select_db() lines as well as the mysql_query() in make.php. That should help you debug the scripts.
BTW, it looks like you have a typo in make.php...
$db = mysql_select_db("easyflas_testdp");
RE: Sign up & SQL table problem by zaher1988 on 09-16-2005 at 02:56 PM
quote: Originally posted by WDZ
BTW, it looks like you have a typo in make.php...
$db = mysql_select_db("easyflas_testdp");
no hehe it's just by mistake , on the server it's correct
RE: Sign up & SQL table problem by J-Thread on 09-16-2005 at 06:27 PM
code: $result=mysql_query("INSERT INTO users(`id`,`username`,`password`,`email`) VALUES ('', '" . $username . "', '" . $password . "', '" . $email . "')");
RE: Sign up & SQL table problem by zaher1988 on 09-16-2005 at 07:10 PM
Well i found the submited info in the table but they were like this
" . $username . " " . $password . " " . $email . "
RE: Sign up & SQL table problem by J-Thread on 09-16-2005 at 07:16 PM
Place:
code: error_reporting(E_ALL);
at the top of the scripts to see all the errors. And do:
code: print mysql_error();
After the query's to see the errors.
btw: there's missing a space after AND in your second query
RE: Sign up & SQL table problem by J-Thread on 09-16-2005 at 07:17 PM
That's strange...attach the php files here, i think you may have made a copy / paste error...
RE: Sign up & SQL table problem by zaher1988 on 09-16-2005 at 07:25 PM
Here's the files
RE: Sign up & SQL table problem by J-Thread on 09-17-2005 at 09:22 AM
I see 3 database names...
In your post you say it's easyflas_testdb, in the php files it's easyflas_spoonodb and spoono_db. Are you sure that's correct!
Besides that, you are making a lot of thinking mistakes. The first:
code: <?
error_reporting(E_ALL);
//replace username and password with your mysql name and password
$conn = mysql_connect("localhost","easyflas_zaher19","okk");
//select the database
$db = mysql_select_db("easyflas_spoonodb");
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
//insert the values
$result=mysql_query("INSERT INTO users(`id`,`username`,`password`,`email`) VALUES ('', '" . $username . "', '" . $password . "', '" . $email . "')");
if($result) {
echo "Your name and password have been submitted into our database ";
}
else {
echo "Error while inserting: " . mysql_error();
}
?>
The second:
code: <?
error_reporting(E_ALL);
$conn = mysql_connect("localhost","eastflas_zaher19","okk");
$db = mysql_select_db("spoono_db");
$username = $_POST["username"];
$password = $_POST["password"];
$result = mysql_query("SELECT * from users WHERE username='" . $username . "' ABD password='" . $password . "'")
or die ("Error in your query: " . mysql_error());
if(mysql_num_rows($result) > 0) {
$worked = mysql_fetch_array($result);
$username = $worked['username'];
$password = $worked['password'];
$email = $worked['email'];
echo "Welcome $user! Your e-mail address is $email";
}
else {
echo "No username / password match found!";
}
?>
And off course first look at the database names. This should work...
|