0
$timeforlog = date("H:i:s");
$dateforlog = date("d/m/y");
$ip = $_SERVER['REMOTE_ADDR'];
$date = $dateforlog;
$time = $timeforlog;
$link = $actual_link;
$responsefromsite = $response;
$response = trim(preg_replace('/\s+/', ' ', $output));
$stmt = $conn->prepare("INSERT INTO logs (ondate, ontime, link, ip, response) VALUES (?,?,?,?,?)");
$stmt->bind_param("sssss", $date, $time, $link, $ip,$responsefromsite);
$stmt->execute();

Its expected to go ahead and add to the database. However despite tables being correct as shown below, it wont.

(note: the ? and t lines shown in the table was testing the queries) Table contents

Peter van der Wal
  • 11,141
  • 2
  • 21
  • 29
  • note stuff shown in db was testing the queries – crazychris Nov 29 '20 at 14:16
  • Have you got error reporting switched on? [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – Dharman Nov 29 '20 at 14:18
  • @Dharman i turned that on still no output – crazychris Nov 29 '20 at 14:24
  • Please update the question with the output of `SHOW CREATE TABLE logs` – Dharman Nov 29 '20 at 14:25
  • 1
    Are you sure this code is even executed? – Dharman Nov 29 '20 at 14:26
  • Yes i am sure it has executed – crazychris Nov 29 '20 at 14:30
  • Is there more related code before the one you've shown? It's a bit weird, you use the `$response` variable: `$responsefromsite = $response;` before it's defined on the next line. – El_Vanja Nov 29 '20 at 14:37
  • just noticed and fixed that thanks @El_Vanja but still not sending to DB – crazychris Nov 29 '20 at 14:47
  • Do a check: echo out all the values you wish to insert. Also check that the table column names are correct in your code. – SJacks Nov 29 '20 at 15:08
  • collums are correct as i tested going through and manually adding each as `t` which is shown in image attached I will now try to echo each variable – crazychris Nov 29 '20 at 15:13
  • @SJacks there is one variable it cannot echo being link which is the following however despite trying to hardcode to the word test still wont send to db ```$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";``` – crazychris Nov 29 '20 at 15:21
  • @crazychris This looks like the problem. All variables must be able to be echoed if they are to be inserted or the insert will fail. Set that link to any static value and retry the insert, it should work. Other than that, check that the column for the link on your table is set to a type of text. – SJacks Nov 29 '20 at 15:26
  • @SJacks still no luck having all as set variables however when changing direct query without variables it sends – crazychris Nov 29 '20 at 15:34

0 Answers0