0

Php insert data to sql DB failed

Dear Community I try to make a reading php file in which I can simply enter my reading data. Sadly, there is something wrong with my Code. Can someone help me please? I think I just oversaw something little. I just get the "Connection sucessfully" message when I sent the data. Thank you all for your help. Kind regards Tech https://code.sololearn.com/wx7Viit129Ig/?ref=app https://code.sololearn.com/wv56w6aBwp45/?ref=app https://www.sololearn.com/post/1583424/?ref=app

19th Mar 2022, 12:27 PM
Tech
2 Réponses
+ 1
Hello Tech, 1. In db_connect.php at line 8: A connection attempt is established and <$conn> is the connection object returned. $conn = new mysqli($servername, $username, $password, $dbname); But in reading.php you use <$dbh> instead of <$conn> for statement preparation (at line 45). Did you declare <$dbh> somewhere else in the code, maybe in another included file? or was it a typo? $stmt = $dbh->prepare($sql); 2. In db_connect.php line 11 Perhaps you want to use `$conn -> connect_errno` instead of `$conn -> connect_error` (https://www.w3schools.com/PHP/func_mysqli_connect_error.asp) if($conn -> connect_errno) 3. In reading.php. I'm not familiar with the way you use parameter placeholders (line 44), and how you bind parameters (line 46 ~ 49). It looks different to the example given in PHP manual page (https://www.php.net/manual/en/mysqli.prepare.php). Perhaps it's a new way I'm not aware of Idk ...
19th Mar 2022, 2:52 PM
Ipang
0
Thanks Ipang These typos are solved now, but the insert isnt there. "Connection sucessfully" nothing more.
19th Mar 2022, 6:02 PM
Tech