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.

Member Avatar for Zagga

Hi Capt Spaghetti (love the name btw),

Are you sure the key 'varID' is being passed correctly in the URL? It looks like 'varID_' is the key that is being displayed in your echo statements ($once and $twice).


Zagga

I down select using a MySQL statement and the user picks their choice based on the org_id. I am passing it as follows:

echo "<a href = 'graborginfo9.php?varID =".$row['org_id']."'>".$row['org_id']."</td></a>";

Should I be doing something differently?

Capt Spaghetti

Member Avatar for Zagga

Hi again,

you need to remove the space where you declare varID.

Change

echo "<a href = 'graborginfo9.php?varID =".$row['org_id']."'>".$row['org_id']."</td></a>";

to

echo "<a href = 'graborginfo9.php?varID=".$row['org_id']."'>".$row['org_id']."</td></a>";

and try that.


Zagga

Zagga,

My father use to kid me by asking me if I majored in space(i.e. taking up space). Now I see how important space is. That did the trick. Thank you very much for the assistance.

Thanks,
Capt Spaghetti

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.