going to wrong MySQL table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
doug76
Forum Commoner
Posts: 26
Joined: Tue Aug 24, 2010 7:44 am

going to wrong MySQL table

Post by doug76 »

Hello,

I amtrying to get my seach php to got t an sql table but for some resons it adda "where" to the table name and therefore goes to a non existant table.
There are other errors but these are minor compared with this one. I have tried a lot of different solutions all to no avail.

These are the errros I get:

Warning: explode() [function.explode]: Empty delimiter in C:\Program Files (x86)\EasyPHP5.2.10\www\search.php on line 66

Warning: Invalid argument supplied for foreach() in C:\Program Files (x86)\EasyPHP5.2.10\www\search.php on line 67
Error: Table 'DBname.TABLEnamewhere' doesn't exist

I feel there must be a simple solution but cannot find it.

Any help much appreciated

Code: [syntax=php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Risky Jobs - Search</title>

<link rel="stylesheet" type="text/css" href="style.css" />

</head>

<body>
<img src="riskyjobs_title.gif" alt="Risky Jobs" />

<img src="riskyjobs_fireman.jpg" alt="Risky Jobs" style="float:right" />

<h3>Risky Jobs - Search Results</h3>



<?php

// Grab the sort setting and search keywords from the URL using GET

$sort = isset($_GET['sort']) ? $_GET['sort'] : '';

$user_search = $_GET['usersearch'];


// Start generating the table of results

echo '<table border="0" cellpadding="2">';


// Generate the search result headings

echo '<tr class="heading">';

echo '<td>Job Title</td><td>Description</td><td>State</td><td>Date Posted</td>';

echo '</tr>';



// Connect to the database

require_once('connectvars1.php');

$dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name);




// Query to get the results



$search_query = "SELECT * FROM riskyjobs";
$where_list = array();
$user_search = $_GET['usersearch'];
$search_words = explode('',$user_search);
foreach ($search_words as $word) {
$where_list[] = "description LIKE '%$word%'";
}
$where_clause = implode('OR', $where_list);

if(!empty($where_clause)) {
$search_query .= "WHERE $where_clause";
}

$query = $search_query .="WHERE $where_clause";
$result = mysqli_query($dbc, $query)

or die("Error: ".mysqli_error($dbc));


while ($row = mysqli_fetch_array($result)) {


echo '<tr class="results">';

echo '<td valign="top" width="20%">' . $row['title'] . '</td>';

echo '<td valign="top" width="50%">' . $row['description'] . '</td>';

echo '<td valign="top" width="10%">' . $row['state'] . '</td>';

echo '<td valign="top" width="20%">' . $row['date_posted'] . '</td>';

echo '</tr>';

}

echo '</table>';


mysqli_close($dbc);

?>


</body>

</html>
][/syntax]
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: going to wrong MySQL table

Post by Jonah Bron »

First try replacing

Code: Select all

$search_words = explode('',$user_search);
With

Code: Select all

$search_words = explode(' ',$user_search);
As stated in the error, you cannot give explode an empty delimiter. See the manual.

http://php.net/explode
Post Reply