I'm trying to take 'username' as form input from users and insert it in MySQL database. But I'm unable to do so. Please tell me what is wrong with my code..
HTML Form:
<form method="POST" action="action.php">
<div class="row
<div class="col-md-3">
<div class="form-group">
<label>Username</label>
<input name="username" id="username" type="text" class="form-control" placeholder="Username">
</div>
</div>
<button type="submit" class="btn btn-info btn-fill pull-right">Update Profile</button>
<div class="clearfix"></div>
</form>
action.php:
<?php
$con = mysqli_connect('localhost', 'id1753243_venom', 'roushan123');
if(!$con)
{
echo 'Not connected to the server';
}
if (!mysqli_select_db($con,'users'))
{
echo 'Database not selected';
}
$username = $_POST['username'];
$sql = "INSERT INTO users (username) VALUES ('$username')";
if(!mysqli_query($con,$sql))
{
echo 'Not inserted';
}
else
{
echo 'Inserted';
}
header("refresh:2; url=user.php");
?>
When I input the form, it gives me "Not inserted" error. I tried to find a solution but failed, I was hoping some of you can look into the above code and help me out here! Thanks.
After adding some error reporting I get
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'id1753243_venom'@'%' to database 'users' in /storage/ssd1/243/1753243/public_html/login-system/action.php:20 Stack trace: #0 /storage/ssd1/243/1753243/public_html/login-system/action.php(20): mysqli_query(Object(mysqli), 'INSERT INTO use...') #1 {main} thrown in /storage/ssd1/243/1753243/public_html/login-system/action.php on line 20