Dear friends,

I have created a html page with dynamic select boxes and included the below line in the form <form action="sqlpage.php"target="_blank" method="post">. The mentioned sqlpage.php contains some php code which connects to MySQL DB and search for queries and displays the results on a webpage.

But when i run the html page and enter search terms in the query box and click search it directs to this sqlpage and i don't see any results but the php code is displayed as it it on the page. This is bcoz i guess that html page is not interpreting this action sqlpage.php.

I would be thankful if someone help me in this matter.

Thanks in advance.

Kind Regards
Aravind

Recommended Answers

All 9 Replies

Have you install php editor for that....you require Apache server for that...So check whether you have that or not....otherwise download WAMP Server,Xampp server...

you are required to install php, mysql to run .php files so simply download XAMPP and install it into your local machine

try using calling php in ajax which is in an html doc

Member Avatar for diafol

Is there a reason to give target="_blank" ?

Dear All,

Thanks for your replies. I have installed WAMP and then started coding HTML and PHP but i have no clue why i get this problem.....i have used target=_blank as i want my result page in a new tab or new window. Could someone think of a solution.

Thanks in advance.

Cheers,
Aravind

Post that 'sqlpage.php'.

<html>
<head>
<title>Query results</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
 
<?php
header("content-type: application/x-javascript");
$class=  $_GET["class"];
$subclass= $_GET["subclass"]; 
$subject = $_GET["subject"];

echo("Searching for entries with Class = $class, Subclass = $subclass and Subject = $subject")."<br />";

$link = mysql_connect('localhost','root'); 
if (!$link) { 
	die('Could not connect to MySQL database ' . mysql_error()); 
} 
echo 'Connected to the Database. Please scroll down for the results'. "<br />";
mysql_select_db("Human-Mouse") or die(mysql_error());
// Query statement with Inner join
if ($subject == NULL && $subclass != "All")
{
$result = mysql_query("SELECT * FROM differences d INNER JOIN `references` r on d.reference = r.reference WHERE class = '$class' AND subclass LIKE '%$subclass%'") or die (mysql_error());
}
else if($subclass == "All" && $subject != NULL)
{
$result = mysql_query("SELECT * FROM differences d INNER JOIN `references` r on d.reference = r.reference WHERE class = '$class' AND subject LIKE '%$subject%' OR human LIKE '%$subject%' OR mouse LIKE '%$subject%'") or die (mysql_error());
} 
else if($subclass == "All" && $subject == NULL)
{
$result = mysql_query("SELECT * FROM differences d INNER JOIN `references` r on d.reference = r.reference WHERE class = '$class'") or die (mysql_error());
} 
else
{
$result = mysql_query("SELECT * FROM differences d INNER JOIN `references` r on  d.reference = r.reference WHERE class ='$class' AND subclass LIKE '%$subclass%' AND subject LIKE '%$subject%' OR human LIKE '%$subject%' OR mouse LIKE '%$subject%'")
or die(mysql_error());
}
if (mysql_num_rows($result)==0 ) 
{
    die('Sorry. No results could be found with your query. Please try with other keywords.' . mysql_error());
}

 echo '<table border="1">';
 echo '<tr>';
 // Columns names of the table
 echo '<th>Class</th><th>Subclass</th><th>Subject</th><th>Human</th><th>Mouse</th><th>Reference</th>';
 echo  '</tr>';
 while($row = mysql_fetch_array($result))
{
// linking the reference key to its url	
$hyperlink = '<a href = "'.$row[9].'" target="_blank">'.$row[6].'</a>';     
	 // start of a new row 
	   echo '<tr>'; 
   //loop through elements (ie td's)
    echo "<td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td><td>$hyperlink</td>";
    echo "<br />";
	echo '</tr>';
 }    
	echo '</table>';
mysql_free_result($result);	
?>

<body>
</body>
</html>

From your first post you setup your form to use the POST method but your PHP page references $_GET variables. You should change $_GET to $_POST so that your form data is sent over to the PHP page.
I have had the same issue with WAMP and XAMPP where my PHP code is displayed as if I'm looking at a text file. I ended up uninstalling WAMP and re-installing XAMPP to fix it although I think it's got something to do with the permissions of the htdocs folder (Windows doesn't like the use Unix permissions on their folders, so it's not the easiest to change in my opinion).
Hope this gives you some direction.

thanks to aall for trying.....i have solved the problem......its due to error in the installation and configuaration of PHP and HTML details in the WAMP server......now its running as i expected.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.