Jump to content
Html

Mysql db data doesn't register

Recommended Posts

Hmm, could you not use the tutorial files, and just type the up to date code? I would plan to use the CSS from the existing files I have.

Anything small would be appreciated, I only state this query, since I haven't got a response from some random individual I contacted, may be the free offer wasn't of interest, how long would it take to create, an hour or two. Could be less if a person knows what they are doing.

I may have to look elsewhere if nothing is possible.

Share this post


Link to post
Share on other sites

If a tutorial is giving you all of the files you need, that should be everything.  You don't need anything from me, I'm sure there are a ton of video tutorials with files that you just save and upload, and modify so they work in the environment.  You would get the same thing from me, but I wouldn't have to spend any time on the night of my wedding anniversary to do that.

If you don't understand the code in the first place, then the source of the files isn't going to make a difference.

Share this post


Link to post
Share on other sites

Hmm, you saw the example, that worked but was completely out of date to use $_POST (iss


<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    if (isset($_POST['login'])) { //user logging in

        require 'login.php';
        
    }
    
    elseif (isset($_POST['register'])) { //user registering
        
        require 'register.php';
        
    }
}
?>

what ever else and all that. I've been posting the examples now for months. 🤔

Like I stated, there is infinityfree, it would be a start, an actual working login system to register, post comments on a user's page, and so on. All i can do is inquire. Where do you suggest I look to try and find somebody who can make something workable on a free host for me for free to begin with, once working I will see where I can go with this.

I cancelled my paid host, I couldn't keep up paying loose cash for no progress. I may eventually return, but infinityfree was better than the other free host since there are no pop up ads, dodgy ads, like install flash player and so on. Unfortunately the example code above wouldn't work, so having something that works according to infinity would be the right step.

 

Edited by Html
corrections

Share this post


Link to post
Share on other sites

I guess you could look at freelancing sites, most of them expect to get paid but if it's quick and easy enough I'm sure there would be someone willing to do it.  I just don't think you're going to learn anything from that.

In general, it's also a good idea to make it easy for people to help you if that's what you want.  Instead of asking someone else to set up a hosting account and building something for you,  for example, offer to set up the account first and just provide the information they need to use it.

Share this post


Link to post
Share on other sites

Well I still have the account but it scheduled for closure within two months. Is there anyone you can point me to? Any contacts?

I did some searches, well there are some freelance offers, I've viewed a few sites, but these range from £79 to into the hundreds, I know a business would need to charge something to make a profit. Some free lance offers are under £20.

I've viewed this odd site. http://www.alittlebitofsomething.co.uk   

https://www.freelancer.com

Also found this interesting old topic from 2007. Just from viewing the website design offers, just ridiculous amount of money being charged, when one  has wix, I have a free wix site for blender 3d. I had made a few demos, quite crappy, based of a film.

Edited by Html
Added some links.

Share this post


Link to post
Share on other sites

I don't have any freelancer contacts, the only one I've used recently was off of Upworx and was for server/application penetration testing.

Share this post


Link to post
Share on other sites

I did send an email to somebody who appears to be a website designer, so I hope he can at least respond to me, I tried with a different one, but nothing so far.

Just so you know, the video tutorial files, lucky I still kept them, just in case somebody could edit the code on my behalf, now the user has setup a charging system, so $5 to get a download. 😉

Share this post


Link to post
Share on other sites
<?php 
/* Main page with two forms: sign up and log in */
require 'connect_db.php';
session_start();
?>
<!DOCTYPE html>
<html>
<head>
  <title>-Sign-Up/Login Form</title>
  <?php include 'css/css.html'; ?>
