Chumppe Chumppe - 1 year ago 55
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="" 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>

the php..


define('SECURE', true);


$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']);



Answer Source

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

$stmt = $mysqli->prepare("INSERT INTO City (District) VALUES (?)");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download