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

Hello funce, thanks for some input.

Justsomeguy,

I downloaded what I have from a video tutorial. So I don't know about PDO, I'm just editing what there was there.

As for the paid host, there is no difference between the two, technical side I'm sure there is. But if the other free host worked to get a registration for the least, as well as my paid host, then why this problem on this free host. How can I be something wrong, there is no difference in the php, its all the same crap. As for the account registration validating stuff, I never got that far with that. Could be the code I am using just is too basic for anything really serious. But then again I doubt that was  really the problem even though you stated the way I was going about trying to get this tutorial to go one way and then hopefully another would add to it, and all that. I tried rereading the book I have, but I don't get it. I need a proper know how video tutorial, and there isn't anything like that yet..

I'm checking out this host since I can't keep continuing to have a paid host as much as I want to keep it. Free hosts are usually rubbish with their pop up ads, this how ever is nice. Just too nice to be true I guess.

May be I should contact the free web host try and see if they can check out their php setup.

Edited by Html
Added a little more info.

Share this post


Link to post
Share on other sites

But if the other free host worked to get a registration for the least, as well as my paid host, then why this problem on this free host.

There's no reason to guess when there are literally error messages just waiting to tell you specifically what the problem is.

How can I be something wrong, there is no difference in the php, its all the same crap.

You're running your crap on a different environment.  There are all kinds of differences.

I need a proper know how video tutorial, and there isn't anything like that yet.

That's correct.  Every video tutorial I've seen for programming is complete crap.

May be I should contact the free web host try and see if they can check out their php setup.

They're going to tell you that the server is fine and they don't debug people's code for free.  It's the programmer's responsibility to debug their own code.

Share this post


Link to post
Share on other sites

Well I've learnt something new then, so there setup is different, and the example code I have used since I got it, is poor quality.

Do you think you could tidy any of it? You don't assist for free obviously.

I'm going to have to may be call it quits if I can't go anywhere with this.

I did take a look at the php book again 207 sessions and cookies.

This was the tutorial I viewed in Feb, having learnt from the previous video I watched last year. I was able to edit some details. So the files are all there, if you wanted to may be make it work, the account creation system using what there is there, patch it up, I'd appreciate it. I want a comment box for each account once created to post to an index, as well the ability to upload an image. But I'd be happy with just the account creation working, so once registered the page works to login to what ever account is listed on the db.

files from the uploader via site

 

Edited by Html
Added some info and link

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  

×