Trouble with database

Hello, I am having trouble trying to insert new data into a table from my database. The problem is just that the new items don’t get inserted from my register site…

The website and the database are correctly connected to each other, this is known because I have manually inserted two users into my table to test if the login was ok, it checks that there are items with the same information and proceeds to do the login. The register is also connected to the database: If you try creating a new user with the data of the user that I created manually, it displays the error message that there is already a user with that username. So that means the problem is just with inserting values “automatically” from the register. After registring, there is the succesfull register message, but not registration is achieved.

<?php 

session_start();
require('getdata.php');
if (isset($_POST['username'])) { 

$con = mysqli_connect('localhost','id9844403_localhst','*******');

mysqli_select_db($con, 'id9844403_accounts');

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
    
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];


$s = " select * from usuarios where username = '$username'";

$result = mysqli_query($con, $s);

$num = mysqli_num_rows($result);

if($num == 1){
    echo'<style="font-family: adelle; font-size: 20px; color: #2b2b2b" href="Login.php"> Nombre de usuario ya está en uso';
}else{
$reg = 'INSERT INTO usuarios(username , email , password) VALUES ("'.$username.'", "'.$email.'", "'.$password.'")';
mysqli_query($con, $reg);
echo mysqli_query($con, $reg);
echo '<p style="font-family: adelle; font-size: 20px; color: #2b2b2b"> Registro Completado </p>';
echo '<a style="font-family: adelle; font-size: 20px; color: #2b2b2b" href="login.php">Haz click aquí para Logearte </a>';
    
    
}
}

 


?>

website: https://memeloot.000webhostapp.com/

I’ve tested your database connection and successfully connected, I’ve tested read and write permissions and managed to successfully write and remove data.

Our team would be more than happy to help you with any problem you encounter. However, we will only provide free support for our system and services. We will help you with basic problems associated with getting scripts running such as advising you of the correct hostname, username, database name and information to us, but if you need help with third-party software, contact the authors of that software or query Google with error message you get.

It is not possible for us to provide help for everyone, fix PHP errors or develop your website as it would require a lot of administrative time. We focus in getting our servers and services up and running.

However, you can upgrade your account at https://www.hostinger.com/special/000webhost and we will provide you with full help in installing your scripts, developing your website and fixing errors.

Thank you,

If you are a beginner checkout http://bitdegree.org or
https://stackoverflow.com/questions/ask to troubleshoot your code with other developers/coders etc.

The thing is that the code works in local, but after uploading it to 000webhost, it doesnt work. I have spoken to a teacher, who knows way more than I do about this. I was hoping that you would tell me there was some kind of restrictions or something that had to be enabled in order to insert items into a table

Make sure table name/row name are exactly the same, as UNIX systems are case sensitive.

1 Like

Yeah, i copied the information provided in my database manager panel fr the username, database, server and passwrd. also the table in the database is in lowercase, s that wouldn’t be the problem…

Hmm weird one, if there was anything disabled or restrictions then we wouldn’t be able to change it anyway.

php_flag output_buffering on try adding that to your .htaccess file, that is the only kind of thing I can see from checking old threads that might assist but I don’t think it will in this casse.

It was wrth tryiung, but still no… My teacher advised me it could have something t doo with concatenation, so she rewrote the INSERT line. That’s the one I poosted here. Still didnt work tho. I will try to rewrite it in as many waYS I can