A
AndyBlack
- Original Poster
- #1
Hi,
I'm new to php and am a bit stuck on the following. The first mysql query works fine, but the second query just returns 'Error updating database'.
So I am guessing it cannot execute the mysql command. I have used the same mysql statement on other scripts/pages and it works fine. I assume that I only have to connect to the database once.
<?php
$email=$_POST['email'];
$password=$_POST['password'];
$count = 0;
mysql_connect('localhost', 'myusername', 'mypassword') or die ('Error: '.mysql_error());
mysql_select_db('mydatabase');
# Check to see if email address already exists
$query = mysql_query("SELECT * FROM members WHERE email LIKE '$email'");
while ($row = mysql_fetch_array($query)) {
$count++;}
echo $count;
if ($count = 0) {echo "Sorry! The email address you entered already exists in our database."; break;} else {
$addemail="INSERT INTO members (ID, email, password) VALUES ('NULL', '".$email."', '".$password."')";
mysql_query($addemail) or die ('Error updating database');
echo '<meta http-equiv="refresh" content="4; url=index.php">';
echo "Your account has been created! Please wait while we redirect you.";}
?>
Any help would be greatly appreciated.
Thanks!
Andy
I'm new to php and am a bit stuck on the following. The first mysql query works fine, but the second query just returns 'Error updating database'.
So I am guessing it cannot execute the mysql command. I have used the same mysql statement on other scripts/pages and it works fine. I assume that I only have to connect to the database once.
<?php
$email=$_POST['email'];
$password=$_POST['password'];
$count = 0;
mysql_connect('localhost', 'myusername', 'mypassword') or die ('Error: '.mysql_error());
mysql_select_db('mydatabase');
# Check to see if email address already exists
$query = mysql_query("SELECT * FROM members WHERE email LIKE '$email'");
while ($row = mysql_fetch_array($query)) {
$count++;}
echo $count;
if ($count = 0) {echo "Sorry! The email address you entered already exists in our database."; break;} else {
$addemail="INSERT INTO members (ID, email, password) VALUES ('NULL', '".$email."', '".$password."')";
mysql_query($addemail) or die ('Error updating database');
echo '<meta http-equiv="refresh" content="4; url=index.php">';
echo "Your account has been created! Please wait while we redirect you.";}
?>
Any help would be greatly appreciated.
Thanks!
Andy