-2

I have been struggling for about a week now and still have not got any results. I have read the following questions:

I tried everything suggested in the above questions' answers. After reviewing my code, if you still think that the above questions' solution relates then please do tell.

My code -
connect.php -

<?php 
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "practice_user";

// Create connection
$con = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($con->connect_error) {
    echo "Connection failed: " . $con->connect_error;
} 
 else {
   echo "Success"; 
}

//Insert data into database
$sql = "INSERT INTO simple_login (name,email) VALUES('{$mysqli->real_escape_string($_POST['name'])}','{$mysqli->real_escape_string($_POST['email'])}')";


$insert = $mysqli->query($sql);

if(!$insert)
{
   echo $mysqli->error;
}



$mysqli->close();


register.html -

<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
       <form action="connect.php" method="post">
        Name: <input type="text" name="name"><br>
        E-mail: <input type="text" name="email"><br>
        <input type="submit" value="Submit" name="submit">
       </form>
    </body>
</html>


As usual I am getting a "Successful" message for connection. Also it is not outputting any error message(if I have not appropriately tried to output insertion error in the given code, please do tell in the comments).

Thank you in anticipation.

Community
  • 1
  • 1
Niraj Pandkar
  • 163
  • 4
  • 15

1 Answers1

2

I'll post this here, we all make mistakes so don't worry! As suggested your $mysqli function is undefined, you've stored your mysqli instance as the $con variable, so you should refer any mysqli functions on that.

Examine http://php.net/manual/en/mysqli.query.php for more information!

skh
  • 396
  • 6
  • 17
  • Yes I got that. Thank you very much. I should have tried harder and not asked this actually. – Niraj Pandkar Jun 22 '15 at 13:11
  • Not a problem, happens all the time! It's good to get other peoples eyes on things after staring at them for so long. Obvious issues are always the easiest to miss! :-) – skh Jun 22 '15 at 13:18