Thanks to a forum member I have moved a little forward but now I am stumped on how to convert a passed value to a variable so it can be used to search a MySQL database. When I use the passed variable as the value I receive the following error:
"SELECT * FROM courses WHERE org_id =
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"
If I "hard code" the actual value passed I am able to select the correct record. Here is php code:
<?php
// connect include
require ("connect.php");
$once = print_r($_GET, true);
echo "<p>" . $once. "<p>";
$twice= var_export($_GET, true);
echo "<p>" . $twice. "<p>";
print_r($_GET);
if($_GET["varID"] === "") echo "varID is an empty string\n";
if($_GET["varID"] === false) echo "varID is false\n";
if($_GET["varID"] === null) echo "varID is null\n";
if(isset($_GET["varID"])) echo "varID is set\n";
if(!empty($_GET["varID"])) echo "varID is not empty";
/* $query = "SELECT * FROM organizations WHERE org_id = {$_GET['varID']}"; */
$query = "SELECT * FROM organizations WHERE org_id = 9661";
/* Temporary ECHO of the $sql string */
echo "<p>" . $query . "</p>";
$result = mysql_query($query)or die(mysql_error());
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
$result = mysql_query($query)or die(mysql_error());
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
$num = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result))
{
echo("<tr>\n<td>" . $row["cityname"] . "</td>");
echo("<td>" . $row["statename"] . "</td>");
echo("<td>" . $row["orgname"] . "</td>");
echo "<td>" .$row['org_id']."</td>";
}
/* Closes Connection to MySQL server */
mysql_close ($connect);
?>
The output of this code is as follows:
Array ( [varID_] => 9661 )
array ( 'varID_' => '9661', )
Array ( [varID_] => 9661 ) varID is null
SELECT * FROM organizations WHERE org_id = 9661
BILLINGSMONTANAAssociation of State Grazing Districts9661
I have tried reading up on the php functions for arrays but can't find what I need. Any help would be appreciated.