-3

I'm checking my data before creating the consult.

Lines are like:

$valpar_sup_reg = isset($_POST["valpar_sup_reg"]) ? mysql_real_escape_string($_POST['valpar_sup_reg']) : 0;

I just want to control in case that there aren't data on my var's to set a 0 to all of them.

But then the consult $valpar_sup_reg gives me '' instead of 0

Okay, i've change to mysqli statements

$valpar_sup_reg = !empty($_POST["valpar_sup_reg"]) ? mysqli_real_escape_string($conn2,$_POST["valpar_sup_reg"])  : 0;

Thanks for all and the negatives :)

ntzz
  • 183
  • 4
  • 22

2 Answers2

1

1) Stop using deprecated mysql_* functions
2) isset just checks if variable is set or not & '' string will reflect true in isset function, use !empty instead.
3) You must be getting empty string i.e. '' in your $_POST use below code instead

$valpar_sup_reg = !empty($_POST["valpar_sup_reg"]) ? mysqli_real_escape_string($mysql_conn_link, $_POST["valpar_sup_reg"]) : 0;

Empty checks below for below values:
1) "" (an empty string)
2) 0 (0 as an integer)
3) 0.0 (0 as a float)
4) "0" (0 as a string)
5) NULL
6) FALSE
7) array() (an empty array)
8) $var; (a variable declared, but without a value)

Varun Krish
  • 529
  • 4
  • 14
  • I'm now using mysqli But now the escape of the $_Post is getting '' instead of the data of my database. I'd assigned the conn_link correctly. What could be happen? – ntzz Mar 14 '17 at 10:07
  • @ntzz: Did you checked your post value before & after sending it? – Varun Krish Mar 14 '17 at 10:10
  • Okay already running thanks Wrong state for mysqli conn, now works correctly. I will try to change all the mysql functions to mysqli okay? Thanks for all, and hope to dont get more negatives xD – ntzz Mar 14 '17 at 10:15
0
$valpar_sup_reg = !empty($_POST["valpar_sup_reg"]) ? mysql_real_escape_string($_POST['valpar_sup_reg']) : 0;

& as Raptor commented, better use MySQLi or PDO instead.

Hossam
  • 1,126
  • 8
  • 19