0

I have this prepared statement and it isn't inserting into the table at all. The connection to my database is working. I am still new to this so I am unsure on what is wrong. The spelling of my table is correct also. My network tab on inspect element doesn't show any errors as if it did insert the data but the table doesn't update with said data.

$stmt = $conn->prepare("INSERT INTO usersreports (DateOfReport,Username,ReportedPostId,ReportedUser,ReportedUserId,ReportedReason,ReportedTopic,Resolved,Response,ActionTaken) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

$stmt->bind_param("ssssssssss", $DateOfReport,$YourUsername,$UsersPostId,$ReportedUsername,$ReportedUserId,$ReportReason,$ReportTopic,$Resolved,$Response,$ActionTaken);
 if ( $stmt === false ) {
        echo $conn->error;
        exit;
    }
$stmt->execute();
$stmt->close();
$conn->close();
  • Try it with hardcoded parameters first – symlink Jul 06 '19 at 06:36
  • do you mean like ` $sql = "INSERT INTO usersreports (DateOfReport,Username,ReportedPostId,ReportedUser,ReportedUserId,ReportedReason,ReportedTopic,Resolved) VALUES ('$DateOfReport','$YourUsername','$UsersPostId','$ReportedUsername','$ReportUserId','$ReportReason','$ReportTopic','$Resolved');"; mysqli_query($conn, $sql); ` because it works like this – AustinVD1998 Jul 06 '19 at 06:38
  • 1
    Yes, that's what I mean. Since that works, you know there is a problem with one of your variable values. Have PHP echo them out and see if any of them look funny. – symlink Jul 06 '19 at 06:40
  • @symlink Do you know what you just recommended to the OP? You told him to break the code even more. – Dharman Jul 06 '19 at 11:14
  • Possible duplicate of [How to get MySQLi error information in different environments? / mysqli\_fetch\_assoc() expects parameter 1 to be mysqli\_result](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments-mysqli-fetch-as) – Dharman Jul 06 '19 at 11:15
  • @Dharman I was telling him to put it in quotes for testing purposes – symlink Jul 06 '19 at 17:48
  • I know, but you inadvertently suggested him a terrible solution. – Dharman Jul 06 '19 at 17:49
  • @AustinVD1998 Remember to take the parameters out of the quotation marks when you're done, that was just for testing purposes. Ultimately you need to fix the variable values so your SQL language accepts them. – symlink Jul 06 '19 at 17:49
  • @Dharman If he's not even testing the data in his database and doesn't know the difference between variables and dummy data, he's such a beginner that it will be hard to recommend anything, but I did just leave him another comment explaining it was for testing only. – symlink Jul 06 '19 at 17:51
  • @Dharman anyway, thanks for the heads up – symlink Jul 06 '19 at 17:55
  • I understand the difference between the two, that's why I'm changing to prepared statements. – AustinVD1998 Jul 08 '19 at 04:09

0 Answers0