Jump to content
Sign in to follow this  
Html

Mysql db data doesn't register

Recommended Posts

Hi,

I am using a free website host to display a login/registration system, the exact same one as the one I am using on a paid service. For what ever reason the free host doesn't seem to store any registered data.

I'm using the same php files, there isn't anything different, since they are from the same setup. The php version on the free host is 7.

I checked both mysql setting pages, I don't know what is the problem with this. If it worked on the other free host I was using months ago, but I closed that account due to pop up ads, this free host doesn't put any on a page.

Thank you.

Share this post


Link to post
Share on other sites

Make sure that your PHP code is checking for and reporting any MySQL error messages, and make sure PHP is configured to use an error log that you can check after the fact.

Share this post


Link to post
Share on other sites

Index.php is the link in the address bar after registration. So it should of been profile.php after.

As for checking errors, I don't remember about that.

Edited by Html

Share this post


Link to post
Share on other sites

I can't comment on code that I haven't seen, but in general it's your responsibility to check for database errors, PHP usually does not report them automatically, and you need to make sure that your PHP settings are set up so that you can find any error messages from PHP.  If there is an error then there will be an error message if everything is set up correctly.

Share this post


Link to post
Share on other sites

Well having recall my previous posts, you'll know i'm not very good at web languages.

From what I can remember, the php settings are the same as the previous free website host I did use, and the paid host.

I have a feeling that free host I am using is may be a reseller account from fasthost web hosting. It only has ads on the cpanel area.

As for the error code, I have the index

so index.php

<?php 
/* Main page with two forms: sign up and log in */
require 'db.php';
session_start();
?>
<!DOCTYPE html>
<html>
<head>
  <title></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 'register.php';
        
    }
}
?>

And then, what other code would be needed to determine errors?

Thank you.

Edited by Html

Share this post


Link to post
Share on other sites

For starters, add this to the top of every page:

ini_set('display_errors', 1);
	error_reporting(E_ALL);

You wouldn't want to use those settings for a production site, you would want to use error logging instead, but that's fine for development.  You didn't show any database code there, it's just a bunch of includes, but you need to check the return values of your database functions to figure out if an error happened.  

http://php.net/manual/en/mysqli.error.php

If you're using PDO I would recommend using exceptions for errors.

http://php.net/manual/en/pdo.error-handling.php

Share this post


Link to post
Share on other sites

I tried that for index.php, it doesn't load anything once done,

This is all it loads after registration.

ini_set('display_errors', 1); error_reporting(E_ALL); 

I have a feeling it must be the free host, because nothing has changed between the paid host, and the free host.

Not sure what I am using, all I know is I got the files from that video tutorial as a start really, after the previous video one didn't go any further.

Edited by Html

Share this post


Link to post
Share on other sites

That's PHP code, it needs to go inside a PHP block.  If the browser is printing the code then the server doesn't think it's PHP code.

Share this post


Link to post
Share on other sites

And yes I did try that too. Also this affects the CSS on the page too.

I tried placing that code in the first part, like so.

 

<?php 
/* Main page with two forms: sign up and log in */
require 'db.php';
session_start();
ini_set('display_errors', 1);
	error_reporting(E_ALL);
?>

That has solved that problem, and then this was displayed after registration.

mysqli::escape_string(): Couldn't fetch mysqli in  line 12 and 18 in register.php

I guess this is line 12 $first_name = $mysqli->escape_string($_POST['firstname']);

and 18 $result = $mysqli->query("SELECT * FROM users WHERE email='$email'") or die($mysqli->error());

Edited by Html
Added more info

Share this post


Link to post
Share on other sites

That sounds like you're not connecting correctly.  Again, if there's an error with MySQL, like with connecting, it is your responsibility to check for that error and output a message if you want to.  It does not happen automatically.

You're also on the wrong track if you're trying to escape data manually, you should use prepared statements instead to avoid SQL injection attacks.

http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

I always prefer using PDO instead of mysqli though:

http://php.net/manual/en/book.pdo.php

http://php.net/manual/en/pdo.prepared-statements.php

Share this post


Link to post
Share on other sites
2 hours ago, Html said:

mysqli::escape_string(): Couldn't fetch mysqli in  line 12 and 18 in register.php

I guess this is line 12 $first_name = $mysqli->escape_string($_POST['firstname']);

and 18 $result = $mysqli->query("SELECT * FROM users WHERE email='$email'") or die($mysqli->error());

This sounds like an error with your mysqli object.

The Database Location, Username, Password, and Database Name on the free plan are the same as the paid plan?

 

If they are (Or you've already checked that), check if you're closing your connection anywhere.
That error can arise when you're trying to use a closed connection object.

 

I agree with justsomeguy, in regards to Prepared Statements. They're not too difficult, so give it a shot!

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
Sign in to follow this  

×