Copy link to clipboard
Copied
I am a complete newbie to mySQL and php, but I have managed to create a database in Dreamweaver. It seems (using 'seems' broadly) I have done everything correctly, following step-by-step instruction from the Dreamweaver help website. But when I load everything to my server and search, the table comes up with no results in it. I had put two entries into my database on phpMyAdmin; the search shows up fine when I test the recordset in Dreamweaver, but when it's online and I search, it's just a blank table on the results page.
I have exhausted search terms on the web trying to figure this out. I thought maybe something was wrong with the connections folder, but it is located where it says it is. Maybe someone here can help. Pasting the code below:
<?php require_once('Connections/ppi_database.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$colname_Recordset1 = "-1";
if (isset($_GET['form1'])) {
$colname_Recordset1 = $_GET['form1'];
}
mysql_select_db($database_ppi_database, $ppi_database);
$query_Recordset1 = sprintf("SELECT * FROM ppiguests WHERE name LIKE %s ORDER BY name ASC", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $ppi_database) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1" align="center">
<tr>
<td>name</td>
<td>date of stay</td>
<td>room</td>
</tr>
<?php do { ?>
<tr>
<td><a href="detail.php?recordID=<?php echo $row_Recordset1['name']; ?>"> <?php echo $row_Recordset1['name']; ?> </a></td>
<td><?php echo $row_Recordset1['date of stay']; ?> </td>
<td><?php echo $row_Recordset1['room']; ?> </td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<br />
<table border="0">
<tr>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Copy link to clipboard
Copied
All that you have provided is a search result page. Obviously, you need a search form to perform the search. Where is that in your provided code?
Copy link to clipboard
Copied
I'm not sure I follow you. (As I said, super new at this) What kind of php do I need on the search page? From the instructions I read, the php code is relevant to the results page, not the search form. But on line 43 you see there is this:
$colname_Recordset1 = "-1";
if (isset($_GET['form1'])) {
$colname_Recordset1 = $_GET['form1'];
The search page is search.php (.php because I plan to create a log in page eventually) and I id'd the form as form1. I hope this answers your question.
Also, if this might help solve the problem I am having, here is the code from the .php file in the connections folder
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_ppi_database = "localhost";
$database_ppi_database = "guests";
$username_ppi_database = "******";
$password_ppi_database = "********";
$ppi_database = mysql_pconnect($hostname_ppi_database, $username_ppi_database, $password_ppi_database) or trigger_error(mysql_error(),E_USER_ERROR);
?>
Copy link to clipboard
Copied
I hope this answers your question.
It doesn't answer my question but it still helps me determine your level of knowledge.
For your search results page code the php is processing data that's sent via URL parameter. That's what the snippet you provided is saying:
$colname_Recordset1 = "-1";
if (isset($_GET['form1'])) {
$colname_Recordset1 = $_GET['form1'];
That says that if a URL parameter for form1 is set then set the value of the parameter to the variable for processing in your query. That's why I asked where your search form code is. You explained your search from briefly, but didn't provide a code. For search page you need a form to send the URL parameter 'form1' to the search results page. Use something like this on search page for your form:
<form action="results_page.php" method="GET">
<input type="text" name="form1">
<input type="submit" value="Search">
The action of the form should point to your search results page to process the data into a query and display the results. GET method of a form will send the "name" data of each form element as a URL parameter. So if you searched for entered text on your search form then when you click submit the URL will look like: www.your-domain.com/result_page.php?form1=entered%20text
Your script will take data form URL parameter and process the data in your query. That should get you going in the right direction.
Copy link to clipboard
Copied
Sorry it took me so long to reply. I think I misunderstood what you were
asking for. This is the code from my search page:
Let me know if you have any other suggestions on how to make it display the
results when I search.
Copy link to clipboard
Copied
According to your search results page the input type="text" field should have a name attribute that is form1 to pass the value to the search. The URL in the search results page after form submission should be search_results.php?form1=something where form1 is the name attribute of the text input field on your search form and something is the text that is entered into the text field when you submitted the search form.
I modified your form code. Does this look familiar? It's pretty much the exact same form code I provided in my previous response weeks ago. If you replaced that (or this) in your form code then you'd have a working search form.... You could of done this from the code I provided in the last post. Do you read?
<form action="search_results_page.php" method="get">
<label for="search"></label> <input name="form1" type="text" />
<input type="submit" value="Submit" />