Prepared statement help needed

<?php
session_start();
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";

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

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


if(isset($_POST['submit_btn1']))
{

$name=$_POST['name'];
$mobile=$_POST['mobile'];
$gender=$_POST['gender'];
$address=$_POST['address'];
$city=$_POST['city'];
$expireance=$_POST['EXPERIANCED'];
$subscribtion=$_POST['subcribed'];



$empcode=$_SESSION['edit'];


$query=conn->prepare("UPDATE employee SET name=?, gender=?,mobile=?,address=?,city=?,expireance=?,subscribtion=? WHERE emp_code=?;");
$query->blind_param('ssssssss',$name,$gender,$mobile,$address,$city,$expireance,$subscribtion,$empcode);
$query->execute();






if ($conn->query($query ) ===TRUE) {
    header("location: employee_edit.php");
} else {
	
    echo "Error: " . $query  . "<br>" . $conn->error;
}
$conn->close();
}


	
	




?>

hey guys i am new to php and i need help at line no 35 please help me out :frowning:

Do you see a problem here?
(Also, use the code tags when you post code.)

1 Like

As you don’t get an error for that mistake, i would say your script is misconfigured, just add

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

What is the error? Without that, it’s not worth going line by line to figure out the problem.

I think this will solve your problem.

//binder function
function bindParameters(&$statement, &$params)
{
  $args   = array();
  $args[] = implode('', array_values($params));

  foreach ($params as $paramName => $paramType)
  {
    $args[] = &$params[$paramName];
    $params[$paramName] = null;
  }

  call_user_func_array(array(&$statement, 'bind_param'), $args);
}

// Usage:
$statement = $database->prepare('INSERT INTO test (value1, value2) VALUES (?, ?)');
$params    = array('param1' => 's',
                   'param2' => 'i');

bindParameters($statement, $params);

$params['param1'] = 'parameter test';
$params['param2'] = 42;

$statement->execute();
Sponsor our Newsletter | Privacy Policy | Terms of Service