 <p>Try this:</p> <pre><code>&lt;?php if ($_POST['sub']) { $server = "localhost"; $username = "yourusernamehere"; $pass = "yourpasswordhere"; $db = "users"; // Create connection $mysqli = new mysqli($server, $username, $pass, $db); // Check connection if ($mysqli-&gt;connect_error) { die("Connection failed: " . $mysqli-&gt;connect_error); } echo "Connected successfully"; $uname = mysql_escape_string($_POST['username']) $mail = mysql_escape_string($_POST['email']); $sql = "INSERT INTO users (username, email) VALUES ('$uname', '$mail')"; $insert = $mysqli-&gt;query($sql); if ($insert){ echo "Success! Row ID: {$mysqli-&gt;insert_id}"; header("Location:main.php"); } else { die("Error: {$mysqli-&gt;errno} : {$mysqli-&gt;error}"); } $mysqli-&gt;close(); } ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;form action = "" method = "POST"&gt; &lt;label&gt;Enter your Username:&lt;/label&gt; &lt;input type="text" name="username" required&gt; &lt;label&gt;Enter your Email:&lt;/label&gt; &lt;input type="email" name="email" required &gt; &lt;input type="hidden" name = "check"&gt; &lt;input type="submit" name = "sub" value = "INSERT"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <blockquote> <p>Your database name as it lookes on the third line is <code>'users'</code> and so is the name of your table that you are trying to <code>INSERT INTO</code> into <code>"users'</code> line 10. Are you sure your are not messing up there?</p> </blockquote>