Jump to content

Searching the database problem


sted999

Recommended Posts

Hiya all. I am new to PHP and am currently having trouble searching my database. All I am getting is a blank page and its driving me up the wall!!

 

If anyone can be of assistance i would be sooooooo grateful.

 

Thanks,

Stephen.

 

Form code

<form action="search_results.php" method="post" id="searchForm">

               

                <div class="row">

                    <span class="label">

                            <label for="startPoint">Enter your start point:</label>

                        </span>

                        <span class="formw">

                            <input type="text" size="20" maxlength="15" name="startTown" id="sPoint" />

                            <br />

                            <br />

                        </span>

                </div>

               

                <div class="row">

                    <span class="label">

                            <label for="startPoint">Enter your destination:</label>

                        </span>

                        <span class="formw">

                            <input type="text" size="20" maxlength="15" name="destinationTown" id="dPoint" />

                            <br />

                            <br />

                        </span>

                </div>

 

Search code

<?php

 

            $startTown=trim($_POST['startTown']);

            $destinationTown=trim($_POST['destinationTown']);

           

if (!$startTown || !$destinationTown)

{

echo 'You have not entered a start or destination point. Please go back and try again.';

exit;

}

 

if (!get_magic_quotes_gpc())

{

$startTown = addslashes($startTown);

$destinationTown = addslashes($destinationTown);

}

 

@ $db = new mysqli('####', '####', '####', '####);

 

if (mysqli_connect_errno())

{

  echo 'Error. Could not conect to database, please contact the website adminsitrator';

  exit;

}

 

$query = "SELECT * FROM Journey WHERE ".$startTown." like '%".$destinationTown."%'";

$result = $db->num_rows;

 

$num_results = $result->num_rows;

 

echo "<p>Number of matches found: ".$num_results."</p>";

 

for ($i=0; $i < $num_results; $i++)

{

  $row = $result->fetch_assoc();

  echo "<p><strong>".($i+1).". Journey name: ";

  echo htmlspecialchars(striplashes($row['journeyName']));

  </strong></p>

}

 

$result->free();

$db->close();

         

            ?>

Link to comment
https://forums.phpfreaks.com/topic/151597-searching-the-database-problem/
Share on other sites

First thing I noticed is your missing echo on your close strong tag

 

echo "<p><strong>".($i+1).". Journey name: ";
              echo htmlspecialchars(striplashes($row['journeyName']));
              </strong></p>
            }

 

If you enable display errors and error reporting, you won't get a blank screen on errors, but will see the actual problem.

 

Second thing I noticed is that you don't set the $row array anywhere.

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.