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

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.