SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

kffoodskffoods Posts: 13Questions: 4Answers: 1

I had this working and now can't seem to figure out. Any ideas?

kffoods.com/allen.html

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Could you give me a little more information please? Do I need to create, edit or delete a row? Or should it happen when I just load the page?

    Also, given its an SQL error, if you can show me the server-side code that would be useful.

    Allan

  • kffoodskffoods Posts: 13Questions: 4Answers: 1

    Happens after clicking the "Update" button on new & create.

    Here is server side:

    Editor::inst( $db, 'Kitchen Fresh Foods$Customer Detail Order Location')
        ->fields(
            Field::inst( 'Customer No_' ),      
            Field::inst( 'Location No_' ),      
            Field::inst( 'Route No_' ),     
            Field::inst( 'Name' ),
            Field::inst( 'Status' ),
            Field::inst( 'Notes' ),
            Field::inst( 'Monday Menu' ),
            Field::inst( 'Tuesday Menu'),
            Field::inst( 'Wednesday Menu'),
            Field::inst( 'Thursday Menu'),
            Field::inst( 'Friday Menu'),
            Field::inst( 'POS' ),
            Field::inst( 'Item List Code' )
        )
        ->where( 'Customer No_', $_GET["CustomerNo"] )
        ->where( 'Status', $_GET["Status"], "like" ) 
        ->where( 'Route No_', $_GET["RouteNo"], "like" )     
        ->debug( true ) 
        ->process( $_POST )
        ->json()
        ;
    
  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin
    Answer ✓

    Thanks. Similar to your other threads, its the spaces in the field names that is causing the issue.

    The SQL statement being executed looks like this:

    UPDATE  [Kitchen Fresh Foods$Web User] SET  [Customer No] = :Customer No, [User Code] = :User Code, [Name] = :Name, [Mapped Route No] = :Mapped Route No, [Waste System] = :Waste System, [Status] = :Status, [Expires On] = :Expires On, [Password] = :Password, [Mobile Phone] = :Mobile Phone, [Email] = :Email WHERE [Customer No] = :where_0 AND [User Code] = :where_1
    

    Using a binding such as :Customer No isn't working, nor will it work.

    If you look in the Database/Query.php file there is a private method called _safe_bind. If you add:

            $name = str_replace(' ', '_5_', $name);
    

    to the list of str_replace calls, that should fix it.

    Allan

  • kffoodskffoods Posts: 13Questions: 4Answers: 1

    Great. Will I have to remember this changes when installing a new version of the Editor?

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    No - I've just added that it to the PHP libraries for Editor. It will be included in the 1.7.4 release :).

    Allan

This discussion has been closed.