Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8024817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:58:15+00:00 2026-06-04T22:58:15+00:00

i am new in php/mysql and sorry if my question is silly. I am

  • 0

i am new in php/mysql and sorry if my question is silly. I am trying to make a register/login/logout system with php and mysql. My skills are not good and i am not a programmer, so i tried to change a script that i found on the web. It contains files, index.php, activate php. login.php, logout.php, register.php.

It worked great when I tried the example given, but i changed the code quite a bit because I wanted the user to add more values in register like first name, last name etc and not just username, password and email. So I changed the code and added more columns on the mysql database. Now it won t work, it says that can ‘t find user when i try to activate and i also can ‘t log in.

index.php: is a very simple file that has an html form and asks unknown user if he wants to login or register and also starts a session

logout.php: simply unsets session

login.php:

 <?php session_start(); ?>
<html>
<body>
    <?php
    if(isset($_POST["user"])){
        $con = mysql_connect("localhost","root","password");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }

        mysql_select_db("myapp", $con);

        $sql = "SELECT * FROM `users` WHERE `user` LIKE '". mysql_real_escape_string($_POST["user"])
        ."' AND ".
            "`pass` LIKE MD5('". mysql_real_escape_string($_POST["pass"])
        ."') AND ".
            "`active` = 'DONE'";

        $result = mysql_query($sql);

        $found = 0;
        while ($row = mysql_fetch_array($result)) {
            if ($row[1]==$_POST["user"]) {
                $found = 1;
            }
        }

        if ($found) {
        $_SESSION["USER"] = $_POST["user"];
        ?>Thank you for logging in<?
        }
        else {
        ?>User/Pass is wrong!<?
        }

        mysql_close($con);
    }
    else {
    ?>

        Please log-in:<br/>
        <form action="login.php" method="POST">
            User: <input type="text" name="user"><br />
            Pass: <input type="password" name="pass"><br />
            <input type="submit" />
        </form>

    <?php
    }
    ?>

register.php:

<?php session_start(); ?>
<html>
<body>
<?php
    if(isset($_POST["user"])){
        $con = mysql_connect("localhost","root","password");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }

        mysql_select_db("myapp", $con);

        $random = rand();

        $sql = "INSERT INTO `myapp`.`users` (`id`, `user`, `pass`, `active`, `firstname`, `lastname`, `mail`) ".
        " VALUES (NULL, '". mysql_real_escape_string($_POST["user"])
        ."', MD5('".mysql_real_escape_string($_POST["pass"])
        ."'), '".mysql_real_escape_string($random)
        ."'), '".mysql_real_escape_string($_POST["firstname"])
        ."'), '".mysql_real_escape_string($_POST["lastname"])
        ."')'".mysql_real_escape_string($_POST["mail"])
        ."');";

        mysql_query($sql);

        mysql_close($con);

        $message = "Please put this url http://localhost/mypage/activate.php?active=" . $random . " in your browser to activate your account.";
        @mail($_POST["mail"], 'Thank you for registering', $message);

        ?>Thank you <?php echo $_POST["user"]; ?> we send you a confirmation e-mail in <?php echo $_POST["mail"]; ?><?php

        echo $message;
    }
    else {
        ?>
        Please register:<br/>
        <form action="register.php" method="POST">
            User: <input type="text" name="user"><br />
            Pass: <input type="password" name="pass"><br />
            firstname:<input type="text" name="firstname"><br />
            lastname:<input type="text" name="lastname"><br />
            mail: <input type="text" name="mail"><br />

            <input type="submit" />
        </form>

        <?php
    }
?>

activate.php:

<?php session_start(); ?>
<html>
<body>
        <?php
    if(isset($_GET["active"])){
        $con = mysql_connect("localhost","root","password");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }

        mysql_select_db("myapp", $con);

        $sql = "SELECT * FROM `users` WHERE `active` LIKE '".      
mysql_real_escape_string($_GET["active"])."'";

        $result = mysql_query($sql);

        $found = 0;
        while ($row = mysql_fetch_array($result)) {
            $found = 1;
        }

        if ($found) {

        $sql = "UPDATE `users` SET `active` ='DONE'";

        $result = mysql_query($sql);

        ?>Thank you for activating<?
        }
        else {
        ?>Can't find user!<?
        }

        mysql_close($con);
    }
    else {
    ?>Invalid activation<?php
    }
    ?>
</body>
</html>

any help would be welcome, thank you and sorry for the long post!! ^_^

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:58:16+00:00Added an answer on June 4, 2026 at 10:58 pm

    In register.php, you have an error in the SQL syntax, you have too many closed parentheses.
    Replace this part like this:

    $sql = "INSERT INTO `myapp`.`users` (`id`, `user`, `pass`, `active`, `firstname`, `lastname`, `mail`) VALUES 
       (NULL,". 
       "'". mysql_real_escape_string($_POST["user"])."',".
       "MD5('".mysql_real_escape_string($_POST["pass"])."'),".
       "'".mysql_real_escape_string($random)."',".
       "'".mysql_real_escape_string($_POST["firstname"])."',".
       "'".mysql_real_escape_string($_POST["lastname"])."',".
       "'".mysql_real_escape_string($_POST["mail"])."');";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use a PHP form (new.php) to update 2 MySQL tables
I am writing a new website that uses PHP and MySQL. I am trying
my last question was no quite good, so im sorry to open new one.
New to PHP and MySQL, have heard amazing things about this website from Leo
I am pretty new to PHP and MySQL and I just can't figure this
I am fairly new to php and mysql but I have created a small
I am very new to PHP and MySql. Is there any method by which
I started doing a new project in PHP / MySql . The Aim of
PHP/MySQL (CodeIgniter) I would like to add new interest_keywords in the exist database value.
Alright, so I'm fairly new to PHP and SQL/MySQL so any help is appreciated.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.