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
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');

 

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.