Jump to content

Not THAT urgent, offer your free help at any time you wish


sabo86

Recommended Posts

hello there.. am new to php and mysql stuffs...

and really need your help..

I've taken this code from a tutorial, and it didn't work for my database...

the html code is:

<html>
<head>
<title> Fleifel's Browser</title>
</head>
<body>
<h1> Fleifel's Browser</h1>
<form action="results.php" method="post">
Browse the Category you want: <br>
<select name="searchtype">
<option value"Accessories">Accessories
<option value="European Office Furniture"> European Office Furniture
<option value="Local Office Furniture"> Local Office Furniture
<option value="School and University Furniture"> School and University Furniture
<option value="Seatings"> Seatings
</select>
<br>
Enter Search Term:<br>
<input name="searchterm" type=text />
<br />
<input type="submit" value="Search" />
</form>
</body>
</html>

and the php code is

<html>
<head>
  <title>Fleifel</title>
</head>
<body>
<h1>Fleifel</h1>
<?
  if (!$searchtype || !$searchterm)
  {
     echo "You have not entered search details.  Please go back and try again.";
     exit;
  }
  
  $searchtype = addslashes($searchtype);
  $searchterm = addslashes($searchterm);
//
//  You will need to change the $database variable value to be your grace
//  user ID
//
  $database = "fleifel";

  @ $db = mysql_connect("localhost", $database);

  if (!$db)
  {
     echo "Error: Could not connect to database server.  Please try again later.";
     exit;
  }

  @ $ok = mysql_select_db($database);

  if (!$ok)
  {
     echo "Error: Could not select database: $database.  Please try again later.";
     exit;
  }

  $query = "select * from item where ".$searchtype." like '%".$searchterm."%'";
  $result = mysql_query($query);

  $num_results = mysql_num_rows($result);

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


  for ($i=0; $i <$num_results; $i++)
  {
     $row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).".Model:";
echo htmlspecialchars(stripslashes($row["Model"]));
echo "</strong><br> Description:";
echo htmlspecialchars (stripslashes($row["Description"]));
}

?>

</body>
</html>

 

 

After I perform the search, I get the following result:

Fleifel
Number of books found: ".$num_results."

"; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); echo "

".($i+1).".Model:"; echo htmlspecialchars(stripslashes($row["Model"])); echo "
Description:"; echo htmlspecialchars (stripslashes($row["Description"])); } ?>

 

 

Suggestions please

Link to comment
Share on other sites

The script you have has two issues:

 

- It uses short tags (<?) not all PHP configurations have short_open_tag enabled. You should always use full PHP tags (<?php ?>)

- It replies on register_globals. Register_globals is now depreciated and is disabled by default. It is soon to removed completely as of PHP6

Link to comment
Share on other sites

Wildteen is too courteous.

 

I already locked this because of the title. Read the forum rules!

 

# DON'T Describe your question or problem as urgent, super important, must have by tommorrow etc...

The people who are answering your questions are contributing their time and expertise for free. If you have an urgent problem and need priority help, consider advertising in the Freelancing forum.

 

Unlocked, but just as easily locked next time.

Link to comment
Share on other sites

Wildteen is too courteous.

 

I already locked this because of the title. Read the forum rules!

 

# DON'T Describe your question or problem as urgent, super important, must have by tommorrow etc...

The people who are answering your questions are contributing their time and expertise for free. If you have an urgent problem and need priority help, consider advertising in the Freelancing forum.

 

Unlocked, but just as easily locked next time.

Was this locked? I didn't realise it had been.

Link to comment
Share on other sites

Oh thanks for that remark.. I think we have something  new.. the result.php page is showing the following:

 

Notice: Undefined variable: searchtype in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 9

You have not entered search details. Please go back and try again.

 

& line 9 in my code is:

if (!$searchtype || !$searchterm)

 {

    echo "You have not entered search details.  Please go back and try again.";

    exit;

 }

 

 

!!!

Link to comment
Share on other sites

That's how i edited it:

if (!$_POST['searchtype'] || !$_POST['searchterm'])

  {

    echo "You have not entered search details.  Please go back and try again.";

    exit;

  }

 

  $_POST['searchterm'] = addslashes(  $_POST['searchterm']);

  $_POST['searchterm'] = addslashes($_POST['searchterm']);

Link to comment
Share on other sites

Now i am getting results, but not as I really want..

I edited the $query variable to:

  $query = "select * from items where Category = '%".$_POST['searchtype']."%'";

I am getting 0 results

Is there a way that I want to get results selected from the drop menu?

Link to comment
Share on other sites

I am just new in programming.. execuse me  ::)

 

Now i modified it to:

  $query = "select * from items where Category = '.$_POST['searchtype'].'";

 

I got this error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 42

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.