Why is my HTML file not executing my php script?

I have a search form that is supposed to be used to search a SQL datab

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2347 Views - Last Post: 06 October 2009 - 06:02 AM Rate Topic: -----

#1 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Why is my HTML file not executing my php script?

Post icon  Posted 30 September 2009 - 06:46 AM

<html>
	<head>
		<title>Search Test</title>
	</head>

	<body topmargin="0" leftmargin="0">
	<FORM ACTION="search.php" METHOD="POST">
		   Search Term <input type="text" name="searchterm"><br />
			<input type="submit" value="Search">

		</form>

	</body>
</html>


Mod edit - Please :code:

This post has been edited by BetaWar: 30 September 2009 - 07:10 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Why is my HTML file not executing my php script?

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1104
  • View blog
  • Posts: 6,913
  • Joined: 07-September 06

Re: Why is my HTML file not executing my php script?

Posted 30 September 2009 - 07:09 AM

The form shouldn't be the problem (as it appears to be properly formed), it is likely the PHP giving you problems. Can we see the PHP code?
Was This Post Helpful? 0
  • +
  • -

#3 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Why is my HTML file not executing my php script?

Posted 30 September 2009 - 07:14 AM

View PostBetaWar, on 30 Sep, 2009 - 06:09 AM, said:

The form shouldn't be the problem (as it appears to be properly formed), it is likely the PHP giving you problems. Can we see the PHP code?


The search form tries to open or save the php file when I click on the search button. The file that I have includes the server IP, username for database, password for database, and SQL database name. The php script is below.


<?php
/*set varibles from form */
$searchterm = $_POST['searchterm'];
trim ($searchterm);
/*check if search term was entered*/
if (!$searchterm){
    echo 'Please enter a search term.';
}
/*add slashes to search term*/
if (!get_magic_quotes_gpc())
{
$searchterm = addslashes($searchterm);
}

/* connects to database */
@ $dbconn = new mysqli('host', 'username', 'password', 'database'); 
if (mysqli_connect_errno()) 
{
echo 'Error: Could not connect to database.  Please try again later.';
exit;
}
/*query the database*/
$query = "select * from tablename where tablerow like '%".$searchterm."%'";
$result = $dbconn->query($query);
/*number of rows found*/
$num_results = $result->num_rows;

echo '<p>Found: '.$num_results.'</p>';
/*loops through results*/
for ($i=0; $i <$num_results; $i++)
{
$num_found = $i + 1;
$row = $result->fetch_assoc();
echo "$num_found. ".($row['tablerow'])." <br />";
}
/*free database*/
$result->free();
$dbconn->close();
?>



*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 30 September 2009 - 08:05 AM

Was This Post Helpful? 0
  • +
  • -

#4 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: Why is my HTML file not executing my php script?

Posted 30 September 2009 - 07:33 AM

If it attempts to download the PHP file the it is possible that the server doesn't support PHP.

Are you uploading this to a host and if so do they support php, if its a local server does that support PHP.

We will need more info concerning how you store and access your site.
Was This Post Helpful? 0
  • +
  • -

#5 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Why is my HTML file not executing my php script?

Posted 30 September 2009 - 12:42 PM

View Postdanny_kay1710, on 30 Sep, 2009 - 06:33 AM, said:

If it attempts to download the PHP file the it is possible that the server doesn't support PHP.

Are you uploading this to a host and if so do they support php, if its a local server does that support PHP.

We will need more info concerning how you store and access your site.

I installed PHP 5.3 on my host server and it now recognizes the php files, but it still did not work. It is still trying to open or save the file. I am rebooting my system to see if that makes a difference.

This post has been edited by knockkneed81: 30 September 2009 - 12:44 PM

Was This Post Helpful? 0
  • +
  • -

#6 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -18
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Why is my HTML file not executing my php script?

Posted 30 September 2009 - 03:03 PM

View Postknockkneed81, on 30 Sep, 2009 - 11:42 AM, said:

