php code to search and show results on same page

Thread Solved

Join Date: Jan 2009
Posts: 1,398
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: php code to search and show results on same page

 
0
  #11
Jan 9th, 2009
more than you can ever read, compiled so you can find the part you need to read
http://www.php.net/docs.php
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 13
Reputation: phpNewbie is an unknown quantity at this point 
Solved Threads: 0
phpNewbie phpNewbie is offline Offline
Newbie Poster

Re: php code to search and show results on same page

 
0
  #12
Jan 10th, 2009
enim213 - thank you very much for the links you supplied - i really do appreciate your time to give them and will definitely make an effort to get the understanding - be afraid lol - if i come up with anything i'll be right back here for you to debug (or get your pasted code - kidding - or not lol)
thank you almostbob for your link and code too
at least today i got my basic html page made and my database loaded so that's a start
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 13
Reputation: phpNewbie is an unknown quantity at this point 
Solved Threads: 0
phpNewbie phpNewbie is offline Offline
Newbie Poster

Re: php code to search and show results on same page

 
0
  #13
Feb 5th, 2009
Hi... i'm baaack
Ok.. i made some effort (got myself more confused in the process - seem to be so many ways to do the same thing??)

Anyway.. this is what i have now: Please help to add or change code to get this working. my sql statement works in phpmyadmin bringing back required results from the database but how do i get that happening on my webpage with the php and html.

Apologies for my messy code but like i explained before, i'm absolutely new to php and finding it very difficult to get my 'blonde' head around it.

Thanks again in advance for any help.

<html>
<head>
<title>Baby Names Database</title>
</head>
<body>
<h1>Baby Names</h1>
<h3>Please fill in the blanks below, and We'll return baby names for you to browse.</h3>

<form method = "post" action = "practiceBaby5.php">
<table border = "1">
<tr>
<th align = "left">Gender:</th>
<th>
<input type = "radio" name = "male" value = "yes">Boys Names<br />
<input type = "radio" name = "female" value = "yes">Girls Names<br />
</th>

<tr>
	<th align = "left">Meaning:</th>
	<th>
		<input type = "text" name = "meaning" value = "">
	</th>
</tr>

<tr>
	<th align = "left">Name Begins With:</th>
	<th>
		<input type = "text" name = "name" value = "">
	</th>
</tr>


<tr>
	<th align = "left">Origin</th>
	<th>
		<select name = "origin">
		<option value = "Muslim">Muslim</option>
		<option value = "anglo">Anglo</option>
		<option value = "african">African</option>
		<option value = "celtic">Celtic</option>
		</select>
	</th>
</tr>

<tr>
	<td colspan = 2> <br />
		<center>
			<input type = "submit" value = "Show me Names">
		</center>
	</td>
</tr>
</table>
</form>
		
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<?
// MySQL Connection Information
$server = "localhost";
$username = "sharlene";
$password = "";
$dbname = "baby_names";

// MySQL Connect String
$connection = mysql_connect($server,$username,$password);

// Select the database
mysql_select_db($dbname);

$gender = $_POST['gender'];
$meaning = $_POST['meaning'];
$name = $_POST['name'];
$origin = $_POST['origin'];

$gender = mysql_real_escape_string($gender);
$meaning = mysql_real_escape_string($meaning);
$name = mysql_real_escape_string($name);
$origin = mysql_real_escape_string($origin);

$sql = "SELECT * FROM names WHERE gender = '" . $gender . "' and name LIKE '" . $name . "%' and 

meaning LIKE '%" . $meaning . "%' and origin = '" . $origin . "'";
//print($sql);

//execute SQL query and get result
$sql_result = mysql_query($sql, $connection)
	or die(mysql_error());
//print("after sql");

// Loop through the data set and extract each row into it's own variable set
while ($row = mysql_fetch_array($sql_result)) {
	extract($row);
}
// Loop through the data set and extract each row into it's own variable set
//while ($row = mysql_fetch_array($sql_result)) {
//	echo $row['gender']." ".$row['meaning']." ".$row['name']." ".$row['origin']."<br>";

?>


</BODY>
</HTML>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 3678 | Replies: 12
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC