0

I have a PHP script designed to answer a users question. Currently I use arrays to provide the programmed questions and then echo the answer for that question. Instead, I want the script to search a MySQL database for questions and their answer. How can I do this in PHP?

I hope you can understand my question.

Here is my PHP code:

<?php

if(stripos($_GET['q'],'what is my ip')===0){
    echo "Your IP address is <b>{$_SERVER['REMOTE_ADDR']}</b>";
}

?>

<form method='get' action=''>
<input type='text' name='q'>
<input type='submit'>
</form>

1 Answer 1

2

Best bet is start here and learn how to connect to a mysql database and execute queries against it. Of course you will need to create the database, tables and populate the data, before you can retrieve anything.

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

1 Comment

Ok, please update your question to be a little more specific, do you need to know what kind of query to write, or how to process the results of the query? show us what your tables/data looks like, etc.

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.