0

This is the login form, when i want to login it doesn't work but some days it works, first i used maysql function for connecting to data base and it shows http error

sasan
  • 1
  • 1
  • 2
    Please complete a basic, recent PHP+MySQL tutorial before you put anything online. You're not secured against sql injection at all and you don't even hash your users passwords. This is a dream for somebody who wants to steal data. – LLJ97 Aug 23 '19 at 11:34
  • 1
    `mysqli_connect("localhost"` <-- are you **sure** your DB is on the localhost of your web server ? – Cid Aug 23 '19 at 11:41
  • yes These codes have worked well so far – sasan Aug 23 '19 at 11:50
  • I highly doubt that if you put this on a server you can create a database connection to `localhost`. At least on my site I had to put in the address of a database that was online. – LLJ97 Aug 23 '19 at 11:55
  • Welcome to StackOverflow, please don't "blockquote" all of the text of your question. Blockquotes serve they're own purpose. – Airn5475 Aug 23 '19 at 12:31
  • @LLJ97 You often have to use localhost on servers, thats fine. – Manuel Mannhardt Aug 23 '19 at 12:44
  • Okay, maybe I have just not ran into a situtation where I had to do that. My bad:) – LLJ97 Aug 23 '19 at 12:49

2 Answers2

0

The problem is you are trying to connect "localhost" on your server. $con=mysqli_connect("localhost","example.com","password");

You should re-write your connection line as;

$con = mysqli_connect('example.com', 'username', 'password', 'DatabaseName');

For some host servers, it can creates an error because of your hostname(example.com) if you get this error after re-write your connection code then please try to write your site's IP Address instead of it's name. Then It will work.

  • i try with my hostname and my site ip and delete if but it doesn't work and it goes on a blank page – sasan Aug 23 '19 at 20:19
0

You need to find out the error just by error reporting. Second you also need to define die(); after mysqli query to show if their is problem in the query.

Sorry I can't paste code I am from mobile

ZaHid
  • 81
  • 8
  • i have used die but there is not any error , i say again this code have worked fine – sasan Aug 24 '19 at 11:49
  • What it shows I mean error or what ? Is it showing page.php in header , and I am saying again put the error reporting E All code above the page. – ZaHid Aug 24 '19 at 12:36
  • i put error error_reporting(E_ALL); but there is no error – sasan Aug 24 '19 at 18:26
  • Seems like you are too new, Some times only error_reporting(E_ALL); not working, what if error reporting is not set from your configuration, So put ini_set("error_reporting", E_ALL); as well on the top. And try try again – ZaHid Aug 24 '19 at 19:09