Jump to content

Script doesnt work * solved


Drezard

Recommended Posts

Hey, Whats wrong with this script. Ive been trying to work out whats wrong for almost 3 hours.

Heres my script:

[CODE]
<html>
<head>
<?php
include('header.php');
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if (!isset($_POST['submit'])) { // if the form has not been submitted before
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    Name(s): <input type="text" name="name"> <br>
    Email: <input type="text" name="email1">
    @<input type="text" name="email2">
  Daytime Phone Number:<input type="text" name="daytime"> <br>
    Nighttime Phone Number:<input type="text" name="nighttime"> <br>
Mobile Number:<input type="text" name="mobile"> <hr>
    Street Number:<input type="text" name="streetnum">
    Street Name: <input type="text" name="streetname"> <br>
    Suburb: <input type="text" name="suburb">
    State: <input type="text" name="state">
    Postcode: <input type="text" name="postcode"> <br>
    Asking Price: <input type="text" name="askprice">
    Bedrooms: <input type="text" name="bedrooms">
    Bathrooms: <input type="text" name="bathrooms"> <hr> 
Desired Username: <input type ="text" name="user"> <br>
Password: <input type="password" name="pass1">
Retype Password: <input type="password" name="pass2">                                 
    <input type="submit" name="submit">
</form>

          <?php
}
else {

$pass1 = empty($_POST['pass1']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass1']);
$pass2 = empty($_POST['pass2']) ? die ("Please Retype Your Password") : mysql_escape_string($_POST['pass2']);
$user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']);
$sql = "SELECT * FROM users WHERE user='$user'";
    $result = mysql_query($sql);

  // Mysql_num_row is counting table ro
$count=mysql_num_rows($result);

  // If result matched $user and $pass, table row must be 1 row

if($count==1){

echo "Username already exists";

}
else {

if ( $pass1 == $pass2 ) {

include('connect.php');
$expire = strtotime('next month',$date); // Start a connection to the MySQL Database
  $name = empty($_POST['name']) ? die ("Please Enter Your Name") : mysql_escape_string($_POST['name']);
$email1 = empty($_POST['email1']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email1']);
    $email2 = empty($_POST['email2']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email2']);
    $daytime = empty($_POST['daytime']) ? die ("Please Enter Your Daytime Phone Number") : mysql_escape_string($_POST['daytime']);
    $nighttime = empty($_POST['nighttime']) ? die ("Please Enter Your Nighttime Phone Number") : mysql_escape_string($_POST['nighttime']);
    $mobile = empty($_POST['mobile']) ? die ("Please Enter Your Mobile Number") : mysql_escape_string($_POST['mobile']);
$streetnum = empty($_POST['streetnum']) ? die ("Please Enter Your Streetnumber") : mysql_escape_string($_POST['streetnum']);
$streetname = empty($_POST['streetname']) ? die ("Please Enter Your Streetname") : mysql_escape_string($_POST['streetname']);
$suburb = empty($_POST['suburb']) ? die ("Please Enter Your Suburb") : mysql_escape_string($_POST['suburb']);
$state = empty($_POST['state']) ? die ("Please Enter Your State") : mysql_escape_string($_POST['state']);
$postcode = empty($_POST['postcode']) ? die ("Please Enter Your Postcode") : mysql_escape_string($_POST['postcode']);
$askprice = empty($_POST['askprice']) ? die ("Please Enter Your Asking Price") : mysql_escape_string($_POST['askprice']);
$bedrooms = empty($_POST['bedrooms']) ? die ("Please Enter How Many Bedrooms Your House Has") : mysql_escape_string($_POST['bedrooms']);      
$bathrooms = empty($_POST['bathrooms']) ? die ("Please Enter How Many Bathrooms Your House Has") : mysql_escape_string($_POST['bathrooms']);
$joindate = date(dmY);
$activationID = rand(10000, 99999);
$activated = 0;
$to = "$email1@$email2";
$subject = "Sellyourownhome.com.au activate your account";
$message = "Welcome to Sell your own home The easiest and cheapest way to sell your own home <br> <br> <a href=\"localhost/activate.php\"> <br> <br> Thanks";
$headers = "Help@sellyourownhome.com.au";

/* The above code is to check whether the user has or has not filled in all of the form. This means the user is forced to fill out the whole
form instead of just half of it. This also puts all of the information from the form into Variables so we can use them later. This code also
emptys all of the posts, so that it frees up memory so we can do other things faster. */
if(!empty($_POST)){
    // This code checks to see if the form has been emptied.
      $query = "INSERT INTO  users (name, email1, email2, daytime, nighttime, mobile, streetnum, streetname, suburb, state, postcode, askprice, bedrooms, bathrooms, joindate, expiredate, activationID, activated) VALUES ('$name', '$email1', '$email2', '$daytime', '$nighttime', '$mobile', '$streetnum', '$streetname', '$suburb', '$state', '$postcode', '$askprice', '$bedrooms', '$bathrooms', '$joindate', '$expire', '$activationID', '$activated')";
/* This is the query, this is what we are asking the MySQL database to do. This specific query asks the database to add the Variables we took
out of that form into the database. So we can later use those variables in different scripts. We can also use them to store user information such
as: how much money a user has. */ 
    $result = mysql_query($query) or die ("User already exists");   
/* This code above executes the query. */
    echo "Account Created";  // This is the message the user gets if the process completed and their account was sucess fully added.
mysql_close($connection);
/* Finally we close the MySQL connection that we opened using Connect.php. This is the end of the hard bit of the script. Below is the tying up
of loss ends. The loss ends of else { and if { statements. */
}
}
}
else {
echo "You passwords dont match";
}
}


?>
</body>
</html>
[/CODE]

- Cheers, Daniel
Link to comment
Share on other sites


hai,
      the error is in way of using if and else

Your Code:
if($count==1){
    echo "Username already exists";
}
else {
                if ( $pass1 == $pass2 ) {
                .................
                }
      else{
              echo "You passwords dont match";
      }
-----------------------------------------

the second condition should be
if($count==1){
else if( $pass1 == $pass2 ) {
}else{
  echo "You passwords dont match";
}
Link to comment
Share on other sites

I have fixed the problem by changing a few else { } statements to if { } statements. I have all the right details in connect.php (contains all the $user, $host, $db info). I have a table in the database called users. I have a Column in the table called user and a column called pass. Yet, I still get problems with this script. Here are the errors:

[QUOTE]

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\xampp\htdocs\newuser.php on line 43

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Program Files\xampp\htdocs\newuser.php on line 43

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\newuser.php on line 46

[/QUOTE]

And here is the script:

[CODE]
<html>
<head>
<?php
include('header.php');
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if (!isset($_POST['submit'])) { // if the form has not been submitted before
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    Name(s): <input type="text" name="name"> <br>
    Email: <input type="text" name="email1">
    @<input type="text" name="email2">
  Daytime Phone Number:<input type="text" name="daytime"> <br>
    Nighttime Phone Number:<input type="text" name="nighttime"> <br>
Mobile Number:<input type="text" name="mobile"> <hr>
    Street Number:<input type="text" name="streetnum">
    Street Name: <input type="text" name="streetname"> <br>
    Suburb: <input type="text" name="suburb">
    State: <input type="text" name="state">
    Postcode: <input type="text" name="postcode"> <br>
    Asking Price: <input type="text" name="askprice">
    Bedrooms: <input type="text" name="bedrooms">
    Bathrooms: <input type="text" name="bathrooms"> <hr> 
Desired Username: <input type ="text" name="user"> <br>
Password: <input type="password" name="pass1">
Retype Password: <input type="password" name="pass2">                                 
    <input type="submit" name="submit">
</form>

          <?php
}
else {

$pass1 = empty($_POST['pass1']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass1']);
$pass2 = empty($_POST['pass2']) ? die ("Please Retype Your Password") : mysql_escape_string($_POST['pass2']);
$user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']);
$sql = "SELECT * FROM users WHERE user='$user'";
    $result = mysql_query($sql);

  // Mysql_num_row is counting table ro
$count=mysql_num_rows($result);

  // If result matched $user and $pass, table row must be 1 row

if($count==1){

echo "Username already exists";

}
if ($count == 0) {

if ( $pass1 == $pass2 ) {

include('connect.php');
$expire = strtotime('next month',$date); // Start a connection to the MySQL Database
  $name = empty($_POST['name']) ? die ("Please Enter Your Name") : mysql_escape_string($_POST['name']);
$email1 = empty($_POST['email1']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email1']);
    $email2 = empty($_POST['email2']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email2']);
    $daytime = empty($_POST['daytime']) ? die ("Please Enter Your Daytime Phone Number") : mysql_escape_string($_POST['daytime']);
    $nighttime = empty($_POST['nighttime']) ? die ("Please Enter Your Nighttime Phone Number") : mysql_escape_string($_POST['nighttime']);
    $mobile = empty($_POST['mobile']) ? die ("Please Enter Your Mobile Number") : mysql_escape_string($_POST['mobile']);
$streetnum = empty($_POST['streetnum']) ? die ("Please Enter Your Streetnumber") : mysql_escape_string($_POST['streetnum']);
$streetname = empty($_POST['streetname']) ? die ("Please Enter Your Streetname") : mysql_escape_string($_POST['streetname']);
$suburb = empty($_POST['suburb']) ? die ("Please Enter Your Suburb") : mysql_escape_string($_POST['suburb']);
$state = empty($_POST['state']) ? die ("Please Enter Your State") : mysql_escape_string($_POST['state']);
$postcode = empty($_POST['postcode']) ? die ("Please Enter Your Postcode") : mysql_escape_string($_POST['postcode']);
$askprice = empty($_POST['askprice']) ? die ("Please Enter Your Asking Price") : mysql_escape_string($_POST['askprice']);
$bedrooms = empty($_POST['bedrooms']) ? die ("Please Enter How Many Bedrooms Your House Has") : mysql_escape_string($_POST['bedrooms']);      
$bathrooms = empty($_POST['bathrooms']) ? die ("Please Enter How Many Bathrooms Your House Has") : mysql_escape_string($_POST['bathrooms']);
$joindate = date(dmY);
$activationID = rand(10000, 99999);
$activated = 0;
$to = "$email1@$email2";
$subject = "Sellyourownhome.com.au activate your account";
$message = "Welcome to Sell your own home The easiest and cheapest way to sell your own home <br> <br> <a href=\"localhost/activate.php\"> <br> <br> Thanks";
$headers = "Help@sellyourownhome.com.au";

/* The above code is to check whether the user has or has not filled in all of the form. This means the user is forced to fill out the whole
form instead of just half of it. This also puts all of the information from the form into Variables so we can use them later. This code also
emptys all of the posts, so that it frees up memory so we can do other things faster. */
if(!empty($_POST)){
    // This code checks to see if the form has been emptied.
      $query = "INSERT INTO  users (name, email1, email2, daytime, nighttime, mobile, streetnum, streetname, suburb, state, postcode, askprice, bedrooms, bathrooms, joindate, expiredate, activationID, activated) VALUES ('$name', '$email1', '$email2', '$daytime', '$nighttime', '$mobile', '$streetnum', '$streetname', '$suburb', '$state', '$postcode', '$askprice', '$bedrooms', '$bathrooms', '$joindate', '$expire', '$activationID', '$activated')";
/* This is the query, this is what we are asking the MySQL database to do. This specific query asks the database to add the Variables we took
out of that form into the database. So we can later use those variables in different scripts. We can also use them to store user information such
as: how much money a user has. */ 
$result = mysql_query($query) or die ("User already exists");   
/* This code above executes the query. */
    echo "Account Created";  // This is the message the user gets if the process completed and their account was sucess fully added.
mysql_close($connection);
/* Finally we close the MySQL connection that we opened using Connect.php. This is the end of the hard bit of the script. Below is the tying up
of loss ends. The loss ends of else { and if { statements. */
}
}
}
else {
echo "You passwords dont match";
}
}


?>
</body>
</html>
[/CODE]

Whats wrong?

Cheers, Daniel
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.