Jump to content

help


affordit

Recommended Posts

Does anyone know whats wrong with this I am getting a blank page

 

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$query = "Select name, email from test Where name = '$name' OR email = '$email'";

$results = mysql_query($query) or die(mysql_error()."<br /><br />".$query);

$num=mysql_numrows($results);

if ($_POST['name'] = ($results['name'])); {

print "Name exists";

 

}elseif{

 

($_POST['email'] = ($results['email'])); {

print "Email exists";

exit();

}

else{

 

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$query = "INSERT INTO `test` (`id`, `company`, `name`, `address`, `city`, `state`, `zip`, `phone`, `acct_num`, `email`, `start_date`, `end_date`, `remind_date`, `lost_password`, `lost_password_answer`) VALUES (' ','$company','$name','$address','$city','$state','$zip','$phone','$acct_num','$email','$start_date','$end_date','$remind_date','$lost_password','$lost_password_answer')";

mysql_query($query) or die ("<table align='center' width='300'><td align='center'><tr><b>Email exists</b></td></tr></table>");

 

#  if the user submitted a password

if( isset($psword) )

{

  #  get the user id 

  $id = mysql_insert_id( );

 

  #  and insert the login details

  $query = "INSERT INTO login VALUES ('','$name','$psword','$email','$lost_password_answer','$end_date','$valid')";

  mysql_query($query) or die ("The username you entered already exists, please choose another");

 

$to = "$email";

$subject = "Your Registration";

$message="Thank You for registering with us $name your password is $psword.";

$headers = "From: webmaster@us@here.com";

$sent = mail($to, $subject, $message, $headers) ;

if($sent)

{print "<br><table align='center' width='300'><td align='center'><tr><b>Your information has been saved and we have sent you an mail to $email with your password. To activate your account just login with your username $name and the password included in the Email.</b></td></tr></table>";

print "<table align='center' width='300'><td align='center'><tr><b><font color='#FF6600'>Your registration begins

$start_date2<br>and will expire on $end_date2.<br>The first time you log in<a href ='first_login.php'>Do it here</a></b></td></tr></table>";

}

else

{print "We encountered an error sending your mail"; }

 

}

  }

mysql_free_result( $result );

mysql_close();

?>

 

 

 

 

 

Link to comment
Share on other sites

You should try indenting your code differently, you would see the problem instantly. It lies here:

 

if ($_POST['name'] = ($results['name'])); {
print "Name exists";

}elseif{

($_POST['email'] = ($results['email'])); {
print "Email exists";
exit();
}
else{

 

Lets indent that code differently:

 

if ($_POST['name'] = ($results['name']));
{
    print "Name exists";
}
elseif
{
    ($_POST['email'] = ($results['email']));
    {
        print "Email exists";
        exit();
    }
    else
    {

 

You didn't give any condition for your 'elseif' statement, which means that it always enters that. Then for the condition you did give, you used ($_POST['email'] = $results['email']). This (attempts) to assign the value of $results['email'] to $_POST['email'] (and fails, as this is not possible) rather than checking for equality. Use two equals signs to check for equality, not one.

Link to comment
Share on other sites

OK added the ++ but still got a blank page so I took out the ; after each IF statement and goty these errors

 

Notice: Use of undefined constant mysql - assumed 'mysql' in /sharon/submit_registration.php on line 72

 

Notice: Undefined variable: acct_num in /sharon/submit_registration.php on line 94

 

Notice: Undefined variable: remind_date in /sharon/submit_registration.php on line 94

 

Email exists

 

Link to comment
Share on other sites

OK I meant == not ++ But now I got no errors but when I put in an email and Username that I know both exist in one of the records it goes past the if name part and goes right to Email exists.

 

Here is the updated code

 

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$query = "Select * from test Where name = '$name' OR email = '$email'";

$results = mysql_query($query) or die(mysql_error()."<br /><br />".$query);

$num=mysql_numrows($results);

if ($_POST['name'] == ($results['name'])) //<--Here

{

    print "Name exists";

exit();

}

elseif ($_POST['email'] == ($results['email'])) //<-- and Here

{

    print "Email exists";

exit();

}

else

{

Link to comment
Share on other sites

You need to use mysql_fetch_assoc in order to get the info from the DB.

 

Also, this line is wrong

 

$num=mysql_numrows($results);

 

should be

 

$num=mysql_num_rows($results);

 

But you are not even checking $num so it's not doing anything.

 

Link to comment
Share on other sites

They are set on a form. What it is is a registration form but when a new person registers I want to insure that the username  and email are not duplicated in the login or clients tables.

 

What happens is I insert into the clients table all the information and then insert into the login table the login info. The username and email are set to unique in the tables.

Link to comment
Share on other sites

If they are sent via a form using the POST method then the variables will be within the $_POSTarray, they don't just magically appear.

 

What it is is a registration form but when a new person registers I want to insure that the username  and email are not duplicated in the login or clients tables.

 

Then your code ought to be....

 

<?php

 // connect to database

 if (isset($_POST['submit'])) {
   
   $name = mysql_real_escape_string($_POST['name']);
   $email = mysql_real_escape_string($_POST['email']);
   
   $sql = "SELECT name FROM test WHERE name = '$name' || email = '$email'";
   if ($result = mysql_query($sql)) {
     if (mysql_num_rows($result)) {
       echo "username or email already in use";
     } else {
       // do registration
     }
   }
 }

?>

Link to comment
Share on other sites

I have no prob geting them to insert with this part of the code:

 

$query = "INSERT INTO `test` (`id`, `company`, `name`, `address`, `city`, `state`, `zip`, `phone`, `acct_num`, `email`, `start_date`, `end_date`, `remind_date`, `lost_password`, `lost_password_answer`) VALUES (' ','$company','$name','$address','$city','$state','$zip','$phone','$acct_num','$email','$start_date','$end_date','$remind_date','$lost_password','$lost_password_answer')";

mysql_query($query) or die ("<table align='center' width='300'><td align='center'><tr><b>Email exists</b></td></tr></table>");

 

#  if the user submitted a password

if( isset($psword) )

{

 #  get the user id  

 $id = mysql_insert_id( );

 

 #  and insert the login details

 $query = "INSERT INTO login VALUES ('','$name','$psword','$email','$lost_password_answer','$end_date','$valid')";

 mysql_query($query) or die ("The username you entered already exists, please choose another");

 

$to = "$email";

$subject = "Your Registration";

$message="Thank You for registering with us $name your password is $psword. You must go to affordit.us/sharon/first_login.php to log in so that your Email will be verified. Then you will be able to login on the normal login page. Thank you again and if you have any questions or concerns please feel free to contact us through our contact page. Patrick St. Charles Affordable Everything";

$headers = "From: webmaster@affordit.us";

$sent = mail($to, $subject, $message, $headers) ;

if($sent)

{print "<br><table align='center' width='300'><td align='center'><tr><b>Your information has been saved and we have sent you an mail to $email with your password. To activate your account just login with your username $name and the password included in the Email.</b></td></tr></table>";

print "<table align='center' width='300'><td align='center'><tr><b><font color='#FF6600'>Your registration begins

$start_date2<br>and will expire on $end_date2.<br>The first time you log in<a href ='first_login.php'>Do it here</a></b></td></tr></table>";

}

else

{print "We encountered an error sending your mail"; }

 

}

 }

mysql_free_result( $result );

mysql_close();

?>

 

That part works fine but when I try to add this to the top of the page:

 

include("sharons_dbinfo.inc.php");

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$query = "Select * from test Where name = '$name' OR email = '$email'";

$results = mysql_query($query) or die(mysql_error()."<br /><br />".$query);

$num=mysql_numrows($results);

if ($_POST['name'] == ($results['name'])) //<--Here

{

   print "Name exists";

exit();

}

elseif ($_POST['email'] == ($results['email'])) //<-- and Here

{

    print "Email exists";

exit();

}

else

{

 

and enter values I know exist into the form it skips over the part where it checks the name and displays the resuut from the email check "EMAIL EXISTS" I don't get it.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.