0

I have this code which ironically WORKS on another page i have but for some reason will not work with my new page even though LITERALLY its the exact same function and should work regardless but with my luck it wont so i need help, maybe i have a small error but i have compared and compared the code time and time again and theres literally no difference from what i can tell.

here is the code:

<?php

$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));   

//submission code, inserting data into mysql database   

$username = NULL;
$password = NULL;
$mySqlDate = date('Y-m-d');
$mySqlTime = date('g:i a');

if(isset($_GET['add']))
{
    $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 count(*) 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));
        }
        $length = "Remember to use lower case letters and do not use spaces";
    echo "<font size='5' color='blue'>".$length."</font> ";
    }
else
{
    $length = "Remember to use lower case letters and do not use spaces";
    echo "<font size='5' color='blue'>".$length."</font> ";
}

?>

<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
</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="add" type="submit" id="add" value="Submit">
</td>
</tr>

</table>
</form>


</html>

this is the adduser.php file
any and all help is greatly appreciated!

1
Contributor
3
Replies
30
Views
3 Years
Discussion Span
Last Post by berserk
0

OH forgot to note that it will add one entry but will only correctly add the time and date to the table with username and password being blank, then after that it will add nothing unless i delete the one added entry.

0

here is something else to add, i have been testing and found that it will actually go ahead and enter the date and time info into the database but not the username and password, it does this without even needing any information entered into the username or password fields, when u hit back it will show a new entry in the table but with no username and password but it will have date and time.. weird...

0

ok here is some more info if it helps, i have a basic setup so its very plain i just need it to work, this is my code so far but i have no idea whats wrong with it:

<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";
}

?>

thats the adduser.php

and this:

<?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>&nbsp;Data From User Submitted Data</strong>
                                &nbsp;&nbsp;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>

is my index.php why is this not working, am i missing something??

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.