nsForum logo

Welcome Guest ( Log In )

 
Reply to this topicStart new topic
> Access To Mysql Database, PHP Script No Longer Opening Database
Aspals
post Oct 2 2013, 06:54 AM
Post #1





Group: Verified NS Member
Posts: 4
Joined: 26-September 10
Member No.: 11,249



Hello

I am asking for some help with a database problem.

I have an on-line case database which, until recently, was fully searchable through a small php script. Suddenly it stopped working and I cannot understand what is wrong, as I haven't changed the script. The only thing I can think of is that there is no longer a connection to the database.

The web address is http://www.aspals.com/search/search.php

It can be seen that none of the default messages are displayed, nor the search results.

Here is a taster:

<html>
<head>
</head>
<body bgcolor="#fcfde3">

<a href="http://www.[removed].com"><img style="Z-INDEX: -1; POSITION: absolute; TOP: 15px; RIGHT: 200px" img src="http://www.aspals.com/images/badgeclear.gif" width="82" height="90" title="" border="0" align="bottom" /></a>

<a name="top"></a>
<h2>Search the <span style="font-family: 'Monotype Corsiva'; font-weight: normal; font-style: normal; text-decoration: none; font-size: 16pt; color: #FF0000;">Aspals</span> Cases Database</h2>

<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="Name">Case Name</option>
<Option VALUE="Reference">Case Reference</option>
<Option VALUE="Subject">Subject</option>
<Option VALUE="Summary">Summary</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="Search" value="Find It" />
</form>

<a name="top"></a>

<?php

//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</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;
}


mysql_connect("MySql database address", "my username", "password") or die(mysql_error());
mysql_select_db("aspalscases") or die(mysql_error());

$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

$data = mysql_query("SELECT * FROM caselist WHERE upper($field) LIKE '%$find%' ORDER BY Name ASC");
$num=mysql_numrows($data);

while($result = mysql_fetch_array( $data ))
{
?>
<b>
<?
echo $result['Name']; echo ":"; echo "&nbsp;&nbsp;"; echo $result['Reference'];
echo "</b><br>";
?>
<span style="font-family: Calibri; font-weight: normal; font-style: normal; text-decoration: none;"><font color="#FF0000"><b>
<?
echo $result['Subject'];
echo "</font><br></b>";
echo $result['Summary'];
echo "<br>";
$str = $result['Access'];
$str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $str);
echo $str;
echo "<br>";
echo "<br>";
}
?></span>

<?

$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we cannot find an entry to match your query<br><br>";
}

echo "<b>Searched For:</b> " .$find;
echo "&nbsp;&nbsp;-&nbsp; $anymatches &nbsp; matches found";
}

?>


</body>
</html>


What should happen, if a connection to the database is made, the results are displayed to the query or, of course, a non-found query should produce the message "Sorry, but we cannot find an entry to match your query" .

Unfortunately, this is not displayed which is why I believe the database conection has been lost.

Grateful for any help or hints.

Thanks

Anthony
Go to the top of the page
 
+Quote Post
Craig
post Oct 2 2013, 08:27 PM
Post #2





Group: Administrators
Posts: 844
Joined: 23-June 08
From: Pennsylvania
Member No.: 1,317



QUOTE (Aspals @ Oct 2 2013, 07:54 AM) *
Hello

I am asking for some help with a database problem.

I have an on-line case database which, until recently, was fully searchable through a small php script. Suddenly it stopped working and I cannot understand what is wrong, as I haven't changed the script. The only thing I can think of is that there is no longer a connection to the database.

The web address is http://www.aspals.com/search/search.php

It can be seen that none of the default messages are displayed, nor the search results.

Here is a taster:

<html>
<head>
</head>
<body bgcolor="#fcfde3">

<a href="http://www.[removed].com"><img style="Z-INDEX: -1; POSITION: absolute; TOP: 15px; RIGHT: 200px" img src="http://www.aspals.com/images/badgeclear.gif" width="82" height="90" title="" border="0" align="bottom" /></a>

<a name="top"></a>
<h2>Search the <span style="font-family: 'Monotype Corsiva'; font-weight: normal; font-style: normal; text-decoration: none; font-size: 16pt; color: #FF0000;">Aspals</span> Cases Database</h2>

<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="Name">Case Name</option>
<Option VALUE="Reference">Case Reference</option>
<Option VALUE="Subject">Subject</option>
<Option VALUE="Summary">Summary</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="Search" value="Find It" />
</form>

<a name="top"></a>

<?php

//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</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;
}


mysql_connect("MySql database address", "my username", "password") or die(mysql_error());
mysql_select_db("aspalscases") or die(mysql_error());

$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

$data = mysql_query("SELECT * FROM caselist WHERE upper($field) LIKE '%$find%' ORDER BY Name ASC");
$num=mysql_numrows($data);

while($result = mysql_fetch_array( $data ))
{
?>
<b>
<?
echo $result['Name']; echo ":"; echo "&nbsp;&nbsp;"; echo $result['Reference'];
echo "</b><br>";
?>
<span style="font-family: Calibri; font-weight: normal; font-style: normal; text-decoration: none;"><font color="#FF0000"><b>
<?
echo $result['Subject'];
echo "</font><br></b>";
echo $result['Summary'];
echo "<br>";
$str = $result['Access'];
$str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $str);
echo $str;
echo "<br>";
echo "<br>";
}
?></span>

<?

$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we cannot find an entry to match your query<br><br>";
}

echo "<b>Searched For:</b> " .$find;
echo "&nbsp;&nbsp;-&nbsp; $anymatches &nbsp; matches found";
}

?>


</body>
</html>


What should happen, if a connection to the database is made, the results are displayed to the query or, of course, a non-found query should produce the message "Sorry, but we cannot find an entry to match your query" .

Unfortunately, this is not displayed which is why I believe the database conection has been lost.

Grateful for any help or hints.

Thanks

Anthony

Your script is dependant on Register Globlas being on. In the latest PHP update, Register Globals was turned off by default.
Rather than checking for the form fields like " if ($searching =="yes") " you need to use " if ($_POST['searching'] =="yes") " (http://php.net/manual/en/security.globals.php).
Go to the top of the page
 
+Quote Post
Aspals
post Oct 3 2013, 02:43 AM
Post #3





Group: Verified NS Member
Posts: 4
Joined: 26-September 10
Member No.: 11,249



QUOTE (Craig @ Oct 2 2013, 09:27 PM) *
Your script is dependant on Register Globlas being on. In the latest PHP update, Register Globals was turned off by default.
Rather than checking for the form fields like " if ($searching =="yes") " you need to use " if ($_POST['searching'] =="yes") " (http://php.net/manual/en/security.globals.php).



Many thanks for your help. I wondered what the problem was. Thanks also for the PHP link.

I shall amend my script and try again.

Kind regards

Anthony
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version    Network Solutions © 2011 Time is now: 19th December 2014 - 10:22 AM
Domain Names | Web Hosting | Web Design | Shopping Cart Software | Online Marketing | SSL Certificates