Derikoe Derikoe - 3 months ago 8
PHP Question

Can't seem to get query to work?

<?php
error_reporting(E_ALL);

session_start();

include ('connect.php');

if(!empty($_POST['budgetbox']))
{
$budgetboxvar = $_POST['budgetbox'];

$sql="INSERT INTO users WHERE username = '".$_SESSION['usernamebox']."'(budget) VALUES ('$budgetboxvar')";


mysqli_query($db,$sql);


}
?>


Does anyone have an idea why the code above doesn't work ? It seems like the code works if I leave the code below out. I'm sorry but I can't seem to figure out how this is not correct ? I'm not getting any error messages either.

When I take out the
WHEN username is SESSION usernamebox
part out.. the query does input into my database, only not in the field of a logged in user..

I tried to echo something if the query succeeded but it doesn't show anything either.. Which means the query can't be executed (I think). Can't figure out why though(it's hard being a noob sometimes)

Thank you in advance, hope you can help !

Answer
if(!empty($_POST['budgetbox']))
{

$query = $db->prepare("UPDATE users SET budget=? WHERE username=?"); ///statements voorbereiden

$budgetboxvar = $_POST['budgetbox'];
$name = $_SESSION['usernamebox']; //var toekennen

$query->bind_param("ss", $budgetboxvar, $name);
$query->execute();
echo"Thank you for entering your budget!";  
}

And.. i changed the database column "budget" to VARCHAR64

Comments