Jump to content

[SOLVED] Help with strange php problem


buds2000

Recommended Posts

What woul cause a search string from my form not to be seen by the php script it calls. The same form and script work fine on one table but not another?

 

Here is the html....

 

<html>

<head><title>Searching</title>

</head>

<body bgcolor=#ffffff>

<form method="post" action="writers.php">

Search the Database for<BR> listings by the writers name.<BR>

<table border=1 align=left>

<tr><td align=right><B>Search for:</B></td><td><input type=text name='writer' style="background:#9BADCA" size=20 maxlength=255></td></tr>

<tr><td></td><td align=right><input type=submit></td></tr>

</table>

</form>

</body>

</html>

 

Here is the php...

 

<?

include("config.php");

 

if ($srch) // perform search only if a string was entered.

{

include("opendb.php");

 

$query = "select * from writers WHERE name = '$writer'";

$result = mysql_query($query) or die('Error, query failed');

 

if ($result)

{

echo "Here are the results:<br><br>";

echo "<table width=90% align=center border=1><tr>

<td align=center bgcolor=#00FFFF>Name</td>

<td align=center bgcolor=#00FFFF>Publishing</td>

</tr>";

 

while ($r = mysql_fetch_array($result)) { // Begin while

  $name=$r["name"];// Writers Name

  $pubtag=$r["pubtag"];// Publisher

echo "<tr>

<td>$name</td>

<td>$pubtag</td></tr>";

 

} // end while

echo "</table>";

} else { echo "problems...."; }

} else {

echo "Search string is empty. <br> Go back and type a string to search";

}

?>

=======================================================================

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/56819-solved-help-with-strange-php-problem/
Share on other sites

Change this

<?
include("config.php");

if ($srch) // perform search only if a string was entered.
{
include("opendb.php");

$query = "select * from writers WHERE name = '$writer'";
$result = mysql_query($query) or die('Error, query failed');

 

To this and try:

 

<?
include("config.php");
$writer=stripslahes($_POST['writer']);
if ($srch) // perform search only if a string was entered.
{
include("opendb.php");

$query = "select * from writers WHERE name = '$writer'";
$result = mysql_query($query) or die('Error, query failed');

 

Ok try this bcoz u have error in ur form:

 

<html>
<head><title>Searching</title>
</head>
<body bgcolor=#ffffff>
<form method="post" action="writers.php">
Search the Database for<BR> listings by the writers name.<BR>
<table border=1 align=left>
<tr><td align=right><B>Search for:</B></td><td><input type=text name='writer' style="background:#9BADCA" size=20 maxlength=255></td></tr>
<tr><td></td><td align=right><input type=submit name='search' Value='Search'></td></tr>
</table>
</form>
</body>
</html>

 

Now in ur php code change to this:

<?php
include("config.php");

if (isset($_POST['search'])) // perform search only if a string was entered.
{
include("opendb.php");
$writer=mysql_real_escape_string($_POST['writer']);
$query = "select * from writers WHERE name = '$writer'";
$result = mysql_query($query) or die('Error, query failed');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.