Shawn
Shawn

Reputation: 941

passing arguments through to a function - php

I have the following code that is supposed to call a function in a loop, and then pass the argument to it and put the selected items in a database. I don't think I am passing the correct arguments through to the function though, so can you have a look?

<?php

function welcome($grill){
$link = mysql_connect('localhost', 'sc2brsting', '1A2');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

mysql_select_db('sc2bring1', $link);

$sql = "INSERT INTO `sc2broad_tesing1`.`Persons` (`re`) VALUES ($grill)";

mysql_query($sql);

mysql_close($link);
}

?>

<?php

$grass=0;
while($grass<500){
$file = $DOCUMENT_ROOT . "website.com";
$doc  = new DOMDocument();
@$doc->loadHTMLFile($file);


$elements = $doc->getElementsByTagName('a');

for ($i=106; $i<=204; $i=$i+2)
  {
  $grill = $elements->item($i)->nodeValue . " ";
welcome($grill);

  }
$grass=$grass+24;
}

?>

the problem im having is that the variable $grill isn't passing through the function

Upvotes: 0

Views: 601

Answers (1)

konsolenfreddy
konsolenfreddy

Reputation: 9671

You are not escaping the variable $grill when inserting it into to database.

This will cause an MySQL error, hence the impression the argument is not passed to the function.

The line should look like this:

$sql = "INSERT INTO `sc2broad_tesing1`.`Persons` (`re`) VALUES ('".$grill."')";

Upvotes: 1

Related Questions