Connecting to mysql after PHP5 upgrade

One of my scripts no longer works after my server upgraded to PHP5.2. From what I have read (but have been unable to find the solution) this is because of the lack of a library in PHP5. I’m not sure what to do to get this to work again. Any tips or help? I don’t think there are any problems in the PHP script (it worked before), but I will post it here if anyone thinks it is necessary to solve the issue.

After further testing I think the problem is in the php code just not working right with PHP5. Here is the code that worked in PHP4, maybe something will stand out obvious as the problem:

[php]<?
//This is only displayed if they have submitted the form
if ($searching ==“yes”)
{

echo "<div class=“GeneralTopCurve”> ";

echo “<div class=“GeneralContent”>”;

echo “Available Visual Guides
”;

echo “<div class=“VGSearchBox”>”;

//If they did not enter a search term we give them an error
if ($find == “”)
{
echo “

You forgot to enter a search term”;
exit;
}

// Otherwise we connect to our Database
mysql_connect(“xyz”, “xyz”, “xyz”) or die(mysql_error());
mysql_select_db(“xyz”) or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//search criteria

$query = ‘SELECT * FROM guides WHERE CONCAT(series,type,origin,mfg,keywords,year,name) LIKE "%’ . implode(’%" AND CONCAT(series,type,origin,mfg,keywords,year,name) LIKE “%’, preg_split(’/\s+/’,$_POST[‘find’])) . '%” ORDER BY year,series,type,name’;

$data = mysql_query($query);

while($result = mysql_fetch_array( $data ))

{
echo ’

';
echo $result[‘series’];
echo ’
'; echo $result['mfg']; echo '
';

echo ‘';
echo $result['name'];
echo '’;

echo ’

'; echo $result['type']; echo '
'; echo $result['year']; echo '
'; echo $result['link']; echo '
'; }

//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

”;
}

//And we remind them what they searched for
echo “”;
echo “Your current search (” .$find;
echo “) returned " .$anymatches;
echo " results.”;
echo “

”;
}

echo “<p class=“p-centerNoBorder”>-Click <A HREF=”/search" >HERE to make another search-

";

echo “”;
echo “<div class=“NewsBottom”>”;
echo " <table width=“660” border=“0” cellpadding=“0” cellspacing=“0” class=“tbl”>

";
echo " <td class=“tbll”><img src="/content/themes/JTA/images/spacer.gif" alt="" width=“8” height=“4” />";
echo " <td class=“tblbot”><img src="/content/themes/JTA/images/spacer.gif" alt="" width=“8” height=“4” />";
echo " <td class=“tblr”><img src="/content/themes/JTA/images/spacer.gif" alt="" width=“8” height=“4” />";
echo " ";
echo “”;

echo “<p class=“p-centerNoBorder”>-Click <A HREF=”/" >HERE to return to the home page-

";
?>[/php]

hello,

when you say is no longer working, what do you mean to be specific?

[ul][li]Blank Page?[/li]
[li]fatal error??[/li]
[li]no error but still does not work?[/li][/ul]

It produces a blank page

I was checking thru all the codes and everything seens correct to me. part of the codes will only display after some statements are met which are met after submit the proper form. i would like to test this script on my localhost. can u please attach the form file. the query sql file with at least 2 or 3 records for to work on and test it.

I don’t see any parse errors. Try this:

  1. use <?php instead of <?
  2. add the following lines to the top of your script:
    [php]
    ini_set(‘display_errors’,1);
    error_reporting(32767);
    [/php]
  3. Change the $data = line as follows:
    [php]$data = mysql_query($query) or die(mysql_error());[/php]

I get this error:

Notice: Undefined variable: searching in /home/content/j/t/a/jtaadmin/html/search/search-old.php on line 16

Also of note, if I remove this part of the code:

[php]if ($searching ==“yes”) { [/php]

as well as the bracket at the end, the search works. The only thing that fails is it doesn’t display the term searched for at the end of the results.

So, at the end I get of the search I get:

Your current search () returned 74 results.

That notice is being thrown because $searching is not set anywhere. Are you including this script from within another script? If not, $searching will always be undefined. Where is it supposed to come from? You will experience the same issue with $find. I suspect that you want to use either $_GET[“searching”] or $_POST[“searching”] - depending on the method= attribute of your form tag. for use $_POST[“searching”] in place of $searching, for use $_GET[“searching”]. Alternatively, you can use $_REQUEST[“searching”] and you don’t have to worry about your form method, but you would need to be careful if you use a combination of post and get methods, which I do all the time.

OK, I replaced

[php]if ($searching ==“yes”) {[/php]

with

[php]if ($_POST[“searching”] ==“yes”) {[/php]

And the page ran and loaded fine. I still get this at the end of the results:

Your current search () returned 30 results.

The search term is supposed to be in the ( ) but it is coming up empty.

$_POST[“find”]

Thank you! That was what did it. All seems to be working now.

Thanks for your troubleshooting!

Sponsor our Newsletter | Privacy Policy | Terms of Service