Page 1 of 1

Script on two servers

Posted: Thu Jul 17, 2008 3:13 pm
by chopper_pc
I have used this script for quite some time on a site hosed at a hosting company (Linux,Apache/Mysql). Works great.
I am developing a similar site on my laptop (Ubuntu/Apache/Mysql) now and the script does nothing, it returns nothing at all no matter what I search for.
Can anyone give me an idea of where I can begin to research to find out why it will not respond on one server yet runs fine on another.

Code: Select all

 
    <form name="search" method="post" action="<?=$PHP_SELF?>">
    Seach for: <input type="text" name="find" /> in
    <Select NAME="field">
    <Option VALUE="name">Name</option>
    <Option VALUE="contact">Contact</option>
    <Option VALUE="phone">Phone</option>
    </Select>
    <input type="hidden" name="searching" value="yes" />
    <input type="submit" name="search" value="Search" />
    </form>
    
    <?php
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results for: $find </h2><p>";
 
 
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
 
// Otherwise we connect to our Database
mysql_connect("localhost", "sqluser", "sqlpasswd") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
 
// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
 
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM table WHERE upper($field) LIKE'%$find%'");
 
//And we display the results
while($result = mysql_fetch_array( $data ))
{
 
 
$name = $result['name'];
$contact = $result['contact'];
$altcontact = $result['altcontact'];
$address = $result['address'];
$phone = $result['phone'];
$fax = $result['fax'];
$cell = $result['cell'];
$altphone = $result['altphone'];
$current = $result['current'];
$destination = $result['destination'];
$special = $result['Special'];
echo "<table width=1200 border=1>";
echo "<tr><td width=50%><b> $name </td><td><b>Special Instructons:</td></tr>";
echo "<tr><td><b>Contact:</b> $contact <br>";
echo "<b>Alt. Contact:</b> $altcontact <br>";
echo "<b>Address:</b> $address <br>";
echo "<b>Phone:</b> $phone";
echo "<b>Fax:</b> $fax";
echo "<b>Cell:</b> $cell <br>";
echo "<b>Email:</b> $altphone <br>";
echo "<b>Currently Using:</b> $current<br>";
echo "<b>Destinations:</b> $destination<br>";
echo "<td> $special </tr></td>";
echo "<br>";
 
 
}
 
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
 
}
}
?>
 

Re: Script on two servers

Posted: Thu Jul 17, 2008 3:15 pm
by s.dot
You're relying on register_globals being on.

$searching should be $_POST['searching'], $find should be $_POST['find'], etc..

Also <?=$_SERVER['PHP_SELF'] is relying on short_open_tags being enabled. Instead this should be <?php echo $_SERVER['PHP_SELF']; ?> (well, really you shouldn't use $_SERVER['PHP_SELF'], use the script name instead).