Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:20:04+00:00 2026-05-20T10:20:04+00:00

I am trying to bind params to a INSERT INTO MySQLi prepared statement if

  • 0

I am trying to bind params to a INSERT INTO MySQLi prepared statement if that variable exists, otherwise insert null.

This is what I have, but it is not working:

if (!empty($name)) {
    $result->bind_param('ss', $name, $url_friendly_name);
} else {
    $result->bind_param('ss', null, null);
}

if (!empty($description)) {
    $result->bind_param('s', $description);
} else {
    $result->bind_param('s', null);
}

Does anyone know of a better way of doing this or is there just a minor issue with my code. I am doing the above for each variable in the prepared statement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:20:05+00:00Added an answer on May 20, 2026 at 10:20 am

    bind_param works by reference. That means that it takes a variable, then uses the value of that variable in execute.

    null is not a variable.

    Try setting a variable to null and then binding that variable instead.

    (Also consider using PDO instead of mysqli, where the execute method can take a simple array and you can bypass wacky binding methodology of mysqli.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to bind a variable in this prepared statement, but i keep
I am trying to pass a string into my MySQLi prepared statement but it
I am trying to do a simple insert into MySQL. I am using mysqli
I'm trying to bind a list of integers into an SQLTemplate IN clause like
I'm trying to bind a XAML ComboBox so that its list items are the
I am trying to insert and update data using 3 prepared statements. There are
I'm trying to bind input parameters into my SELECT query and then fetch the
I am trying to do prepared statements as follows: $stmt = $mysqli->prepare(SELECT COUNT(*) FROM
I'm basically trying to call mysqli::bind_param via call_user_func_array . Here's my function: function Insert($table,
I'm trying to loop over a set of results using MySQLi and the bind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.