0

I am trying to get prepared statements to work, but I get the same error. It says I am trying to use a Boolean where a mysql_stmt is required.

if ($_SERVER['REQUEST_METHOD']=='POST') 
{
 {
   require('zzzx.php') ;
   $quer = 'insert into bloggert (message,email,date) values  (?,?,now()) ';
   $stmt=  mysqli_prepare($conn,$quer);
   mysqli_stmt_bind_param($stmt,'ss',$email,$message);
   //  this is where the errors start.  It always ways says it is getting a 
   // boolean rather than a mysql statement which is required
   $message= nl2br(strip_tags  ($_POST['message']));
   $auathor = strip_tags($_POST['email']);

   mysqli_stmt_execute($stmt);

   if (mysqli_stmt_affected_rows($stmt)==1)
   {
      echo '<p> the review made it to posting</p>';
   }
   else
   {
      echo '<p style = "font-weight:bold; color:#c00;"> It failed utterly.</p>';
      //this, needless to say is what I got with ever reiteration
      echo '<p>'.mysqli_stmt_error($stmt).'   </p>' ;
   }
   mysqli_stmt_close($stmt);
   mysqli_close($conn);
 }
}

The thing is, I copied it off another file that does work, no problem.

Also, I notice other folks are using a different way of assigning. Would that be the source of my problem?

Jeff
  • 6,895
  • 1
  • 15
  • 33
  • Try [enabling errors](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments) and see if that gives more information. – Nigel Ren Dec 16 '18 at 20:15
  • is `$conn` defined and in scope (or are you maybe inside a function/method)? – Jeff Dec 16 '18 at 20:32
  • Do a `echo mysqli_error($conn);` to see why mysqli_prepare could have failed. – Jeff Dec 16 '18 at 20:32
  • _sidenote:_ there's a `{` too much at the beginning, but it doesn't hurt, cause there is a `}` too much at the end too. – Jeff Dec 16 '18 at 20:34
  • do a `var_dump($stmt)` to see if you've got a valid statement or `false` – Peter Dec 16 '18 at 20:42
  • @Peter _"It says I am trying to use a Boolean"_ - I bet for false. – Jeff Dec 16 '18 at 20:47
  • $conn is defined on zzzx.php. I was told that for security you should always have this defined eslewhere. – Steven Demonnin Dec 16 '18 at 20:51
  • if `$conn` is ok (not only defined, but also a valid successful connection), then there's something wrong with the query. Maybe a wrong table/field name? – Jeff Dec 16 '18 at 20:53
  • @Jeff, you are correct, it gives a "false." Which begs the question why it is givings a false, as $conn,$quer and $stmt are all defined in the preceding two lines. I have $conn defined and it always tells me that the connection works – Steven Demonnin Dec 16 '18 at 21:09
  • Then there's something wrong with the query. Jump to my second comment about echo mysqli_error...! – Jeff Dec 16 '18 at 21:15
  • Thank you for your fantastic help! I went and looked, swearing up, down, and sideways that this was _NOT_ the result of some spelling error or table name being incorrect.... and found out it was both. Thank you for your great help. My face is vermilion from embarrassment, but I am grateful for the assistance. – Steven Demonnin Dec 16 '18 at 21:27

0 Answers0