</head>

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{
    if (isset($_POST['login'])) { //user logging in

        require 'login.php';
        
    }
    
    elseif (isset($_POST['register'])) { //user registering
        
        require 'proces.php';
        
    }
}
?>
<body>
<img src="header20182.jpg">
<center>
<img src="userscopy.jpg">
</center>
  <div class="form">
      
      <ul class="tab-group">
        <li class="tab"><a href="#signup">Sign Up</a></li>
        <li class="tab active"><a href="#login">Log In</a></li>
      </ul>
      
      <div class="tab-content">

         <div id="login">   
          <h1>Welcome!</h1>
          
          <form action="proces.php" method="post" autocomplete="off">
          
            <div class="field-wrap">
            <label>
              Email Address<span class="req">*</span>
            </label>
            <input type="email" required autocomplete="off" name="email"/>
          </div>
          
          <div class="field-wrap">
            <label>
              Password<span class="req">*</span>
            </label>
            <input type="password" required autocomplete="off" name="password"/>
          </div>
          
          <p class="forgot"><a href="forgot.php">Forgot Password?</a></p>
          
          <button class="button button-block" name="login" />Log In</button>
          
          </form>

        </div>
          
        <div id="signup">   
          <h1>Create an account today! </h1>
          
          <form action="proces.php" method="post" autocomplete="off">
          
          <div class="top-row">
            <div class="field-wrap">
              <label>
                First Name<span class="req">*</span>
              </label>
              <input type="text" required autocomplete="off" name='firstname' />
            </div>
        
            <div class="field-wrap">
              <label>
                Last Name<span class="req">*</span>
              </label>
              <input type="text"required autocomplete="off" name='lastname' />
            </div>
          </div>

          <div class="field-wrap">
            <label>
              Email Address<span class="req">*</span>
            </label>
            <input type="email"required autocomplete="off" name='email' />
          </div>
          
          <div class="field-wrap">
            <label>
              Six to eight character Password<span class="req">*</span>
            </label>
            <input type="password"required autocomplete="off" name='password'/>
          </div>
          
          <button type="submit" class="button button-block" name="register" />Register</button>
          
          </form>

        </div>  
        
      </div><!-- tab-content -->
      
</div> <!-- /form -->
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

    <script src="js/index.js"></script>
<a href="privacy.html" target="_blank"><img src="privacy.jpg">
<img src="bottomheader.jpg">
</body>
</html>

Okay I'm trying to get this index page from the old files to work with a new register.php, which is from the php 7 book,

So far the page goes to it after registration but recorded data in the db. Not sure if this was the correct way but consider it works to post data, seemed like the next best step.

so proces.php

