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

  • SEARCH
  • Home
  • 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 8098401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:04:12+00:00 2026-06-05T22:04:12+00:00

I am trying to see if there is an existing row in my sqlite

  • 0

I am trying to see if there is an existing row in my sqlite database and if not add it. But something is wrong with my query. I hope someone can spot my error.

Specifically I thin the error is in the query line:

$query = 'SELECT * FROM plant WHERE common_Name = '. $commonName . ' AND latin_Name = '. $latinName . 'AND  url = '. $URL ;

Thank you,
Todd

// set path of database file
$file = "db/plants.db";

// create database object
$db = new SQLiteDatabase($file) or die("Could not open database");

// see if the EXACT same tag exists
$query = 'SELECT * FROM plant WHERE common_Name = '. $commonName . ' AND latin_Name = '. $latinName . 'AND  url = '. $URL ;
$result = $db->query($query) or die("Error in query");
$rows = sqlite_num_rows($result);


if($rows>0) return; //do not add it

// generate query string
$query = 'INSERT INTO plant (common_Name, latin_Name, url) VALUES("'.$commonName.'","'. $latinName.'","'.$URL.'")';

// execute query
// return result object
$result = $db->query($query) or die("Error in query");


// destroy database object
unset($db);
  • 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-06-05T22:04:14+00:00Added an answer on June 5, 2026 at 10:04 pm

    You’re missing quotes in your SELECT query, so it’s failing.

    $query = "SELECT * FROM plant WHERE common_Name = '$commonName' AND latin_Name = '$latinName' AND  url='$URL'";
             ^                                        ^           ^ etc...
    

    Note the indicated quote changes and formatting differences. As well, unless you’ve done it somewhere else outside of your code snippet, be aware that this type of query construction is vulnerable to SQL injection attacks, and you should read up and learn about those before you go any farther with this code.

    Next time you put in an error handler (kudos for checking the return value, by the way), don’t just output a static “Something went wrong” error message. That’s useless for diagnostics. The database can tell you exactly what went wrong, so output the DB’s error message instead, e.g. sqlite_error_message().

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

Sidebar

Related Questions

I am trying to locate leaks using instruments, but the leaks I see there
I'm trying to see if there is a way to build a Linq statement
I'm trying to see the value of a variable, but the debugger shows me
I am trying to write a query to find out what users are not
Hy there, I'm trying to adapt an existing code to boost::variant. The idea is
I'm trying to add a table row with ajax/jquery that has a form element
I'm trying to add this iOS lib PTImageAlbumViewController to an existing project that I'm
I was trying to add coded UI test project to an existing project in
I was trying to insert new data into an existing XML file, but it's
I'm trying to add existing files as links to a Website project in Visual

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.