Announcement

Collapse
No announcement yet.

PHP & mysql

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP & mysql

    I am working on a registration and login form for my website and have reached the point where I can submit the data, insert it into the database, and validate it. I can't seem to get the users to the proper pages after the information has been checked. I have tried the "header" statement to no avail. I am using "if---else" to validate. Here is my script for validation:

    <html>
    <body>
    <?php
    $con = mysql_connect("localhost","colescom_colen","****** *");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("colescom_names", $con);
    $result = mysql_query("SELECT * FROM person
    WHERE name='Colen'");
    while($row = mysql_fetch_array($result))
    $name=$row['name'];
    $email=$row['email'];
    if ($name=="Colen")
    header("Location: ThankYou.html");
    else
    header("Location: NoRecord.html");
    echo "<br />";
    ?>
    </body>
    <html>

    When I run the script, I get this error:

    Warning: Cannot modify header information - headers already sent by (output started at /home/colescom/public_html/where.php:3) in /home/colescom/public_html/where.php on line 16

    I have used "echo" statements in place of the "header" statements to let me know whether the information in the database matches. That works. Any help would be greatly appreciated.

    Anyone who wishes to study php or mysql should check out this website:

    http://www.w3schools.com/php/php_intro.asp
    No matter how fast you are going, there is always someone trying to pass.

  • #2
    Re: PHP &amp; mysql

    Try:

    <html>
    <body>
    <?php
    $con = mysql_connect("localhost","colescom_colen","****** *");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("colescom_names", $con);
    $result = mysql_query("SELECT * FROM person
    WHERE name='Colen'");
    while($row = mysql_fetch_array($result))
    $name=$row['name'];
    $email=$row['email'];
    if ($name=="Colen")
    {
    header("Location: ThankYou.html");
    }
    else
    {
    header("Location: NoRecord.html");
    }
    echo "<br />";
    ?>
    </body>
    <html>


    But why is it all included in the html tags ?
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment


    • #3
      Re: PHP &amp; mysql

      I have been going thru the tutorials at: http://www.w3schools.com/php/php_variables.asp

      Some of the examples include the html tags and some do not. Apparently it makes no difference whether they are there or not as far as the php code is concerned as long as the necessary php start and stop tags are in place
      No matter how fast you are going, there is always someone trying to pass.

      Comment


      • #4
        Re: PHP &amp; mysql

        Here is a script I have as login.php:

        <?php
        $name=$_POST["name"];
        $email=$_POST["email"];
        $con = mysql_connect("localhost","colescom_colen","****** **");
        if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }
        mysql_select_db("colescom_colen", $con);
        $result = mysql_query("SELECT * FROM person)
        WHERE email=$email);
        if $result==$email;
        {
        echo 'Login okay';
        else
        echo 'Not in system';
        }
        mysql_close($con);
        ?>

        I also have a login.html which transmits a login email address. When I submit the address I get the following error:

        Parse error: syntax error, unexpected $end in /home/colescom/public_html/login.php on line 20


        There is no line 20 in my script. I did a search on this type of error but could not find an answer.
        No matter how fast you are going, there is always someone trying to pass.

        Comment


        • #5
          Re: PHP &amp; mysql

          1. Did you get any results by inserting the {
          and } ?
          2. The html tags are used if in the same page you have to combine php with some html code. If the script is stand alone, as it seems to be in your case (the presense of two " headr: .... " lines makes me think so) there is no need for html tags.
          3. I think that you have a small error in here, and this caused your script to go directly to the end, which causes the error message.

          Try it like this: (please note that i have not tested it)


          <?php
          $name=$_POST["name"];
          $email=$_POST["email"];
          $con = mysql_connect("localhost","colescom_colen","****** **");
          if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }
          mysql_select_db("colescom_colen", $con);
          $result = mysql_query("SELECT * FROM person WHERE email=$email");
          while ( $row = mysql_fetch_array($result))
          {
          if ($row['email'] = $email)
          {
          $registered = "True";
          }
          }
          mysql_close($con);
          if ($registered !="")
          {
          echo 'Login okay';
          header("Location: page_to_send_him_to.html"); // Use this line if you wish to send him to a specific page
          }
          else
          {
          echo 'You are not registered yet.';
          header("Location: registrationpage.html"); // Use this line if you wish to send him to the registration form page
          }
          ?>
          Navaldesign
          Logger Lite: Low Cost, Customizable, multifeatured Login script
          Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
          DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
          Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

          Comment


          • #6
            Re: PHP &amp; mysql

            Here is the script as I tried it:

            <?php
            $name=$_POST["name"];
            $email=$_POST["email"];
            $con = mysql_connect("localhost","colescom_colen","****** ");
            if (!$con)
            {
            die('Could not connect: ' . mysql_error());
            }
            mysql_select_db("colescom_colen", $con);
            $result = mysql_query("SELECT * FROM person WHERE email=$email");
            while ( $row = mysql_fetch_array($result))
            {
            if ($row['email'] = $email)
            $registered = "True"
            mysql_close($con);
            }
            if ($registered !="")
            {
            echo 'Login okay';
            header("Location: ThankYou.html"); // Use this line if you wish to send him to a specific page
            }
            else
            {
            echo 'You are not registered yet.';
            header("Location: NoRecord.html"); // Use this line if you wish to send him to the registration
            form page
            }
            ?>

            I get this error:

            Parse error: syntax error, unexpected T_STRING in /home/colescom/public_html/login.php on line 15

            Line 15: mysql_close($con);

            I checked it with ***ad (a php editor). All parentheses and brackets are in place.

            I noticed you closed the connection to the database before using the header statement. Is this necessary to get the header statement to work?
            No matter how fast you are going, there is always someone trying to pass.

            Comment


            • #7
              Re: PHP &amp; mysql

              You have moved one of the curly brackets - the one before the mysql_close($con);

              I also made a couple of changes. Please copy / paste and try again.

              The connection is only needed till the check is done. As a good rule, the connection should be closed after every querry, unless you use loop in loop techniques which are rather complicated.
              Navaldesign
              Logger Lite: Low Cost, Customizable, multifeatured Login script
              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

              Comment


              • #8
                Re: PHP &amp; mysql

                What were the other changes you made?
                No matter how fast you are going, there is always someone trying to pass.

                Comment


                • #9
                  Re: PHP &amp; mysql

                  Put two curly bracket where missing.
                  Navaldesign
                  Logger Lite: Low Cost, Customizable, multifeatured Login script
                  Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                  DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                  Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                  Comment

                  Working...
                  X