PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1847
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to correct search key Posted by bae on 12 Jul 2009 at 11:32 AM
my problem is the keyword not working.
<?php
include('connect_login.php');
?>


<div class="post">
<h1>&nbsp;</h1>
<div align="center"></div>
<table width="500" border="1" bordercolor="#9E8C83">
<tr>
<td bordercolor="#864243" bgcolor="#0099FF"><div align="center" class="style4">ID</div></td>
<td width="300" bordercolor="#864243" bgcolor="#0099FF"><div align="center" class="style4">Title</div></td>
<td bordercolor="#864243" bgcolor="#0099FF"><div align="center" class="style4">Student Name</div></td>
</tr><?
$title=$_POST['title'];
$query = "Select * from 'developer' where title='$title'";
$result = mysql_query($query);
while($result_row = mysql_fetch_row($result))
{
$input = $result_row[1];
}
if($input == "")
{ ?>
<meta http-equiv="refresh" content="0; url=searchdb.php" />
<script>window.alert('You have inserted wrong title, please try again ...');</script>

<?
}
else
{
?>

<tr>
<td><? echo $result_row[1]; ?></td>
<td><? echo $result_row[2]; ?></td>
<td><? echo $result_row[4]; ?></td>
</tr>
<?
}
?>
</table>
<table width="500" height="200" border="0" align="center" bordercolor="#9E8C83">
</table>
<div align="center"></div>
</div>
</div>


how to correct the code in order to display the output?
Report
Re: how to correct search key Posted by Agbagbara on 16 Jul 2009 at 7:26 PM
<?php
	include('connect_login.php');
?>

<div class="post">
	<h1>&nbsp;</h1>
<div align="center"></div>
<table width="500" border="1" bordercolor="#9E8C83">
<tr>
<td bordercolor="#864243" bgcolor="#0099FF"><div align="center" class="style4">ID</div></td>
<td width="300" bordercolor="#864243" bgcolor="#0099FF"><div align="center" class="style4">Title</div></td>
<td bordercolor="#864243" bgcolor="#0099FF"><div align="center" class="style4">Student Name</div></td>
</tr>
<?
$title=$_POST['title'];
$query = "Select * from developer where title='$title'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows  > 0){ 
	while($result_row = mysql_fetch_row($result)){
		//$input = $result_row[1];
		$all_data[] = $result_row;
	?>
		<tr>
			<td><? echo $result_row[1]; ?></td>
			<td><? echo $result_row[2]; ?></td>
			<td><? echo $result_row[4]; ?></td>
		</tr> 
	<?
	}
}else{ ?>
	<meta http-equiv="refresh" content="0; url=searchdb.php" />
	<script>window.alert('You have inserted wrong title, please try again ...');</script>
<?
}?>
</table>
</div>
</div>



Basically the code you have is correct.
You have included your configuration,
Extracted you php post variables from $_POST, although you may have to do some escaping but that is along the way.
You have created your query and gotten the result.

It would be good to count the number of rows returned from the query,
if it is more than zero, then write out all the results.
else if it is equal to zero, then you have to do your page redirect, but I dont see any reason why.

You might as well write a no result or no row message on the current page.

Hope this helps.

And please provide some feedback even if it don't.

Thanks.
Report
Re: how to correct search key Posted by bae on 17 Jul 2009 at 10:57 AM
well, i have started from row 1 due to $title=$_POST['title'];<<<<according to this command has begun from this row. Also, the row zero is id no need to assign because it is auto_increment(auto adding). However, the error are occur;

mysql_fetch_row() : supplied argument is not a valid MySQL result resource

via this line
while($result_row = mysql_fetch_row($result))


thanks for your answer
Report
Re: how to correct search key Posted by Agbagbara on 18 Jul 2009 at 8:11 PM
There is nothing wrong with the command, it is straigth forward, there must be something wrong with you configuration.

Try this command
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
if you dont get any error, then u know that there is something else wrong.

Make sure that you have a database selected, in your config file using.
mysql_select_db('my_database') or die('Could not select database');

also check that the configuration is correct? check for typographical errors.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.