Search code examples
ormredbean

Check if an existing value is in a database


I was wondering how I would go about checking to see if a table contains a value in a certain column.

I need to check if the column 'e-mail' contains an e-mail someone is trying to register with, and if something exists, do nothing, however, if nothing exists, insert the data into the database.

All I need to do is check if the e-mail column contains the value the user is registering with.

I'm using the RedBeanPHP ORM, I can do this without using it but I need to use that for program guidelines.

I've tried finding them but if they don't exist it returns an error within the redbean PHP file. Here's the error:
Fatal error: Call to a member function find() on a non-object in /home/aeterna/www/user/rb.php on line 2433

Here's the code that I'm using when trying this:

function searchDatabase($email) {
    return R::findOne('users', 'email LIKE "' . $email . '"');
}

Solution

  • Edited to account for your updated question:

    According to the error message, the error is happening inside the function find() in rb.php on line 2433. I'm guessing that rb.php is the RedBean package.

    Make sure you've included rb.php in your script and set up your database, according to the instructions in the RedBean Manual.

    As a starting point, look at what it's trying to do on line 2433 in rb.php. It appears to be calling a method on an invalid object. Figure out where that object is being created and why it's invalid. Maybe the find function was supplied with bad parameters.

    Feel free to update your question by pasting the entirety of the find() function in rb.php and please indicate which line is 2433. If the function is too lengthy, you can paste it on a site like pastebin.com and link to it from here.