Jump to content

Form won't work in PHP5


brucieboy22

Recommended Posts

Hi,

 

I'm a novice when it comes to PHP. I have tried to run the below within PHP5, but for some reason the behavious is wrong. The code doesn't execute. It's obviously a type of some sorts, but under PHP4 it works fine. Any help would be appreciated.

 

<form name="search" method="post" action="<?=$PHP_SELF?>">

  <select name="field">

    <option value="Artist" name="artist">Artist</option>

    <option value="Label" name="label">Label</option>

<option value="Title" name="title">Title</option>

  </select>

  <input type="text" size="25" name="find">

<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")

{

 

//If they did not enter a search term we give them an error

if ($find == '')

{

echo "<div align=\"center\"><strong>You forgot to enter a search term</strong></div>";

exit;

}

 

etc, .....

Link to comment
https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/
Share on other sites

Many thanks monkeybidx for the promt reply. This fixed the code, I've now got another problem and attach the entire piece. It now 'blows up' about :-

 

mysql_num_rows(): supplied argument is not a valid MySQL result resource, and

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

<?php

 

//This is only displayed if they have submitted the form

if ($_POST['searching'] == "yes")

{

 

//If they did not enter a search term we give them an error

if ($_POST['find'] == '')

{

echo "<div align=\"center\"><strong>You forgot to enter a search term</strong></div>";

exit;

}

 

// 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 *,DATE_FORMAT(Released, '%M %Y') AS date FROM music_data WHERE upper($field) LIKE '%$find%'");

 

//This counts the number or results

 

$anymatches=mysql_num_rows($data);

if ($anymatches == '0')

{

echo "<div align=\"center\"><strong>Sorry, but I can not find any records to match your query of $find</strong></div><br><br>";

}

elseif ($anymatches >= '1') {

print "

<p align=\"center\"><strong>I found $anymatches record(s) matching your search of $find</strong></p>";

}

 

//And we display the results

 

while($result = mysql_fetch_array( $data ))

{

  $title = $result['Title'];

 

etc, ...

 

Sorry to be a pain :-)

You most probably have an error within your query, change this line:

$data = mysql_query("SELECT *,DATE_FORMAT(Released, '%M %Y') AS date FROM music_data WHERE upper($field) LIKE '%$find%'");

To:

$data = mysql_query("SELECT *,DATE_FORMAT(Released, '%M %Y') AS date FROM music_data WHERE upper($field) LIKE '%$find%'") or die(Query error: ' . mysql_error());

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.