0

Can I have some advice on where I'm going wrong with this Query?

 $entry_id = '1';
 $accident_road = $form_data[58]["id"]; //print_r returns "116"

        $accident_road_array = $wpdb->get_results(
          "SELECT id FROM wp_rg_lead_detail
           WHERE field_number = '$accident_road'
           AND 'lead_id' = '$entry_id' ",
           ARRAY_A); 


 print_r returns 'Array()'
2
  • 1
    Did you intend to name that first variable $accident_road_exp? That's what your query expects. Commented Jun 17, 2013 at 15:49
  • Yes, sorry that was an error on my part. see edited code above. Commented Jun 17, 2013 at 15:54

2 Answers 2

1

I assume lead_id is a field in DB so you don't need quotes for it:

AND lead_id = '$entry_id'

You're also going wrong by putting variables directly into the query, you make your app vulnerable to SQL injections. consider using prepared statements.

Sign up to request clarification or add additional context in comments.

Comments

0

you set values in variable $accident_road while down there in query you used '$accident_road_exp' cross check this one man

1 Comment

please correct 'lead_id' = '$entry_id' ", as lead_id = '$entry_id' ",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.