0

While the request completes without an error it doesn't write in the database. It connects to the database i've checked it.

This is my code:

<?php
$json = json_decode(file_get_contents("config.json"), true);
$dbuser = $json['dbuser'];
$servername = $json['dbip'];
$dbpass = $json['dbpass'];
$dbname = $json['dbname'];
$password = $_GET['password'];
$email = $_GET['email'];

// Create connection
$conn = mysqli_connect($servername, $dbuser, $dbpass);
mysql_select_db( $dbname );

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO credentials (usermail, pass)
VALUES ($email, $password)";

?>

Example: http://localhost/php/[email protected]&password=ilovestackoverflow

It just doesn't do anything. Please if you have any ideas

4
  • 1
    Hopefully you are not using this code anywhere, it's very hack-freindly. You should not pass user/pass with $_GET. mysql_ is removed from the new PHP, and your statement is injection-prone: "INSERT INTO credentials (usermail, pass) VALUES ($email, $password)"; Commented Jan 1, 2017 at 17:12
  • @Rasclatt Thank for the note. Commented Jan 1, 2017 at 17:14
  • 1
    Use $_POST, look at PDO or mysqli_, once using a new db library, prepare/bind your user input. Commented Jan 1, 2017 at 17:15
  • Solved thank you for the notes again :) Commented Jan 1, 2017 at 17:26

1 Answer 1

1

you must quote strings like:

$sql = "INSERT INTO credentials (usermail, pass)
VALUES ('$email', '$password')";
Sign up to request clarification or add additional context in comments.

2 Comments

there is no mysqli_query($conn,$sql); at the end
Solved! Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.