<?php 
$page_title = 'PHP Process' ;
include ( 'includes/header.html' ) ;
function fail( $str )
{
  echo "<p>Please enter a $str.</p>";
  echo '<p><a href="post.php">Post Message</a>' ;
  include ( 'includes/footer.html' ) ;
  exit(); 
}
if( isset( $_POST[ 'message' ] ) )
{
  if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
  { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
  else { fail( 'First Name' ) ; }
  if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
  { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
  else { fail( 'Last Name' ) ; }
  if ( !empty( trim( $_POST[ 'email' ] ) ) )
  { $subject = addslashes( $_POST[ 'email' ] ) ; }
  else { fail( 'email' ) ; }
  if ( !empty( trim( $_POST[ 'password' ] ) ) )
  { $subject = addslashes( $_POST[ 'password' ] ) ; }
  else { fail( 'password' ) ; }
  require ( 'connect_db.php' ) ;
  $sql = "INSERT INTO users (first_name,last_name,email,password) 
          VALUES ('$first_name', '$last_name', '$email', '$password' )" ;
  $result = mysqli_query( $dbc, $sql ) ;
  if (mysqli_affected_rows($dbc) != 1) 
  { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
  else 
  { mysqli_close( $dbc ) ; header('Location: profile.php') ;   }
}

So profile should be next, but only loads the includes header page heading.

Share this post


Link to post
Share on other sites

If a connect_db is in a different folder, it should be /new/connect_db.php? I tried that, I couldn't get a register.php to work from the example files.

Share this post


Link to post
Share on other sites

You should not start relative paths with a slash.  For any Linux server, starting a path with a slash indicates that you are starting at the root of the filesystem, not relative to the current location.

Share this post


Link to post
Share on other sites

I corrected that. Thanks.

The files do work. I think I could still use the file I am using from the example files, the index only, the one from the easy book files is very basic, and was the first file I used a year back when I first watched a php 7 tutorial. The individual who went out of his way to get it to work, never responded to any further emails. He probably thought the code was still fine to use, or what ever, thought yeah make a tutorial series using out of date code.

I imagine the code I am using which is from Mysql & php from the easy series is probably out of date, similar to what I got from php 7. But yes I sent a message via site for a Php 7 PDO user login system.

Share this post


Link to post
Share on other sites

What I would need to do is, using what I have is, the profile page would need to load once registered a name, I'm sure some out of date code can be inserted into one of the pages.

I guess on the register page some sort of extra code like the id part from the example files can be added with that, from what I can remember you stated that "1" is one user, so the php has to be able read that, but individually, so not to login with just one user.

Taken from the downloaded files.

<?php # DISPLAY COMPLETE REGISTRATION PAGE.

# Set page title and display header section.
$page_title = 'Register' ;
include ( 'includes/header.html' ) ;

# Check form submitted.
if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
{
  # Connect to the database.
  require ('../connect_db.php'); 
  
  # Initialize an error array.
  $errors = array();

  # Check for a first name.
  if ( empty( $_POST[ 'first_name' ] ) )
  { $errors[] = 'Enter your first name.' ; }
  else
  { $fn = mysqli_real_escape_string( $dbc, trim( $_POST[ 'first_name' ] ) ) ; }

  # Check for a last name.
  if (empty( $_POST[ 'last_name' ] ) )
  { $errors[] = 'Enter your last name.' ; }
  else
  { $ln = mysqli_real_escape_string( $dbc, trim( $_POST[ 'last_name' ] ) ) ; }

  # Check for an email address:
  if ( empty( $_POST[ 'email' ] ) )
  { $errors[] = 'Enter your email address.'; }
  else
  { $e = mysqli_real_escape_string( $dbc, trim( $_POST[ 'email' ] ) ) ; }

  # Check for a password and matching input passwords.
  if ( !empty($_POST[ 'pass1' ] ) )
  {
    if ( $_POST[ 'pass1' ] != $_POST[ 'pass2' ] )
    { $errors[] = 'Passwords do not match.' ; }
    else
    { $p = mysqli_real_escape_string( $dbc, trim( $_POST[ 'pass1' ] ) ) ; }
  }
  else { $errors[] = 'Enter your password.' ; }
  
  # Check if email address already registered.
  if ( empty( $errors ) )
  {
    $q = "SELECT user_id FROM users WHERE email='$e'" ;
    $r = @mysqli_query ( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) != 0 ) $errors[] = 'Email address already registered. <a href="login.php">Login</a>' ;
  }
  
  # On success register user inserting into 'users' database table.
  if ( empty( $errors ) ) 
  {
    $q = "INSERT INTO users (first_name, last_name, email, pass, reg_date) VALUES ('$fn', '$ln', '$e', SHA2('$p',256), NOW() )";
    $r = @mysqli_query ( $dbc, $q ) ;
    if ($r)
    { echo '<h1>Registered!</h1><p>You are now registered.</p><p><a href="login.php">Login</a></p>'; }
  
    # Close database connection.
    mysqli_close($dbc); 

    # Display footer section and quit script:
    include ('includes/footer.html'); 
    exit();
  }
  # Or report errors.
  else 
  {
    echo '<h1>Error!</h1><p id="err_msg">The following error(s) occurred:<br>' ;
    foreach ( $errors as $msg )
    { echo " - $msg<br>" ; }
    echo 'Please try again.</p>';
    # Close database connection.
    mysqli_close( $dbc );
  }  
}
?>

<!-- Display body section with sticky form. -->
<h1>Register</h1>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>"> 
Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>"></p>
<p>Email Address: <input type="text" name="email" size="50" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"></p>
<p>Password: <input type="password" name="pass1" size="20" value="<?php if (isset($_POST['pass1'])) echo $_POST['pass1']; ?>" >
Confirm Password: <input type="password" name="pass2" size="20" value="<?php if (isset($_POST['pass2'])) echo $_POST['pass2']; ?>"></p>
<p><input type="submit" value="Register"></p>
</form>

<?php 

# Display footer section.
include ( 'includes/footer.html' ) ; 

?>

So this part is from the example files of the older stuff I had been hanging onto for half a year now.

$user_id="";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["id"])) {
$user_id=$_GET["id"];
}

///process profile to id retrieved

}

And then, home.php

As you can see there is even a shop page, not sure if the book contained a full chapter on a task like that.

<?php # DISPLAY COMPLETE LOGGED IN PAGE.

# Access session.
session_start() ; 

# Redirect if not logged in.
if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; }

# Set page title and display header section.
$page_title = 'Home' ;
include ( 'includes/header.html' ) ;

# Display body section.
echo "<h1>HOME</h1><p>You are now logged in, {$_SESSION['first_name']} {$_SESSION['last_name']} </p>";

# Create navigation links.
echo '<p><a href="forum.php">Forum</a> | <a href="shop.php">Shop</a> | <a href="goodbye.php">Logout</a></p>';

# Display footer section.
include ( 'includes/footer.html' ) ;
?>

So well yes as you can see there is user_id, that wouldn't be related to this task of trying to get profile index of that registered username listed in that page with some code.

Share this post


Link to post
Share on other sites

When the user has logged in successfully, his user_id, first_name, last_name from the database are assigned to sessions, you can use the session user_id, to go to the profile page, and retrieve that specific user profile details from the database using that user_id value to show on that profile page.

Share this post


Link to post
Share on other sites

I see, there is a small chapter in the easy book, about sessions but using a cookie to store login details. That obviously doesn't apply to this.

The good news is this login system works as is, just needs a comment box to post to a user index, as well a index link to go to it.

I renamed post to post2 for the comment system, since the post.php is also used for registering on the account system too.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×