Jump to content

passing arrays using $_POST


offsprg01

Recommended Posts

ok so here the deal. i have to write a script that searches a giant database of school and returns the contact info for all schools matching the search term.

 

no big deal it's cake to code something that simple...

 

but wait there more! the search must be executed by a joomla page...

 

we crap. joomla doesn't allow me to run php scripts...

 

so i found a little plugin called jumi that lets me do just that.

 

and it works great minus all the errors joomla spits out because the mysql_connect statement and the mysql_query statment are connecting to a different database than the one joomla is installed onand thus joomla thinks the tables i am searching don't exist so joomla outputs this 4 page long error code in a bright red box a the top of the page.

 

so i tried turning off joomls error reporting.. no bueno. so i figured no problemo i'll just have the script call out to a .php file hosted else where on the server and pass the search terms to that file via $_POST. then have said file execute a quick search of the database and return the results back to the original joomla page from whence the search commenced via a nice tidy $_POST array.

 

one problem how in hades do you pass around php arrays via $_POST?

 

 

 

Link to comment
Share on other sites

ok so here's how i figure i'll handle the first step (getting the search terms sent to the file where we are dong the searching)

 <form name="search" method="post" action="school_search.php">
 	Seach for: <input type="text" name="find" /> in 
	<Select NAME="field">
			<Option VALUE="SchoolName">School Name</option>
		<Option VALUE="SchoolDistrict">School District</option>
		<Option VALUE="State">State</option>
	</Select>
	<input type="hidden" name="searching" value="yes" />
	<input type="submit" name="search" value="Search" />
</form>

 

 

that was cake. so here's how i think i should handle the searching of the database and returning the results back to joomla.

 

 


<?php
$searchdbhost = 'localhost';
$searchdbuser = 'blarg';
$searchdbpass = 'honk';
$searchdbname = 'listofschools';
$searchtable = 'SchoolList';
//Check to see if user actually submitted something
//If they did not enter a search term we give them an error 
if ($_POST['find'] == ""){ 
	echo "<p>You forgot to enter a search term</p>"; 
	exit; 
}
// Otherwise we connect to our Database 
mysql_connect($searchdbhost, $searchdbuser, $searchdbpass) or die(mysql_error());
mysql_select_db($searchdbname) or die(mysql_error()); 
// We preform a bit of filtering 
$find = $_POST['find'];			
$find = strtoupper($find); 
$find = strip_tags($find);
$find = trim ($find);
$field = $_POST['field'];
//Now we search for the school in question 
$query = "SELECT * FROM $table WHERE upper($field) LIKE '%$find%' LIMIT 50";
$data = mysql_query($query) or die(mysql_error()); 
//And we return the results to the referring joomla page
?>
<form onload="submitform()" action="<?php echo getenv("HTTP_REFERER"); ?>">
<input type="hidden" name="searching" value="yes" />
<?php 
	foreach ($results as $key => $value){
			echo '<input type="hidden" name="results[]" value="'.htmlspecialchars($value).'">';
	}
?>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.