php - Very simple insert function, no data get's stored and no errors received -
i'm trying add button generates dummy data table 1 click
<?php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); include("classes/db.class.php"); $currenttime = time(); $totalusers = '20000'; $usersus1 = '5000'; $usersus2 = '5263'; $usersfr1 = '8000'; $usershk1 = '7425'; $usersuk1 = '0'; if(!empty($_post)) { $currenttime = time(); $db = new db(); $sql = "insert connections (users, us1, us2, fr1, hk1, time, uk1) values ('".$db->conn->real_escape_string($totalusers) ."' , '". $db->conn->real_escape_string($usersus1) ."' , '". $db->conn->real_escape_string($usersus2) ."' , '". $db->conn->real_escape_string($usersfr1) ."' , '". $db->conn->real_escape_string($usershk1) ."', '". $db->conn->real_escape_string($currenttime) ."', '". $db->conn->real_escape_string($usersuk1) ."')"; $result = $db->conn->query($sql); return $result; } ?>
however everytime press button, receive 0 errors , nothing gets stored in db.
the php code , html on same page.
does know what's causing problem?
edit:
db class:
<?php class db { private $m_shost = "localhost"; private $m_suserlogin = "root"; private $m_spassword = "root"; private $m_sdatabase = "radius"; public $conn; public function __construct() { $this->conn = new mysqli($this->m_shost, $this->m_suserlogin, $this->m_spassword, $this->m_sdatabase); } } ?>
and form use post:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>screen wall</title> <link rel="stylesheet" type="text/css" href="styles/style.css"> <!--<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>--> <script src="scripts/d3-3.5.2/d3.js"></script> </head> <body> <p> current timestamp:<?php echo time(); ?> </p> <form method="post"> <input type="text" required="required" name="titel" value="test field :)"> <button type="submit" id="generatebtn">add data</button> </form> </body>
again, html , php on same page.
first thing first: should not using real_escape_string
since input not user whereas hard coded in code itself.
secondly alternative way rectify issue can use
if (!mysqli_query($db->conn,$sql)) { die('error: ' . mysqli_error($con)); } echo "1 record added";
instead of
$result = $db->conn->query($sql);
hope helps.
thank you
Comments
Post a Comment