-1

I am trying to update database with php update function but it always goes to else

It seems to me the no syntax error

function UpdateData()
{
    $bookid = textboxValue("book_id");
    $bookname = textboxValue("book_name");
    $bookpublisher = textboxValue("book_publisher");
    $bookprice = textboxValue("book_price");

    if($bookname&&$bookpublisher&&$bookpublisher){

        $sql="UPDATE books SET book_name='$bookname', book_publisher='$bookpublisher', book_price='$bookprice' WHERE id='$bookid' ";
        if(mysqli_query($GLOBALS['con'],$sql)){
            TextNode("success",'data successfully update');
        }else{
            TextNode("error","enable to update data");
        }
    }else{
        TextNode("error","select data using edit icon");
    }
}

Error:

No data sources are configured to run this SQL

Martin
  • 22,212
  • 11
  • 70
  • 132
  • 1
    That sounds like an error from an IDE, not from running the code – aynber Jun 04 '19 at 13:16
  • 1
    You are wide open for SQL injection. Since you're using mysqli, take advantage of [prepared statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [bind_param](http://php.net/manual/en/mysqli-stmt.bind-param.php). **This will take care of any pesky quoting issues that may occur.** – aynber Jun 04 '19 at 13:17
  • 1
    If a query does not work as you think it should, check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) in your else. This will tell you exactly what is wrong with your query instead of trying to make a guess. – aynber Jun 04 '19 at 13:21
  • @aynber, thanks for your reply. can you be more specific? – New Programmer Jun 04 '19 at 13:25
  • Which part? The links I posted will help you in adjusting your code to check for errors and preventing quoting issues. – aynber Jun 04 '19 at 13:27
  • @aynber, I am using PHP storm. – New Programmer Jun 04 '19 at 13:27
  • check that your connection to DB is correctly created or not. For that just try to run a select query and check the results. – anuj arora Jun 04 '19 at 13:28
  • @aynber,mysqli errors, thanks,Jacky – New Programmer Jun 04 '19 at 13:29
  • I figured that you were using PHPStorm, considering the "no data sources". That's just a warning that means that it can't check the syntax for your sql, so you can ignore that message. – aynber Jun 04 '19 at 13:30
  • @anujarora. connect db is correct. Create and Read function works well, thanks – New Programmer Jun 04 '19 at 13:33
  • Possible duplicate of [No data sources are configured to run this SQL](https://stackoverflow.com/questions/42933570/no-data-sources-are-configured-to-run-this-sql) – Martin Jun 04 '19 at 14:07

1 Answers1

0

Your error "No data sources are configured to run this SQL" is an IDE specific error for PHPStorm not for your code syntax.

"Live" code errors will be found in your PHP error log.

You can find guidance from JetBrains for setting up your SQL analysis for PHPStorm here.

You may also get help on this topic here: No data sources are configured to run this SQL

Martin
  • 22,212
  • 11
  • 70
  • 132
  • @all, thanks to you all for the help. I finally figured it out. In the if condition I have 3 input fields. I need to enter all the input field otherwise it goes to "else". I am closing this question. Again, thanks to you all and have a good day! Jacky – New Programmer Jun 04 '19 at 14:39
  • @NewProgrammer that `if` condition does not relate to the error you put in your question. – Martin Jun 04 '19 at 15:37