PDA

View Full Version : Communication problem between html and php files


user_marko
04-21-2011, 03:26 PM
Hi ,

I am new to php / mysql and using dreamweaver to start since it seems easier . I have created a database in XAMPP and also a connection to a php results page and everything seems to be ok with the connection . Now I am trying to create a very simple search option on a html page which should bring up the results on the php page using URL parameters . So when I try the php page using Live View and puting the desired parameters it works correctly but when opening the html page ( mozilla browser ) and clicking submit on the form the results will not show on the php page . Here are my codes :

html search form :

<form id="form1" name="form1" method="get" action="results.php">
<label for="to">to</label>
<select name="to" id="to">
<option value="Bangkok">Bangkok</option>
</select>
submit
<input type="submit" name="submit" id="submit" value="Submit"/>
</form>php results page ( results.php )

<?php require_once('Connections/flights.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "-1";
if (isset($_GET['to'])) {
$colname_Recordset1 = $_GET['to'];
}
mysql_select_db($database_flights, $flights);
$query_Recordset1 = sprintf("SELECT * FROM schedules WHERE `to` = %s", GetSQLValueString($colname_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $flights) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$colname_Recordset1 = "-1";
if (isset($_GET['to'])) {
$colname_Recordset1 = $_GET['to'];
}
mysql_select_db($database_flights, $flights);
$query_Recordset1 = sprintf("SELECT * FROM schedules WHERE `to` = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $flights) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body,td,th {
font-size: 16px;
color: #000;
}
</style>
</head>

<body>
<table border="1">
<tr>
<td>from</td>
<td>to</td>
<td>start date</td>
<td>arrival date</td>
<td>start time</td>
<td>arrival time</td>
<td>flight number</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['from']; ?></td>
<td><?php echo $row_Recordset1['to']; ?></td>
<td><?php echo $row_Recordset1['start date']; ?></td>
<td><?php echo $row_Recordset1['arrival date']; ?></td>
<td><?php echo $row_Recordset1['start time']; ?></td>
<td><?php echo $row_Recordset1['arrival time']; ?></td>
<td><?php echo $row_Recordset1['flight number']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
as I said before the connections to database should be ok since I have done tests and also on the live view mode it works perfectly ,

thanks a lot for your help

EagerNewby
04-26-2011, 09:58 AM
Did you try inserting a require_once function above the DOCTYPE heading on your HTML page to refer to your php page:

i.e.

<?php
require_once('results.php');
?>

Then open the HTML page in your test browser or live view.

edbr
04-27-2011, 12:52 AM
"SELECT * FROM schedules WHERE `to` = %s"

so if you echo $s what do you get?

user_marko
04-28-2011, 11:58 PM
thanks for your answers , I could not get it to work , anyways I have to start working on a website for a new customer so I will get back on this later , but thanks again , your help is appreciated !!!