Having trouble with procedural use of mysqli
Here\'s the function:
db.php
Since $link
is being define in db.php probably you should
require db.php;
in function.php file
`enter code here`
need
<?php
function addItemToCatalog($var1, $var2, $var3, $var4) {
$sql = 'INSERT INTO catalog (var1, var2, var3, var4, $link)
VALUES (?, ?, ?, ?)';
end
<?php
require_once ("db.php");
require_once ("function.php");
$var1 = $_POST['var1']; //showing without filtering methods
$var2 = $_POST['var2'];
$var3 = $_POST['var3'];
$var4 = $_POST['var4'];
if(!addItemToCatalog($var1, $var2, $var3, $var4, $link)){
echo 'some error text';
The way the two files db.php
and function.php
are glued together I think results in $link
being defined as a global variable - you need to use global to access it within function:
function addItemToCatalog($var1, $var2, $var3, $var4) {
global $link;
...
}
or give the $link
to the function explicitly through parameter:
function addItemToCatalog($var1, $var2, $var3, $var4, $link) {
...
}