0

I am converting my site from MySQL to MySQLi but all of my queries had stopped to work.

I have tried everything but queries are not making any entries into the database, I will provide a couple of the queries that aren't working.

Where did I do a mistake?

    $sql             = array();
    $sql             = "SELECT my_mailban,mban_reason 
                              FROM members
                              WHERE playerid = '" . mysqli_real_escape_string($con, $_SESSION['playerid']) . "'";
    $mb               = array();
    $mb               = mysqli_fetch_array(mysqli_query($con, $sql));
    $_POST['message'] = stripslashes($_POST['message']);
    $_POST['subject'] = stripslashes($_POST['subject']);
    $_POST['to']      = abs(intval($_POST['to']));

$sql = array();

$sql = "INSERT INTO member_mail
                                 VALUES ('NULL',
                                         '" . mysqli_real_escape_string($con, $_POST['to']) . "',
                                         '" . mysqli_real_escape_string($con, $_SESSION['playerid']) . "',
                                         '" . mysqli_real_escape_string($con, $_POST['subject']) . "',
                                         '" . mysqli_real_escape_string($con, $_POST['message']) . "',
                                         unix_timestamp(),
                                         '0')";
            mysqli_query($con, $sql);

Thank you

Arfan Mahmood
  • 142
  • 13
braidz
  • 45
  • 9
  • 1
    Quote from [this meta post](https://meta.stackoverflow.com/questions/293931/should-one-answer-terribly-poor-questions/293946#293946): *We do not want debug-my-wall-of-code-for-me questions. Period. [...]* such questions are likely to get downvoted, closed and/or deleted. Try to reduce your code to a specific problem you've got by creating [a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Filnor Oct 17 '17 at 13:37
  • Yeah I figured out the only way I could do it was to provide the whole function otherwise it would not make sense.. I will edit my post.... – braidz Oct 17 '17 at 13:37
  • 1
    When your query doesn't work, then there is an error. if there is an error, then there is an error message. You should get the error message, read it and then fix the problem. – Your Common Sense Oct 17 '17 at 13:38
  • Getting no error messages @YourCommonSense – braidz Oct 17 '17 at 13:41
  • What did you do to get them? – Your Common Sense Oct 17 '17 at 13:42
  • They are just not inserting into the database for some reason, but giving me no errors! – braidz Oct 17 '17 at 13:42
  • 1
    Just added the the "i' to the end of the mysql and added the $con for the connection from my connections file that is included in the whole script – braidz Oct 17 '17 at 13:43
  • So you did nothing to get the error message. We cannot do it for you, sorry. – Your Common Sense Oct 17 '17 at 13:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156922/discussion-between-braidz-and-your-common-sense). – braidz Oct 17 '17 at 13:48
  • The error I am getting now is Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Incorrect integer value: 'NULL' for column 'mm_id' at row 1' in C:\wamp64\www\messages.php:1195 Stack trace: #0 C:\wamp64\www\messages.php(1195): mysqli_query(Object(mysqli), 'INSERT INTO mem...') #1 C:\wamp64\www\messages.php(58): mail_send() #2 {main} thrown in C:\wamp64\www\messages.php on line 1195 – braidz Oct 17 '17 at 14:05
  • Now you can google for this error accordingly. Most likely someone already asked for it and got a solution. This is how the modern web-development works. – Your Common Sense Oct 17 '17 at 14:07
  • https://stackoverflow.com/questions/14762904/incorrect-integer-value-for-column-id-at-row-1 – Arfan Mahmood Oct 17 '17 at 14:17
  • @ArfanMahmood this is a wrong one. – Your Common Sense Oct 17 '17 at 14:23
  • You should not be using `*_real_escape_string()`, but rather prepared statements with parameterized variables. I recommend `PDO`. If you need help learning how to use [PDO](http://php.net/manual/en/book.pdo.php) for safe and secure queries, then you can check [GrumpyPDO](https://github.com/GrumpyCrouton/GrumpyPDO) (A class I wrote) which makes [Prepared Statements](https://www.w3schools.com/php/php_mysql_prepared_statements.asp) easy, and clean. Alternatively you should learn how to use [Prepared Statements for MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – GrumpyCrouton Oct 17 '17 at 14:24
  • @YourCommonSense - Did you check the error from braidz? Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Incorrect integer value: 'NULL' for column 'mm_id' at row 1' According to this error, braidz need to specify columns and skip to pass values in mm_id. If mm_id is set to auto-increment. – Arfan Mahmood Oct 17 '17 at 14:32
  • @ArfanMahmood yes, I did. Google is finding me a question on Stack Overflow with exactly the same error message. And and solving it by bypassing values is rather silly – Your Common Sense Oct 17 '17 at 14:41
  • https://stackoverflow.com/questions/20469720/1366-incorrect-integer-value-null-for-column-cid-at-row-1 – Your Common Sense Oct 17 '17 at 14:47
  • I only had to change a line in my my.ini file. And I will look into cleaning my code up correctly – braidz Oct 17 '17 at 18:25

0 Answers0