I have so far this script and I am aiming to run the sql insert query and fetch the results and echo some of them to appear in the web page. I want to have id and code and Period to appear in the output. Everytime, I run the script, it gives me the error message ' 0 results ' even though I checked through phpmyadmin that the query was successful and a new row was inserted as I hoped.
I copied some parts of this code from different forms, I doubt that my success key "if ($result->num_rows) {" with insert sql are not a match. Could someone help me with how to define correct success key for the insert query and help me to output the ID and CODE and PERIOD from the inserted data. Thank you very much
<?php
$servername = "localhost";
$username = "myuser";
$password = "mypass";
$dbname = "xtream_iptvpro";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$randnum = rand(1111111111111111,9999999999999999);
$ipaddress = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO codes (id,code,period,userid,statut,prixcode,ip) VALUES (null,'$randnum',365,73,0,0,'$ipaddress')";
$result = $conn->query($sql);
if ($result->num_rows) {
while($row = $result->fetch_assoc()) {
echo $row['id']." ".$row['code']."<br/>";
}
} else {
echo "0 results";
}
$conn->close();
?>
SELECTquery to get data from the database. AnINSERTdoes not return anything.