View Postdanny_kay1710, on 30 Sep, 2009 - 06:33 AM, said:

If it attempts to download the PHP file the it is possible that the server doesn't support PHP.

Are you uploading this to a host and if so do they support php, if its a local server does that support PHP.

We will need more info concerning how you store and access your site.

I installed PHP 5.3 on my host server and it now recognizes the php files, but it still did not work. It is still trying to open or save the file. I am rebooting my system to see if that makes a difference.


you need my sql has well has php
:rolleyes:
Was This Post Helpful? 0
  • +
  • -

#7 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1104
  • View blog
  • Posts: 6,913
  • Joined: 07-September 06

Re: Why is my HTML file not executing my php script?

Posted 30 September 2009 - 03:06 PM

I would also suggest putting apache on your host system if it isn't there already. It makes things a lot easier to setup and modify later on.
Was This Post Helpful? 0
  • +
  • -

#8 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Why is my HTML file not executing my php script?

Posted 01 October 2009 - 07:03 AM

View PostBetaWar, on 30 Sep, 2009 - 02:06 PM, said:

I would also suggest putting apache on your host system if it isn't there already. It makes things a lot easier to setup and modify later on.



I currently have IIS on that server.
Was This Post Helpful? 0
  • +
  • -

#9 trizz  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 10-October 08

Re: Why is my HTML file not executing my php script?

Posted 01 October 2009 - 07:18 AM

View Postknockkneed81, on 1 Oct, 2009 - 06:03 AM, said:

View PostBetaWar, on 30 Sep, 2009 - 02:06 PM, said:

I would also suggest putting apache on your host system if it isn't there already. It makes things a lot easier to setup and modify later on.



I currently have IIS on that server.


That's no problem, but if you're webserver ("production server") uses Apache, strange things can happen... :)
Always try to have the same software (and versions) on your test and production server.
Was This Post Helpful? 0
  • +
  • -

#10 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Why is my HTML file not executing my php script?

Posted 01 October 2009 - 09:19 AM

View Posttrizz, on 1 Oct, 2009 - 06:18 AM, said:

View Postknockkneed81, on 1 Oct, 2009 - 06:03 AM, said:

View PostBetaWar, on 30 Sep, 2009 - 02:06 PM, said:

I would also suggest putting apache on your host system if it isn't there already. It makes things a lot easier to setup and modify later on.



I currently have IIS on that server.


That's no problem, but if you're webserver ("production server") uses Apache, strange things can happen... :)
Always try to have the same software (and versions) on your test and production server.


But looking at the php script, should it do a search of the SQL database and display the results on the screen?

This post has been edited by knockkneed81: 01 October 2009 - 09:20 AM

Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: Why is my HTML file not executing my php script?

Posted 01 October 2009 - 03:33 PM

$query = "select * from tablename where tablerow like '%".$searchterm."%'";


Is your table really called "tablename" and your column to search really called "tablerow"?

EDIT: Also, here:
if (!$searchterm){
    echo 'Please enter a search term.';
}
you probably want to use:
if (!empty($searchterm))

Note also that if the searchterm is empty, as you've coded it it will still continue on to the database, as you're not exiting or redirecting.
Was This Post Helpful? 0
  • +
  • -

#12 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Why is my HTML file not executing my php script?

Posted 02 October 2009 - 01:13 PM

View PostJackOfAllTrades, on 1 Oct, 2009 - 02:33 PM, said:

$query = "select * from tablename where tablerow like '%".$searchterm."%'";


Is your table really called "tablename" and your column to search really called "tablerow"?

EDIT: Also, here:
if (!$searchterm){
    echo 'Please enter a search term.';
}
you probably want to use:
if (!empty($searchterm))

Note also that if the searchterm is empty, as you've coded it it will still continue on to the database, as you're not exiting or redirecting.



I've made the edits and still no luck.
Was This Post Helpful? 0
  • +
  • -

#13 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Why is my HTML file not executing my php script?

