0
 $q2=$_REQUEST['binge'];
'book2'=>array('callno'=>123006,'price'=>number_format(844,2),'desc'=>'Binge','auth'=>'Tyler Oakley','quant'=>$q2,'total'=>number_format(844,2)*$q2)

On this particular code, It kept displaying errors like this

Warning: A non-numeric value encountered in C:\xampp\htdocs\Webcard_3new\Webcard\wishlist.php on line 97

I searched all over the net for finding the right answers but some are just so complex to understand...

It supposed to be that $q2 is the variable inside an array. That variable is then multiplied to the "TOTAL". but the errors kept on going.. please help!!

5
  • Can you show us the output of $q2? var_dump($q2); Commented Apr 20, 2017 at 14:10
  • I think instead of 'book' => you should write $book = Commented Apr 20, 2017 at 14:11
  • I just tested this code and works: $q2= "100"; $book2 = array('callno'=>123006,'price'=>number_format(844,2),'desc'=>'Binge','auth'=>'Tyler Oakley','quant'=>$q2,'total'=>number_format(844,2)*$q2); var_dump($book2); Commented Apr 20, 2017 at 14:14
  • @Hackerman What did you get? Commented Apr 20, 2017 at 14:14
  • i used the is_numeric function Commented Apr 20, 2017 at 15:45

2 Answers 2

4

The super-globals will always be strings. You need to explicitly convert them using intval():

$q2 = intval($_REQUEST['binge']);

Also, this line:

'book2'=>array...

Should be

$book2 = array...
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the recommendation... I just found the error and I just fixed it a while ago.. Maybe ill use this in other projects..
0

You can use

$q2 = filter_var($_REQUEST['binge'], FILTER_VALIDATE_INT);

here you will have the benefit of validation where false is returned when someone passes a value that is not an integer. If it is instead a float use FILTER_VALIDATE_FLOAT instead.

Also, consider using $_GET, or $_POST directly to have more control of the data channel. $_REQUEST cobbles together several things into one, which sometimes may cause issues when more than one channel have the same key.

1 Comment

ok thanks for the recommendation... I already found it.. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.