Question regarding mysql

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
Termina
Forum Newbie
Posts: 18
Joined: Sat Apr 10, 2004 11:17 pm

Question regarding mysql

Post 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"
?>
Sander
Forum Commoner
Posts: 38
Joined: Sat Aug 06, 2005 12:43 pm

Re: Question regarding mysql

Post 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.
Termina
Forum Newbie
Posts: 18
Joined: Sat Apr 10, 2004 11:17 pm

Post by Termina »

Thanks, everything is working now. =)
Post Reply