I need help adding new users to a table i have made for an admin that can add or delete users from said table freely. What i have so far is an entry that can add date and time but for some reason it doesnt add the username and password. I dont know if its skipping the username and password and simply adding them the second you go to that page but something is wrong and i can figure this out, i have been stuck for days and what makes little sense to me is that i have this same code somewhere else but it woks there, allbeit a little different but its the same concept so then why isnt it working here??
here is the code for the adduser.php
<html>
<form method="post" action="index.php">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<div style = "margin-bottom: 100px" >
<tr width="200">
<font size="6">
Add a New User with Administrative Privileges
<br>
<br>
</tr>
</font>
</div>
<tr>
<td width="100">Username:</td>
<td>
<input name="username" type="text" id="username">
</td>
</tr>
<tr>
<td style="width:100%;" width="200">Password:</td>
<td>
<input name="password" type="text" id="password">
</td>
</tr>
<tr>
<td>
<input name="new" type="submit" id="new" value="Add User">
</td>
</tr>
</table>
</form>
</html>
<?php include('header.php');
$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));
//submission code, inserting data into mysql database
$username = "";
$password = "";
$mySqlDate = date('Y-m-d');
$mySqlTime = date('g:i a');
if(isset($_GET['new']))
{
$username = $_GET['username'];
$password = $_GET['password'];
}
//filter out non numeric and special characters
$username = mysqli_real_escape_string($con, $_GET['username']);
$password = mysqli_real_escape_string($con, $_GET['password']);
$check = mysqli_query($con, "SELECT * FROM admin WHERE username = '".$username."'") or die();
$row = mysqli_fetch_row($check);
if ($row[0] == 0)
{
$sql="INSERT INTO admin (username, password, date, time) VALUES ('".$username."','".$password."','".$mySqlDate."','".$mySqlTime."')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "false";
//$length = "Remember to use lower case letters and do not use spaces";
//echo "<font size='5' color='blue'>".$length."</font> ";
}
else
{
echo "true";
}
?>
and here is the index.php code
<?php
/*
session_start();
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] == false){
header('location: index.php');
exit();
}
*/
include('header.php');
//include('index.php');
?>
<body>
<div class="row-fluid">
<div class="span12">
<div class="container">
<br><br>
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<div class="alert alert-info">
<strong><i class="icon-user icon-large"></i> Data From User Submitted Data</strong>
Check the CheckBox then click the Delete button to Delete selected Data
</div>
<thead>
<tr>
<th></th>
<th>User Name</th>
<th>Password</th>
<th>Date Added</th>
<th>Time Added</th>
</tr>
</thead>
<tbody>
<?php
$query=mysql_query("select * from admin")or die(mysql_error());
while($row=mysql_fetch_array($query)){
$id=$row['id'];
?>
<tr>
<td>
<input name="selector[]" type="checkbox" value="<?php echo $id; ?>">
</td>
<td><?php echo $row['username'] ?></td>
<td><?php echo $row['password'] ?></td>
<td><?php echo $row['date'] ?></td>
<td><?php echo $row['time'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<input type="submit" class="btn btn-danger" value="Delete" name="delete">
</form>
<form method="post" action="adduser.php" >
<br>
<div class = "exportbtn">
<input type="submit" class="btn btn-info" value="Add New User" name="export">
</div>
</form>
</div>
</div>
</div>
</body>
</html>