Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument 1 passed to myFunction() must be an instance of string, string given, called in

i have this function:

function myFunction(string $name) {
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db(...); 

    $insertplayer="INSERT INTO `...`(....)
    VALUES (......')";
    if (!mysql_query($insertplayer,$db))
      {
      die('Error: ' . mysql_error());
      }
    $id = mysql_insert_id();
    echo 'done for player N°'.$id;
    mysql_close($db);
}

and the form i use:

<form action="insertplayer.php" method="post">
    <input type="text" name="nameplayer" />
    <input type="submit" value="ok" />
</form>

But when i do this, i have this error:

Catchable fatal error: Argument 1 passed to myFunction() must be an instance of string, string given, called in C:.... on line 23 and defined in C:...

I have this error with the int problem. How can i resolved it ?

like image 841
user3414480 Avatar asked Mar 13 '14 16:03

user3414480


1 Answers

Try removing the primitive data type from the function declaration. PHP does not require type hints for primitive data types.

function myFunction($name) {
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db(...); 

    $insertplayer="INSERT INTO `...`(....)
    VALUES (......')";
    if (!mysql_query($insertplayer,$db))
      {
      die('Error: ' . mysql_error());
      }
    $id = mysql_insert_id();
    echo 'done for player N°'.$id;
    mysql_close($db);
}
like image 85
Deep in the Code Avatar answered Oct 19 '22 05:10

Deep in the Code