Chumppe Chumppe - 2 months ago 7
MySQL Question

Inserting into database gives me "localhost not working"

I'm trying to insert information into database through two inputs when you click a submit button. But when I click it it says it can't connect to localhost (everything else works so I know it has to be some form of syntax problem) Code:

<form action="prices.inc.php" method="post">
<input class="price-list-input" type="text" id="priceupdate1" name="priceupdate1" required></input>
<input class="price-list-input2" type="text" id="priceupdate2" name="priceupdate2" required></input>
<input class="price-list-button" type="submit" id="priceupdate-button" name="priceupdate-button" value="Uppdatera"></input>
</form>


the php..

<?php

require_once('check_login.inc.php');
define('SECURE', true);
require_once('connection.php');


if(isset($_POST['priceupdate-button'])){

$info = trim(htmlspecialchars($_POST['priceupdate1'], $_POST['priceupdate2']));

// prepared statement
$stmt = $db->prepare('INSERT INTO prices (name, price) VALUES = (?, ?)');
$stmt->bind_param('ss', $_POST['priceupdate1'], $_POST['priceupdate2']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($info);

}

?>

Answer

GOT IT WORKING.. all that was the problem was the "=" that @Fred-ii- mentioned.. – Chumppe

Posting as a community wiki. I don't want rep for this but just to close the question.

As I said in comments, VALUES = (?, ?) the equal sign shouldn't be there.

Example from the manual http://php.net/manual/en/mysqli.prepare.php

$stmt = $mysqli->prepare("INSERT INTO City (District) VALUES (?)");