php - Posting into database using mysqli -


i learning php , trying make following work:

<?php require_once("db_connect.php");      // todo - check connection successful.      $dname = $_post["dname"];     $daddress = $_post["daddress"];       $stmt = $mysqli->prepare("insert test (dname, daddress) values (?, ?)");      // todo check $stmt creation succeeded      // "s" means database expects string     $stmt->bind_param("s", $dname, $daddress);      $stmt->execute();      $stmt->close();      $mysqli->close(); ?> 

it works 1 bind_param not 2. if $daddress removed code posts. form has 26 posts database doing 2 @ moment keep minimal.

i following error when form submitted.

warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: number of elements in type definition string doesn't match number of bind variables in /home/mymotorsportco/public_html/entry/actions/entry.php on line 15

as per php manual:

types

a string contains 1 or more characters specify types corresponding bind variables

i - corresponding variable has type integer

d - corresponding variable has type double

s - corresponding variable has type string

b - corresponding variable blob , sent in packets

you have add types parameters binding. if second parameter string, have do

$stmt->bind_param("ss", $dname, $daddress); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -