Postingan lainnya
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
1
1 Jawaban:
tambahkan global $link didalam fungsi <pre> function addinfo($page5) { global $link;
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 ?
}
}
} </pre>
0
Tanggapan
Terima kasih atas masukkan dan saran nya.
jadi udh solved?
sedang di coba-coba..