Why this code is not working?


<?php

$name = $_POST['name'];

$servername = "SERVER NAME IN ORIGINAL CODE";

$username = "YE, IN ORIGINAL CODE";

$spassword = "IN CODE";

$dbname = "IN CODE";

$conn = new mysqli($servername, $username, $spassword, $dbname);

if ($conn->connect_error) {

die("failed" . $conn->connect_error);

}

$sql = "SELECT reg FROM accounts WHERE name = '$name'");

die($conn->query($sql));
?>

How it doesn’t work?

3 Likes

He probably get error 500

4 Likes

the original code doesnt have the )

Yes it does. Look back at the code you pasted when you created the topic, the right parenthesis is visible.

4 Likes

I don’t know what’s happening here…
start by removing the end-parenthesis from the line where you set $sql
and then also remove the extra end-parenthesis from the die() call below that.

4 Likes

ive removeed the ) now. It still doesnt work.

Can you re-paste the code here? This time, show all the database information except the password.

Thanks!

4 Likes
<?php
$name = $_POST['name'];
$password = $_POST['password'];
$servername = "sql213.epizy.com";
$username = "epiz_32450514";
$spassword = "/**/";
$dbname = "epiz_32450514_accounts";

$conn = new mysqli($servername, $username, $spassword, $dbname);
if ($conn->connect_error) {
  die("connection failed" . $conn->connect_error);
}
$sql = "SELECT reg FROM accounts WHERE name = '$name'";
$result = $conn->query($sql);
die($result);
?>

What is the error now? That code is valid… (but it is highly susceptible to SQL injection)

1 Like

It shows “HTTP ERROR 500”

Can you turn on error messages?

In the control panel, look for PHP Config (Or something similar), select your domain name, and turn on PHP errors.

What error are you getting?

5 Likes

Fatal error : Uncaught Error: Object of class mysqli_result could not be converted to string in /home/vol2_5/epizy.com/epiz_32450514/htdocs/register/submit.php:15 Stack trace: #0 {main} thrown in /home/vol2_5/epizy.com/epiz_32450514/htdocs/register/submit.php on line 15

1 Like

Maybe this will be useful to you

6 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.