logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Dreamweaver General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 07-23-2014, 03:41 PM   #1
greg.farmer
 
Join Date: Jan 2012
Posts: 11
Default Search Engine

Hi everybody

I have been following this tutorial to build a search and return page

http://help.adobe.com/en_US/dreamwea...d65-78b0a.html

I am having trouble in that I can't get my results to display.

Below is my code. I would appreciate any help anyone can offer. Thanks

Search page



<!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>
<p>Search</p>
<form id="form1" name="form1" method="get" action="returns.php">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
</body>
</html>




RETURNS PAGE

<?php require_once('Connections/connTSweb.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;
}
}
$colname_Recordset1 = "-1";
if (isset($_GET['form1'])) {
$colname_Recordset1 = $_GET['form1'];
}
mysql_select_db($database_connTSweb, $connTSweb);
$query_Recordset1 = sprintf("SELECT id, firstname, lastname, `alias`, `role`, ext, ddi, mobile, fax, email, chargeoutrate, secretary, secext FROM staff WHERE firstname = %s ORDER BY lastname ASC", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $connTSweb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$colname_Recordset1 = "-1";
if (isset($_GET['form1'])) {
$colname_Recordset1 = $_GET['form1'];
}
mysql_select_db($database_connTSweb, $connTSweb);
$query_Recordset1 = sprintf("SELECT firstname, lastname, `alias`, ext, ddi, mobile, fax, email, chargeoutrate, secretary, secext FROM staff WHERE firstname = %s ORDER BY lastname ASC", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $connTSweb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($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>
<p>Return </p>
<p>&nbsp;</p>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>firstname</td>
<td>lastname</td>
<td>alias</td>
<td>ext</td>
<td>ddi</td>
<td>mobile</td>
<td>fax</td>
<td>email</td>
<td>chargeoutrate</td>
<td>secretary</td>
<td>secext</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['firstname']; ?></td>
<td><?php echo $row_Recordset1['lastname']; ?></td>
<td><?php echo $row_Recordset1['alias']; ?></td>
<td><?php echo $row_Recordset1['ext']; ?></td>
<td><?php echo $row_Recordset1['ddi']; ?></td>
<td><?php echo $row_Recordset1['mobile']; ?></td>
<td><?php echo $row_Recordset1['fax']; ?></td>
<td><?php echo $row_Recordset1['email']; ?></td>
<td><?php echo $row_Recordset1['chargeoutrate']; ?></td>
<td><?php echo $row_Recordset1['secretary']; ?></td>
<td><?php echo $row_Recordset1['secext']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
greg.farmer is offline   Reply With Quote
Old 07-23-2014, 03:50 PM   #2
Ricky55
Ricky55's Avatar
 
Join Date: Oct 2005
Location: West Yorkshire, UK
Posts: 1,855
Default

What happens when you run a search?

Have you set up the database and are you running a local environment to test PHP?
__________________
Qwerty Design

Check out my blog for web design insights.
http://www.qwerty-design.co.uk/
Follow me on Twitter: @QwertyDesignUK
Ricky55 is offline   Reply With Quote
Old 07-23-2014, 05:24 PM   #3
greg.farmer
 
Join Date: Jan 2012
Posts: 11
Default

Thanks for the reply Ricky55. Yes I am running a local PHP test environment. Everything else is working OK jus this.

My returns should be in a table but all I see are the table headers and that is all.
greg.farmer is offline   Reply With Quote
Old 07-23-2014, 10:38 PM   #4
Ricky55
Ricky55's Avatar
 
Join Date: Oct 2005
Location: West Yorkshire, UK
Posts: 1,855
Default

Just making sure it wasn't anything obvious.

TBH with you my PHP isn't strong enough to spot an error just by looking at the code. Ed may be able to help you. I'm a front end guy, HTML, CSS and JS.

If you want a quick answer you could try on the PHP Freaks forum many of their users use PHP daily and I'm sure will be able to point you in the right direction.

Good luck.
__________________
Qwerty Design

Check out my blog for web design insights.
http://www.qwerty-design.co.uk/
Follow me on Twitter: @QwertyDesignUK
Ricky55 is offline   Reply With Quote
Old 07-24-2014, 03:44 AM   #5
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,175
Default

<input type="text" name="name" id="name" /> is the value you are passing.
the select is based on WHERE firstname = %s
so i can only guess that this is the wrong parameter?

Frankly it would be better to use POST as the action i would think, bit mostly do not use dreamweaver wizard for this, way too code soup to help y0u get the basics.

use a form to select the name ( method post)
on the results page colect the passed value as (for instance) $name= $_POST['name]

use a connection and a select
"SELECT firstname, lastname, `alias`, ext, ddi, mobile, fax, email, chargeoutrate, secretary, secext FROM staff WHERE firstname = $name ORDER BY lastname ASC"

then echo the results. you can find code examples on tizag.com or we can help you
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas

Last edited by edbr; 07-24-2014 at 08:20 AM..
edbr is offline   Reply With Quote
Old 07-25-2014, 02:14 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,175
Default

here a simple example using PDO, ill post a mysqli example later time permitting

Connect
Code:
<?php
$hostname = "localhost";
$username= "root";
$password = "pass";
 $db="dbname";
try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
 //   echo "Connected to database"; // check for connection
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
	 }
?>
select

Code:
<?php
   $sql = "SELECT * FROM tablename ORDER BY Rand() LIMIT 2"; 
 
     foreach ( $dbh->query($sql) as $row) { ?>
      <?php echo  $row['comment']."&nbsp"."&nbsp"."&nbsp"."<strong>". $row['name']."</strong>"."<br>"."<br>";

} ?>
now if you wanted to select using a passed value
Code:
$news= $_POST['name'];  //or $_GET
 $sql = "SELECT * FROM tablename  WHERE lastname =$name;
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:37 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com