PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 14, 2022

[FIXED] What mysqli value for bind_param() i or s

 September 14, 2022     bindparam, mysqli, php     No comments   

Issue

I am using mysqli bind_param() when I'm inserting stuff to my DB.

When I tried to insert a phone number as "0737327373" the value got inserted as "737327373" without the leading "0". But when I changed bind_param("i", $phoneNumber) to bind_param("s", $phoneNumber) instead the value got inserted correctly as "0737327373". So should I use "s" instead of "i" when I'm inserting numbers with a leading 0 in it?

Also, I have a value that could be anywhere between (0-5) and (0-1) depending on what select/checkboxes a user check during a registration.

Should those values also be inserted as bind_param("s") since they could be "0" as well.


Solution

If you are inserting a "number" into a varchar field then yes, use an "s".

In your case it makes no real sense to insert a phone number as an integer since you probably won't be doing any math analysis on it and you lose functionality (leading zeros, for example).



Answered By - Snowburnt
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing