How to Extract from a database

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Wed May 22, 2013 4:16 am

How to Extract from a database

Postby chrispy » Wed May 22, 2013 4:43 am

I am trying to connect to a database following an autocomplete script to find out if an activity is listed in the database.
The code for the search is:

Code: Select all

<form method="post" action="connect.php">
    <label for="tags"><strong>Please enter the activity below to check. </strong><br>
    <div align="center">
      <label for="label"><br>
        <label for="label">Activity: </label>

        <input name="Input" id="tags" />
        <input type="submit" name="submit" value="Click to Check" />

I then connect to the database using the connect.php page as follows:-

Code: Select all

$mysqli = new mysqli("localhost", "XXX", "XXX", "XXX");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());

$tags = $_POST['tags'];   
$sqli = mysqli_query("SELECT linkto FROM activity WHERE active= '$tags'");   
if (mysqli_num_rows($sqli) <= 0) {
// no results
echo '<strong>The activity you have entered is not listed on our database!</strong> 
} else

while ($row = mysqli_fetch_assoc($sqli))
   echo '<strong>YOUR RESULTS</strong>';
   echo '<br/>';
   echo '<em><br/> You Searched for the activity: '.$row['active'];
   echo ', this activity is listed in our database!</em>'; 
   echo '<br>';
   echo '<br/> '.$row['linkto']; 
   echo '<br>';       
   echo '<br/><br/>';     

/* close connection */

The purpose of the query is to select the activity in the database and confirm the information that is stored under the linkto column in the data base.
Every entry that I am running to search the database is saying that the entry is not in the database (as per the no entry statement above).
Can anybody help me to successfully select the one line from the database following the search?

Thanking anyone who answers in advance.

php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: How to Extract from a database

Postby johnj » Wed May 22, 2013 9:54 pm

You need to assign this query SELECT linkto FROM activity WHERE active= '$tags' to a variable, display (echo) it, copy that displayed query and run it from a database client like phpmyadmin and see if your query is picking the right records.

New php-forum User
New php-forum User
Posts: 75
Joined: Wed Jun 12, 2013 9:30 pm

Re: How to Extract from a database

Postby johnmacd » Thu Jun 13, 2013 11:15 pm

It is possible that you have entered capital letters and in database all letters are in small case.Check it properly.

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 8 guests