I have a file called functions.php which contains many functions, now what i want to do is store whatever those functions return in a database. What i am currently doing is that i am starting a database connection in every function and closing it as well in every connection. Which what it does it that, it stores the data in database but it also increments the rows in my database. each value returned by a function is being stored in a different row. I want them to be in the same row. What should i do? This is my code so far,
function h3() {
$con=mysqli_connect("localhost","root","","fyp");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$url=$_POST["urlo"];
$counter = 0;
include_once('simple_html_dom.php');
$html = file_get_html($url);
foreach($html->find('h3') as $element){
$counter++;
}
echo $counter;
mysqli_query($con,"INSERT INTO results(h3) VALUES ('$counter')");
mysqli_close($con);
}
function paragraph() {
$con=mysqli_connect("localhost","root","","fyp");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$url=$_POST["urlo"];
$counter = 0;
include_once('simple_html_dom.php');
$html = file_get_html($url);
foreach($html->find('p') as $element){
$counter++;
}
echo $counter;
mysqli_query($con,"INSERT INTO results(p) VALUES ('$counter')");
mysqli_close($con);
}