0

I'm having a problem with a snippet of my code not entering data into the database. Does anyone see it? Cuz, I don't see it...

I'm using 000's free web hosting for testing purposes if that matters.

$ConnServ is included via another .PHP page and is working on multiple other requests to server. All spelling has been checked multiple times. This script worked at one point but it was a separate page. It was then consolidated onto the same page as the HTML form for 'required field' checking.

Code is throwing zero errors.

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<!-- this was included to show how the form interacts with the below code. -->
//Add Table Data
$sql = $ConnServ->prepare("INSERT INTO TestingDatabase (file,fileTwo,text,textTwo,tPos,tPosTwo,owner,createDate,invisible,tags)
VALUES (?,?,?,?,?,?,?,?,?,?)");
$sql->bind_param("ssssiissis",$fileName,$fileName2,$textinput,$textinput2,$textPos,$textPos2,$ContentOwner,$currentDate,$visState,$lineTags);
$sql->execute();
$sql->close();

//echo '<a>'. $fileName . $fileName2 . $textinput . $textinput2 . $textPos . $textPos2 . $ContentOwner . $currentDate . $visState . $lineTags .'</a>'; //<- this will echo the correct data from the form inputs if not commented out.

No data is being input into the database fields, the auto increment is not being incremented either, yet all the data seems to make it to the $sql request.

If it's something simple I'm going to bed...

Napalm
  • 1
  • 2
  • No errors you say? I suggest you read these two posts... [How to get useful error messages in PHP?](https://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) and [How to get MySQLi error information in different environments](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments) – Phil Feb 07 '19 at 02:50
  • Will do, Phil. Thanks. – Napalm Feb 07 '19 at 02:51
  • While they're not reserved words so shouldn't cause errors, I'd be wary about using the MySQL keywords `file`, `text` and `owner` as column names. One day, they may become reserved words – Phil Feb 07 '19 at 02:56
  • I'll keep this in mind. As this was my first database it's a little bit amateurish. When I decide to go live with the website I'll take this recommendation into account. Thanks! – Napalm Feb 07 '19 at 03:00
  • How did you go adding `mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);`? – Phil Feb 07 '19 at 03:41
  • 1
    Well, after trying to add the commit() command from the suggestion below it magically threw a code. Turns out that some of the fields needed default values. Something that was never required for the code to work in the past. So, magic is the reason... – Napalm Feb 07 '19 at 03:45

1 Answers1

1

You need to commit the transaction using commit()

JBurt
  • 48
  • 1
  • 5
  • 1
    From w3schools, it seems this is needed only if the auto-committing is turned off. I haven't done this. Is it still needed? – Napalm Feb 07 '19 at 03:07
  • Generally if your data shows no errors and appears to be accepted properly by the database but does not persist it is not being committed. It is worth checking in case auto correct has not been correctly setup. – JBurt Feb 07 '19 at 03:09
  • 1
    This helped throw an error. Other than that, it was unnecessary for the code to work. BUT, it helped a lot in that it finally gave me an error. Thanks, friend! – Napalm Feb 07 '19 at 03:54