mobimobi mobimobi -5 years ago 144
PHP Question

Unable to insert rows into MySQL database using PHP-MySQLi

EDIT: Question was marked as a duplicate for asking about backticks and other things? That was not my intention. I was wondering why this specific code was not executing correctly.

Also, I have added the

into my code, however it is still not executing. I'm checking if the problem lies in connecting to the DB now.

My goal is to create a register page in which
takes inputs and adds the data to a
table through MySQLi.

The name of the table is userinfo. I have also checked config.php and verified that the password, username, and database are all correct.

is in

The relevant PHP code goes as follows:



// username and password sent from form
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$ip = mysqli_real_escape_string($db, "N/A");

//checks for different ips (no masking allowed unless u tryhard)
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
} else {
//inserts info into tables
$sql = "INSERT INTO userinfo (email, username, password, ip) VALUES ($email, $username, $password, $ip);";


All inputs on the table are text-based.

<form action = "" method = "post">
<label>Email: </label><input type = "text" name = "email" class = "box" /><br/><br />
<label>Create UserName: </label><input type = "text" name = "username" class = "box"/><br /><br />
<label>Create Password: </label><input type = "password" name = "password" class = "box" /><br/><br />
<label>Verify password: </label><input type = "password" name = "vpassword" class = "box"/><br/><br/>
<input type = "submit" value = " Submit "/><br />

Answer Source

$sql = "INSERT INTO userinfo (email, username, password, ip) VALUES ('$email', '$username', '$password', '$ip')";

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download