Posted 05 October 2009 - 05:08 AM

View Postknockkneed81, on 2 Oct, 2009 - 12:13 PM, said:

View PostJackOfAllTrades, on 1 Oct, 2009 - 02:33 PM, said:

$query = "select * from tablename where tablerow like '%".$searchterm."%'";


Is your table really called "tablename" and your column to search really called "tablerow"?

EDIT: Also, here:
if (!$searchterm){
    echo 'Please enter a search term.';
}
you probably want to use:
if (!empty($searchterm))

Note also that if the searchterm is empty, as you've coded it it will still continue on to the database, as you're not exiting or redirecting.



I've made the edits and still no luck.


What do I need to change in this code to make it work? I need it the code to pull the results to a new window or the existing window. I was tasked with this and in no way, shape, or form am I a developer. I really take my hat off to you guys and gals. Any help is appreciated.

 <?php
/*set varibles from form */
$searchterm = $_POST['searchterm'];
trim ($searchterm);
/*check if search term was entered*/
if (!$searchterm){
echo 'Please enter a search term.';
}
/*add slashes to search term*/
if (!get_magic_quotes_gpc())
{
$searchterm = addslashes($searchterm);
}

/* connects to database */
@ $dbconn = new mssql('192.xxx.xxx.xx', 'username', 'password', 'database'); 
if (mssql_connect_errno()) 
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
/*query the database*/
$query = "select * from CallLog where CallID like '%".$searchterm."%'";
$result = $dbconn->query($query);
/*number of rows found*/
$num_results = $result->num_rows;

echo '<p>Found: '.$num_results.'</p>';
/*loops through results*/
for ($i=0; $i <$num_results; $i++)
{
$num_found = $i + 1;
$row = $result->fetch_assoc();
echo "$num_found. ".($row['tablerow'])." <br />";
}
/*free database*/
$result->free();
$dbconn->close();
?>


This post has been edited by knockkneed81: 05 October 2009 - 05:23 AM

Was This Post Helpful? 0
  • +
  • -

#14 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Why is my HTML file not executing my php script?

Posted 05 October 2009 - 05:54 AM

Hypothetically, Is this script supposed to work? I have the file saved as HTML.

<h2>Search for ticket by Call ID</h2>

<form name="search" method="get" action="<?=$PHP_SELF?>">
  Enter Call ID Number: <input type="text" name="find" /> 
  <input type="hidden" name="searching" value="yes" />
  <input type="submit" name="search" value="Search" />
</form>

<?php
  if ($searching =="yes"){
	echo "<h3>Search Results</h3><p>";
	if ($find == ""){
	  echo "<p>Please Enter a search term";
	  exit;
	}
	
	//connect to your database ** EDIT REQUIRED HERE **
mssql_connect("192.xxx.xxx.xx","usernam","password"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mssql_select_db("database") or die("Unable to select database"); //select which database we're using

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

	$query = mssql_query("SELECT * FROM CallLog WHERE CallID LIKE'%$find%'");
	while($result = mssql_fetch_array($query)){
	  echo $result['fname'];
	  echo " ";
	  echo $result['lname'];
	  echo "<br>";
	  echo $result['designation'];
	  echo "<br>";
	  echo "<br>";
	}

	$matches=mssql_num_rows($query);
	if ($matches == 0){
	  echo "Sorry, we can not find an entry to match your query<br><br>";
	}

	echo "<b>Searched For:</b> " .$find;
  }
?>  

Was This Post Helpful? 0
  • +
  • -

#15 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Why is my HTML file not executing my php script?

Posted 05 October 2009 - 06:09 AM

The php in this line:
<form name="search" method="get" action="<?=$PHP_SELF?>">


isn't currently writing anything to the html. You need to echo the value of PHP_SELF like this:
<form name="search" method="get" action="<? echo $SERVER['PHP_SELF']; ?>">



...and no, this will not work if the file is saved as html. Your file must be saved as .php and be viewed via a web server.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2