Function php 7

Dear Master PHP,

Mau bertanya dong pada PHP 5 function di bawah ini dapat berjalan dengan baik. Namun pada saat saya update PHP 7 selalu gagal di eror : "Can\'t insert into hits : "

function addinfo($page5)
{
	if(mysqli_num_rows(mysqli_query($link,"SELECT page FROM hits WHERE page = '$page5'")))
	{
	//A counter for this page  already exsists. Now we have to update it.

		$updatecounter = mysqli_query($link,"UPDATE hits SET count = count+1 WHERE page = '$page5'");
		if (!$updatecounter)
		{
		die ("Can't update the counter : " . mysqli_error($link)); // remove ?
		}
	}
	else
	{
	// This page did not exsist in the counter database. A new counter must be created for this page.

		$insert = mysqli_query($link,"INSERT INTO hits (page, count)VALUES ('$page5', '1')");

		if (!$insert)
		{
    		die ("Can\'t insert into hits : " . mysqli_error($link)); // remove ?
		}
	}
}

Mohon bantuan nya ya master.

Terima kasih

avatar FitriR
@FitriR

109 Kontribusi 2 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

tambahkan global $link didalam fungsi <pre> function addinfo($page5) { global $link;

if(mysqli_num_rows(mysqli_query($link,&quot;SELECT page FROM hits WHERE page = &#039;$page5&#039;&quot;)))
{
//A counter for this page  already exsists. Now we have to update it.

	$updatecounter = mysqli_query($link,&quot;UPDATE hits SET count = count+1 WHERE page = &#039;$page5&#039;&quot;);
	if (!$updatecounter) 
	{
	die (&quot;Can&#039;t update the counter : &quot; . mysqli_error($link)); // remove ?
	}	
} 
else
{
// This page did not exsist in the counter database. A new counter must be created for this page.

	$insert = mysqli_query($link,&quot;INSERT INTO hits (page, count)VALUES (&#039;$page5&#039;, &#039;1&#039;)&quot;);

	if (!$insert) 
	{
		die (&quot;Can\&#039;t insert into hits : &quot; . mysqli_error($link)); // remove ?	
	}
}

} </pre>

avatar dianarifr
@dianarifr

642 Kontribusi 316 Poin

Dipost 4 tahun yang lalu

Tanggapan

Terima kasih atas masukkan dan saran nya.

jadi udh solved?

sedang di coba-coba..

Login untuk ikut Jawaban