1

I'm making a VERY basic ticket system. Where basically if an SQL query or something doesn't run properly. It will insert a few bits of data into a MySQL table so the admin can run through and see what has happened and try to fix it.

<?php
$stamp = gettimestamp();
$error = $db->error;
$page = basename($_SERVER['PHP_SELF']);
echo "Error Updating! Please contact your IT Admin Team!";
echo "Stamp: ".$stamp;
echo "Error: ".$error;
echo "Page: ".$page;
echo "Email: ".$email;

$ticketSQL="INSERT INTO `db744544270`.`supportTickets` (`timestamp`, `problem`, `page`, `user`) VALUES ('$stamp', '$error', '$page', '$email')";
  if ($db->query($ticketSQL) === TRUE) {
            echo '<script>alert("Record Upated!");</script>';
            header( "refresh:5;url=index.php" );
            //var_dump($sql);
            //echo "<script>location.href = 'index.php';</script>";
        } else {
          echo "Error AGAIN!";
        }
?>

Above is the code I am running and basically I have put this into a file and just include that file on every page where I need it. For example inside the error handling of an if statement. If query TRUE-> YAY, else query FALSE->include ticket page.

Like I said...very basic.. Whenever I run the page and at the moment I am getting an error from another query but that's a question for a different time :) this is the current error i get...

Error updating record: Unknown column '1' in 'where clause'
Fatal error: Call to undefined function gettimestamp() in /homepages/38/d735513801/htdocs/includes/supportTicket.php on line 2

I have no idea why it is saying it's undefined. I have tried changing the type and everything. It just will not insert into the table, I feel like I'm being stupid but I can't see why it's not working...

rkta
  • 3,959
  • 7
  • 25
  • 37
  • 2
    Where do you define the `gettimestamp()` function? It is not a native PHP function. – rickdenhaan Jul 07 '18 at 11:15
  • To be clear: your question is only about the `Call to undefined function gettimestamp() `? And not about everything else below the second line of your code? – Ivar Jul 07 '18 at 11:18
  • Prevent SQL injection must read https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1 – Raymond Nijland Jul 07 '18 at 11:31
  • `Error updating record: Unknown column '1' in 'where clause'` ... Non off your current pasted code will trigger this error.. We want the code of the gettimestamp() function but likely you don't have it.. `Call to undefined function gettimestamp() in /homepages/38/d735513801/htdocs/includes/supportTicket.php on line 2` – Raymond Nijland Jul 07 '18 at 11:34
  • This doesn't directly answer your question, but why not just implement a logging library or system and throw exceptions at it? All the hard work done by someone else, you just need to throw data at it as required – James Jul 07 '18 at 13:58

0 Answers0