i cant get any of my php code to connect to the mysql to put any data there how can i do?
First your need to connect to MySQL. You can find several simple to follow tutorials on internet e.g. PHP MySQL Connect to database
You can find MySQL credentials in your profreehost dashboard.
i have alreddy tried but it didnt work, so i am trying to find help here because it doesnt seem to be an issue with the code but rather the conectivity between the php and mysql
Can you share your connection code here?
ye. everything works as intended but it gets an error
<?php // Creates connection $conn = new mysqli($servername, $username, $password, $dbname); //private data // Checks connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); echo "Connection failed"; } $un = $\_POST\['username'\]; $pwd = password_hash($\_POST\['password'\], PASSWORD_DEFAULT); $mail = $\_POST\['mail'\]; $sql = "INSERT INTO users (username, password, mail) VALUES ('$un', '$pwd', '$mail')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; header("Location: ../"); } else { echo "Error: " . $sql . "" . $conn->error; } $conn->close(); ?>
edit: coud the issue be because of the sql or is it the code.
Can you double check a few things in your ProFreeHost dashboard? First, make sure your $servername isn’t set to ‘localhost’; it usually needs to be the specific DB host address provided in your control panel. Also, ensure your $dbname includes the full prefix. Finally, since you are using password_hash, check that your password column in MySQL is set to VARCHAR(255). If the column is too short, the query will fail silently because the hash is being cut off.
i alreddy did all that, still isnt working. i might need to re check the server name and db name and all that because who knows, i might have messed something upp there
so i checked the thingy and i realised a massive issue, i have everything in the same folder but in the php the file it has the “header(“Location: ../”)“ and because it has 2 dots it tries sending me back by 2 files. thats whats causing the issue and now everything is working as intended.
im sorry i wasted time, but i got things working
top tier patience btw, 10/10
This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.