- This topic is empty.
-
AuthorPosts
-
April 29, 2014 at 2:06 pm #168884
ben_foyster
ParticipantHey Guys,
I was hoping you could help.
I have wrote a query in php for a mysql database. Now the query works and outputs fine but it outputs to a new page. How to I get it to output to the html page with the form on it?
Thanks
Ben
<?php
// remove these style tags to remove the large font size
echo ‘<style type=”text/css”> table {font-size: x-large} </style>’;// Accept a parameter called “BUILDING” from a form.
$BUILDING = $_POST[‘BUILDING’];
echo ‘Parameter value was: ‘.$BUILDING.’
‘;
echo ‘<br/><br/>’;// Connect to the Oracle database
require(‘x_connect.php’);// Specify SQL STATEMENT CONTAINING A BIND VARIABLE
$query1 = ‘SELECT “FirstName”, “LastName”, “WorkPhone”
From “tbl_Staff”
INNER JOIN “tbl_Space”
ON “tbl_Staff”.”OfficeID” = “tbl_Space”.”RoomNo”
INNER JOIN “tbl_Buildings”
ON “tbl_Space”.”BuildingID” = “tbl_Buildings”.”BuildingID”
WHERE “tbl_Buildings”.”Name” = :BUILDING’;// Parse the query containing a bind variable.
$stmt = oci_parse($conn, $query1);// Bind the value into the parsed statement.
oci_bind_by_name($stmt, ‘:BUILDING’, $BUILDING);// Execute the completed statement.
oci_execute($stmt);// Search for buidling name and building items then output building items
echo “<table border=’1′ cellpadding=’5′>\n”;
while ($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo “<tr>\n”;
foreach ($row as $item) {
echo ” <td>” . ($item !== null ? htmlentities($item, ENT_QUOTES) : ” “) . “</td>\n”;
}
echo “</tr>\n”;
}
echo “</table>\n”;// Release the statement variable and close the connection
oci_free_statement($stmt);
oci_close($conn);// Show the SQL
echo ‘SQL statement executed was: </br>’.$query1.’
‘;
?>April 29, 2014 at 3:06 pm #168888Alen
ParticipantWrap your code with the
` (the key above the tab on your keyboard). Or create a Gist on github.com. So we can see the code better.
April 29, 2014 at 4:06 pm #168891__
ParticipantHow to I get it to output to the html page with the form on it?
PHP cannot do that. PHP is long gone by the time your user fills out the form.
You can use ajax to call your PHP script, and bring the output back to your current page. Various javascript libraries (like jQuery) have methods that make working with ajax easier.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.