0

My website currently accepts email registeration(not login) . On localhost I have managed to link it to phpmyadmin. How do I create a database to accept registerations on my website.

<?php
session_start();

//connect to database

$db=mysqli_connect("IP address","user","passwd","dbname",port);
 if (isset($_POST['register_btn'])) {
 session_start();
 $username= mysql_real_escape_string($_POST['username']);
 $email= mysql_real_escape_string($_POST['email']);
 $sql="INSERT INTO users(username,email) VALUES ('$username','$email')";
 mysqli_query($db,$sql);
 $_SESSION['username']=$username;
 header("location:index.html");
}
else{
    $_SESSION['message']="Error";
}
?>
Marc Delisle
  • 8,760
  • 3
  • 27
  • 29
Anurag Bannur
  • 23
  • 1
  • 7
  • Does your website offer you a MySQL server? – Marc Delisle Jun 11 '17 at 17:51
  • Yes it does, do I just have to create a table with form inputs and connect it through php? @Marc Delisle – Anurag Bannur Jun 11 '17 at 18:45
  • On your website's MySQL server you need to create a database (usually done with your hosting control panel, or maybe via the hosting phpMyAdmin) then a table in this table. Then you need to create a PHP application that displays form inputs, receives the results and populates the table. – Marc Delisle Jun 12 '17 at 21:00
  • Yes I have done that. I created a mysql database using putty on my droplet. After which I did the following: I used the website and the database from the allotted droplet IP but didn't receive any registrations. So I connected the droplet IP database with the website running locally and vice-versa, unfortunately the website still did not accept registrations. However locally the website runs and accepts registrations. – Anurag Bannur Jun 13 '17 at 16:12
  • Unfortunately I don't know what you mean by "droplet IP database". If the website's database does not stores registrations, it could be for a number of reasons. I assume that your application is sending an INSERT command to the database, so did you check for errors after this INSERT? – Marc Delisle Jun 13 '17 at 18:52
  • A droplet is a VPS. And by droplet IP database I mean the database was on the VPS connected to my website. – Anurag Bannur Jun 13 '17 at 18:56
  • I have added the php code with the question desc now. – Anurag Bannur Jun 13 '17 at 19:10

1 Answers1

0

You can modify your code to display the MySQL error, as explained on How to display errors for my mysqli query

Marc Delisle
  • 8,760
  • 3
  • 27
  • 29