I have set up a simple site that allows the user to login and register. I'm using a MySQL database to store the login details in the columns of a table. I will provide more details, but basically, I have gotten the login page to work, it connects to the database properly and either logs in or notifies the user that their login details are invalid. My problem is that the register page won't register users. I'm not extremely good at php but I am decent at it, I was able to make the login page work and I have done research and can't figure out why the register page won't work.
Code I used to create my database:
CREATE TABLE `users` (
`id` INT NOT NULL auto_increment ,
`username` VARCHAR( 20 ) NOT NULL ,
`password` VARCHAR( 20 ) NOT NULL ,
`fullname` VARCHAR( 20 ) NOT NULL ,
`email` VARCHAR( 20 ) NOT NULL,
`ip` VARCHAR( 20 ) NOT NULL,
PRIMARY KEY ( `id` )
)
Code I used to connect to the database and register: (It is messy & simple, keep in mind that all I am trying to do is have it inject into the db properly, once I have gotten that down, I can easily add a lot more)
FYI, I changed the actual details for connection to my MySQL server to fake stuff for the purpose of this post. For me I have the real details, and it does successfully connect and the login script works, just not the register script. The issue is not that it won't connect, it's just that it won't inject the user submitted info into the respective columns in the table "users". Also, I cut out the part with the if statements for the submit button being pressed and etc, because again those parets aren't related to the problem.
<?php session_start(); ?>
<?php
ob_start();
//Defining server variables
$host ="000webhost.com";
$username ="username1";
$password ="pass1";
$db_name = "database1";
$tbl_name ="users";
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define register variables
$myusername=$_SESSION['myusername'];
$mypassword=$_SESSION['mypassword'];
$myemail=$_SESSION['myemail'];
$myname=$_SESSION['myname'];
$myip=$_SERVER['REMOTE_ADDR'];
$sql="INSERT INTO users (username,password,fullname,email,ip)VALUES('$myusername','$mypassword','$myname','$myemail','$myip')";
$_SESSION['registersuccess'] = "Registration success"
header('location:index.php');
ob_end_flush();
?>
?>
I'm obviously do something wrong because when I run this code on my MySQL query than it injects into the table but when I try use php for it than it doesn't. Not sure what I am doing wrong, that is where I need the help. Thanks in advance, and any help would be very greatly appreciated.