-1

How to insert varchar types to mysqli database using prepare and bind.

Here is my code for prepare

$ins_filter = $con->prepare("INSERT INTO http_filter ( filter_id , filter_name , created_by , src_ip_address_from , src_ip_address_to , src_mac_address , des_ip_address_from , des_ip_address_to , des_mac_address , website_name , content_type , timestamp_start , timestamp_end , sql_q ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

to bind

$ins_filter->bind_param("isiiisiissssss",$filter_id,$filter_name, $creat_by,$sourceip,$destip,$smaf,$dia_sourceip,$dia_destip,$dmaf,$url_address,$content_type,$start_time, $end_time,$f_data_slash);
$ins_filter->execute();

Schema:
filter_id is int
filter_name varchar
creat_by is varchar
sourceip is varchar Entering ip address like 10.10.10.1 in db table returns 0 instead of ip address
destip is varchar
smaf is varchar
dia_sourceip is varchar
dia_destip is varchar
dmaf is varchar
url_address is varchar
content_type is varchar,
start_time is varchar
end_time is varchar
f_data_slash is varchar

Problem:

While inserting if text value is inserted it is stored in db, but when inserting ip address like 10.10.10.1 then 0 is stored in db.

bind_param supports 4 types
i int
d double
s string
b blob

What should I use to support for values with both integers and alphabets?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Asha N
  • 11
  • 6

1 Answers1

0

How to Insert Varchar types to mysqli database using prepare and bind

You have to use "s" type modifier for this purpose.

If this modifier is used, but 0 is still inserted, then your problem is irrelevant to prepared statements. It is either the input data, or the field type in the database which you have to double-check.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345