Page 1 of 1

Question regarding mysql

Posted: Wed Aug 31, 2005 1:25 pm
by Termina
I would like my PHP script try to grab the username/pass (based on users input) from a mysql database.

If it returns something (ie, their username/pass is there), I would then like another query to replace (based on users input) the password field.

So far, I am able to display (on the users screen) their username/pass (if they get it right in the HTML file, otherwise it displays nothing)

I have no idea how to see if a query returns null though. :/

Here's my script, can you help me?

Code: Select all

<form action="account.php" method="post">
Name: <input type="text" name="name"><br>
Domain: <select name="domain" size=1>
<option value="necropile.com">Necropile.com
<option value="sociopathological.org">Sociopathological.org
<option value="botchedvirus.com">BotchedVirus.com
<option value="binaryslaughter.com">BinarySlaughter.com
</select><br>
Password: <input type="password" name="password"><br>
New Password: <input type="password" name="newpass"><br>
<input type="Submit">
</form>

Code: Select all

<?
$link = mysql_connect("localhost", "username", "password")
               or die("Could not connect to database");
$name=$_POST['name'];
$domain=$_POST['domain'];
$password=$_POST['password'];
$newpass=$_POST['newpass'];
@mysql_select_db(provider, $link) or die( "Unable to select database");
$email = "$name@$domain";
$query="SELECT * FROM users WHERE email='$email' and  password='$password'";
//$query2="INSERT INTO users VALUES ($email, $newpass)";
$result = mysql_query($query) or die("Wrong password.");
echo "<table border=1>\n";
echo "<tr><td>email</td><td>password</tr>\n";
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s</td><td>%s</td></tr>\n", $myrow[0], $myrow[1]);
}
echo "</table>\n"
?>

Re: Question regarding mysql

Posted: Wed Aug 31, 2005 1:48 pm
by Sander
Termina wrote:I have no idea how to see if a query returns null though. :/
You can do that like this:

Code: Select all

if(!mysql_num_rows($query))
That basically counts the rows returned by the query. If no user exists with that email account, no rows are returned.

Posted: Wed Aug 31, 2005 2:54 pm
by Termina
Thanks, everything is working now. =)