php/sql problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • styliek@gmail.com

    php/sql problem

    I know this might not be the right place for a sql problem but as im
    writhing in php I thought someone might be able to help. Im creating a
    registering page, where the scripts should first check if the business
    name exists or not, if it doesnt exist it should bring the user to a
    page to create the business details.
    If the business name already exists it should check if it has been
    activated already, again if it has been activated it will guide the
    user out of the process, if not it will attach the user to the
    business so they can login and modify the details.

    Any help greatly appreciated, it worked fine when registering a user
    to a business with out the checks, but when I entered the sql checking
    queries it went to hell. The answer is probably obvious but i have
    been staring at it so long i cant see whats right in front of my eyes


    if ($fn && $ln && $e && $p) { // If everything's OK.

    //check to see if the business name exists, if it doesnt then
    allow the user to enter the business

    $queryN = 'SELECT * FROM business_finder WHERE Name =$Name';
    $resultN = mysql_query ($queryN) or trigger_error(" Query:
    $query\n<br />MySQL Error: " . mysql_error());

    if (mysql_num_rows ($resultN) == 0)
    { // the business name doesnt exists
    echo'no such '.$Name.' here lets create it .';
    }
    else
    {

    // Make sure the business has not already been activated . non
    active is an empty field in DB

    $query = 'SELECT * FROM business_finder WHERE active =""';
    $result = mysql_query ($query) or trigger_error(" Query: $query
    \n<br />MySQL Error: " . mysql_error());
    if (mysql_num_rows ($result) == 0) { // Available.

    // Create the activation code.
    $a = md5(uniqid(rand (), true));
    // Add the user.
    $query5 = "INSERT INTO users(email, pass, first_name,
    last_name, active, registration_da te) VALUES ('$e', '$p', '$fn',
    '$ln', '$a', NOW() ) ";
    $query1 = "UPDATE business_finder SET active='$a' WHERE Name =
    '$Name'";
    $result5 = mysql_query ($query5) or trigger_error(" Query: $query
    \n<br />MySQL Error: " . mysql_error());
    $result1= mysql_query ($query1) or trigger_error(" Query: $query
    \n<br />MySQL Error: " . mysql_error());
    if (mysql_affected _rows() == 1)
    { // If it ran OK.
    echo '<p><font color="red" size="+1">Every thing is ok, please
    click <a href="./user_admin.php" >here</ato continue with registering
    your business</font></p>';
    }
    else
    { // If it did not run OK.
    echo '<br><br><p><fo nt color="red" size="+1">Busin ess not available.
    We apologize for any inconvenience.</font></p>';
    }
    }//end available
    else
    { // The business is registered.
    echo '<p><font color="red" size="+1">That business has already been
    registered/active. If you have forgotten your password, use the link
    to have your password sent to you.</font></p>';
    }
    }

    }
    else
    { // If one of the data tests failed.
    echo '<p><font color="red" size="+1">Pleas e try again.</font></p>';
    }

    mysql_close(); // Close the database connection.

    } // End of the main Submit conditional.

  • strawberry

    #2
    Re: php/sql problem

    On Mar 15, 7:04 pm, styl...@gmail.c om wrote:
    I know this might not be the right place for a sql problem but as im
    writhing in php I thought someone might be able to help. Im creating a
    registering page, where the scripts should first check if the business
    name exists or not, if it doesnt exist it should bring the user to a
    page to create the business details.
    If the business name already exists it should check if it has been
    activated already, again if it has been activated it will guide the
    user out of the process, if not it will attach the user to the
    business so they can login and modify the details.
    >
    Any help greatly appreciated, it worked fine when registering a user
    to a business with out the checks, but when I entered the sql checking
    queries it went to hell. The answer is probably obvious but i have
    been staring at it so long i cant see whats right in front of my eyes
    >
    if ($fn && $ln && $e && $p) { // If everything's OK.
    >
    //check to see if the business name exists, if it doesnt then
    allow the user to enter the business
    >
    $queryN = 'SELECT * FROM business_finder WHERE Name =$Name';
    $resultN = mysql_query ($queryN) or trigger_error(" Query:
    $query\n<br />MySQL Error: " . mysql_error());
    >
    if (mysql_num_rows ($resultN) == 0)
    { // the business name doesnt exists
    echo'no such '.$Name.' here lets create it .';
    }
    else
    {
    >
    // Make sure the business has not already been activated . non
    active is an empty field in DB
    >
    $query = 'SELECT * FROM business_finder WHERE active =""';
    $result = mysql_query ($query) or trigger_error(" Query: $query
    \n<br />MySQL Error: " . mysql_error());
    if (mysql_num_rows ($result) == 0) { // Available.
    >
    // Create the activation code.
    $a = md5(uniqid(rand (), true));
    // Add the user.
    $query5 = "INSERT INTO users(email, pass, first_name,
    last_name, active, registration_da te) VALUES ('$e', '$p', '$fn',
    '$ln', '$a', NOW() ) ";
    $query1 = "UPDATE business_finder SET active='$a' WHERE Name =
    '$Name'";
    $result5 = mysql_query ($query5) or trigger_error(" Query: $query
    \n<br />MySQL Error: " . mysql_error());
    $result1= mysql_query ($query1) or trigger_error(" Query: $query
    \n<br />MySQL Error: " . mysql_error());
    if (mysql_affected _rows() == 1)
    { // If it ran OK.
    echo '<p><font color="red" size="+1">Every thing is ok, please
    click <a href="./user_admin.php" >here</ato continue with registering
    your business</font></p>';
    }
    else
    { // If it did not run OK.
    echo '<br><br><p><fo nt color="red" size="+1">Busin ess not available.
    We apologize for any inconvenience.</font></p>';
    }}//end available
    >
    else
    { // The business is registered.
    echo '<p><font color="red" size="+1">That business has already been
    registered/active. If you have forgotten your password, use the link
    to have your password sent to you.</font></p>';
    }
    }
    >
    }
    else
    { // If one of the data tests failed.
    echo '<p><font color="red" size="+1">Pleas e try again.</font></p>';
    }
    >
    mysql_close(); // Close the database connection.
    >
    } // End of the main Submit conditional.
    Have you tried echoing the quer(y)/ies?

    Comment

    • Paul Furman

      #3
      Re: php/sql problem

      strawberry wrote:
      On Mar 15, 7:04 pm, styl...@gmail.c om wrote:
      >
      >but when I entered the sql checking queries it went to hell.
      I'm not clear what the problem is. Some error message or the results
      just not registering in the database?

      Have you tried echoing the quer(y)/ies?
      Yes put lots of echos/prints to debug.

      Comment

      Working...