How to disable button based on sql query?

how to make button enable and disable in php
disable button javascript
how to disable a button in javascript based on condition
disable button css
jquery disable button
how to disable a submit button in php
disable button until dropdown selected jquery
javascript disable button until text entered

I need to disable or hide, button if existsusername in the table, and == logged in user

For example: username John exists in table paym we should disable button to John

table: paym

 ID        username        column1      column2  
+-------+-------------+-------------+-----------+
|   1   |  John       |  Value      |    Value  |
+-------+-------------+-------------+-----------+
|   2   |  Alex       |  Null       |    Null   |
+-------+-------------+-------------+-----------+

May be some syntax error or error in Query??

<?php
  $sql = "SELECT * FROM paym WHERE username = '" . $_SESSION['username'] . "'and column1 IS NOT NULL ";
  $result = mysqli_query($connection, $sql);
       if($result === true) {
        echo "<button class='btn btn-primary' disabled='disabled' name='add_box'>Add Box</button>";
    } else {
        echo "<button class='btn btn-primary' type='submit' name='add_box'>Add Box</button>";
    } 
  ?>

You should check for number of rows matched by query, so your condition should be

if($result !== false && $result->num_rows > 0)

because $result is only false when there was an error.

If your query is

SELECT * FROM paym WHERE username = 'not existing user' and column1 IS NOT NULL

mysqli_query will return mysqli_result not false, even if there are no rows matched.

Disable a button based on database value, These seat button will be disable if any passenger select the seat button before on same Departing date,same time, same Leaving place and� I have a table in my sql database called "usertype". My website has a registration form where the user will choose which type of user s/he is. So, what I want is that, when the user type of the person who logs in is User add, edit and delete buttons would be disable in the List of Faculty page of the website.

As mentioned in the comments, please make sure to read the documentation for functions you use, so you understand what they do, what they return, and how you can use that.

https://www.php.net/manual/en/mysqli.query.php is pretty clear on what it returns, and explains why what you've written cannot ever work: the function only ever returns either false, or a mysql_result object. It will never return true, so you can't test against that.

Of course, you can absolutely check against false, because that is a value it returned, if nothing was found:

if ($result !== false) {
  // generate button
}

but remember that $thing !== false in no way implies that $thing === true.

PHP - SQL - Disable, Hide or Enable Button based on Data, It is just used to give a clearer picture of the Web Description. (StatusQuery) SELECT status FROM SchoolData sd WHERE SelectedClass = sd. Hello, I have a button on my form and I would like to disable this button based on a certain value of the field. the field is a single line of text field. If the value of this field is "Yes", then the submit button should be disabled. I tried various options with display mode on Form OnVisble pr

Here mysqli_query returns mysqli_result object:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE. Here

instead you can count row

HTML button disabled Attribute, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java� Additional Notes. I'm very new to PHP and JQuery, like few days new and I had to take over from a previous developer. This link Disable submit button unless original form data has changed is quite

HTML DOM Button disabled Property, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java� Expand SQL Server Agent. Expand Jobs, and then right-click the job that you want to disable or enable. To disable a job, click Disable. To enable a job, click Enable. Using Transact-SQL To disable or enable a job. In Object Explorer, connect to an instance of Database Engine. On the Standard bar, click New Query. Copy and paste the following

HTML DOM Input Button disabled Property, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java� Note: Formatting the sql Query string is vulnerable to SQL Injection attacks always use Parameterized queries to prevent SQL Injection Attacks in SQL Server [ ^ ] use FindByText [ ^ ] or FindByValue [ ^ ] based on how you are populating the list items.

Disable or Enable Submit Button using JavaScript disabled Property, Here in this post I am sharing a simple example showing how to disable or enable a submit button based on certain condition. Syntax. submitObject. disabled. The� We all know that every time SQL Server executes a query it builds an execution plan that translates the logical operations like joins and predicates into physical operations that are implemented in the SQL Server source code. That conversion is based on certain rules known as the Optimizer Rules. They define for example how to perform an INNER

Comments
  • var_dump() your $result variable and see what it returns. Then, adapt your condition with this return.
  • Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. A select won't return TRUE. Check the number of rows returned. Also parameterize your query...and check for errors, if the query fails you probably want to know why
  • Also on a security note: don't use string concatenation to form your query. If that session's username managed to trick your system into having quotes and semi-colons in it, they can probably corrupt your database, so don't run that risk: you're using mysqli, which is good, you just need to form a prepared statement now, letting the mysqli library make sure that your values are made safe for executing. php.net/manual/en/mysqli.prepare.php
  • It's also best to avoid SELECT * outside of testing/development; just what you need, someone down the line adds high resolution photos to the table, and now every check to see if a button should be enabled pulls a large blob that is not even used.
  • The stackoverflow.com/a/55656205/3783243 answer should resolve your issue.. I'd think. Check that the query worked and has rows.
  • Condtion works good! I think problem in query? As @user3783243 told above "A select won't return TRUE." How to correct query that returnes true or false value??
  • Why would you? The fact that there is a result is a clear indication that "John" is in that table. As per the original question that is what they want to test for, so there is no reason to actually unpack the result in any way. Just knowing that there is a result is literally the information necessary to decide whether or not to generate output.
  • You're not in SQL, you're in PHP. So determine what you need to know (which in this case is "are there results at all") and then query for that (which your code does). Given the table data in your question, there is literally no reason to look for a word "True" anywhere. To quote you: "For example: username John exists in table paym we should disable button to John", so we only need to check whether that record exists and we're done. We don't need anything else.
  • You have to ask a question in order for people to answer you. The only question you asked was "what is wrong here", and this is what was wrong. If you have another question now that the code itself works, then remember how this website works and ask a new question specifically about your SQL statement, given your table data. Given what you show in your post, the SELECT looks fine to me, except for the part where you should be using a prepared statement to make sure it's a safe query.
  • The number of rows must be checked. 0 and 1 will both return result object which is not false.