0

For the life of me, I cannot figure out why this is happening. I tried typecasting I've tried using built-in parsing functions (intval), and I have tried using string replace methods, but no matter what I do, my $AccountNum returns "1" and after "parsing" it turns into a 0.

I don't have much experience in custom programming on WordPress and am hoping someone here might know where the problem lies. Below is the WordPress page I am trying to implement, and below that is the portion of functions.php that I added on to, which is being implemented, and the last bit is my output.

Please help!

[vc_row][vc_column][vc_column_text][insert_php]

if ($_POST['submit']) {

saveAccountNum($_POST['email'], $_POST['password']);

echo $AccountNum;

get_all_user_info((int)$AccountNum);


}

[/insert_php][/vc_column_text][/vc_column][/vc_row]

part 2 (functions.php script)

function get_all_user_info($AccountNumber){

    global $AccountNum;

    $dbhost = "localhost";
    $dbuser = "#######";
    $dbpass = "#######";
    $db = "#######";
    $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);


    echo $AccountNumber;
    $userData = "CALL get_all_user_info("+$AccountNumber+")";
    $sql = mysqli_query($conn, $userData);

    global $First_Name;

        if(!$sql){
          die("Didn't work, here's why: " . mysql_error());
        }
        else{
         $object = $sql->fetch_object();
         $First_Name = $object->First_Name;
         echo "All variables made: " .$First_Name;
        }
$conn->close();
 }

part 3 (output)

Changed variable name: ‘1”1’0All variables made:

As you can see, It doesn't give me any errors, but the error arises when I try to parse from a string to an int. This happens whether I try typecasting, or calling functions, and to be honest, I am out of ideas as to why. Any help would be much appreciated.

2
  • Not a PHP expert here, but why do you declare a global variable in a function - even more, after a variable with the same name is used in the parent scope? Commented Apr 27, 2018 at 6:32
  • I'm referencing it from the header.php file in wordpress. I can try to make it all within one page, but it would be all the same. This is for a school project to demonstrate some database design, I just found that this looks cleaner. Commented Apr 27, 2018 at 6:34

1 Answer 1

-1

Try this references links

http://php.net/manual/en/function.intval.php

https://stackoverflow.com/questions/7008214/php-string-to-int

https://stackoverflow.com/questions/8529656/how-do-i-convert-a-string-to-a-number-in-php


 $myVar = "13";
 var_dump($myVar); // string '13' (length=2)
 $myVar= intval($myVar);
 var_dump($myVar); // int 13

  $myVar = "13";
  var_dump($myVar); // string '13' (length=2)
  $myVar= (int)$myVar;
  var_dump($myVar); // int 13
Sign up to request clarification or add additional context in comments.

Comments

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.