I have a problem with this script. I would like to have the user input used in the query.
I have been trying for days and numerous methods with no success.
<?php
function new_module_menu() {
$items = array();
$items['new_module/form'] = array(
'title' => t('My form'),
'page callback' => 'new_module_form',
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
);
return $items;
}
function new_module_form() {
return drupal_get_form('new_module_my_form');
}
function new_module_my_form($form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
);
// Adds a simple submit button that refreshes the form and clears its contents -- this is the default behavior for forms.
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
$q=$form['name'][0];
// Modifies this function so that it will respond appropriately based on
// which page was submitted. If the first page is being submitted,
// values in the 'storage' array are saved and the form gets
// automatically reloaded.
// If page 2 was submitted, we display a message and redirect the
// user to another page.
function new_module_my_form_submit($form, &$form_state) {
// Handle page 1 submissions
if ($form_state['clicked_button']['#id'] == 'edit-next') {
$form_state['storage']['page_two'] = TRUE; // We set this to determine
// which elements to display
// when the page reloads.
// Values below in the $form_state['storage'] array are saved
// to carry forward to subsequent pages in the form.
$form_state['storage']['page_one_values'] = $form_state['values'];
}
// Handle page 2 submissions
else {
// Connects to your Database
mysql_connect("localhost","drupaluser","sep221984")or die(mysql_error());
mysql_select_db("drupal") or die(mysql_error());
//$query = "SELECT `languagearts`.`Description`\n"
// . "FROM languagearts\n"
// . "WHERE ((`languagearts`.`Description` LIKE \"%$ke%\") AND (`languagearts`.`Grade` =
//\"Grade 6\"))\n AND (`languagearts`.`Label` like \"p%\")\n"
// . " ";
$query = "select * from languagearts where Description like \"%$q%\" order by Description";
//$query = "select * from languagearts where Description like '".$q."' order by Description";
$result = db_query($query);
while ($row = db_fetch_object($result)) {
$Description="{$row->Description}";
$url_pr=str_replace("http://","",$url);
echo "<strong>".$org."</strong><br>\n";
if($Description!=""){ echo $Description."<br>\n"; }
echo "<br>\n";
}
while($a_list = db_fetch_object($result)){
foreach ($a_list as $array => $a){
}
print("<tr><td>".$a."</td></tr>\n");
}
/*
Normally, some code would go here to alter the database with the data
collected from the form. Sets a message with drupal_set_message()
to validate working code.
*/
drupal_set_message('Your form has been submitted');
unset ($form_state['storage']); // This value must be unset for
// redirection! This is because
// $form_state['rebuild'] gets set to TRUE
// when 'storage' is set. See code sample
// #9 for more on this.
//$form_state['redirect'] = 'node/5'; // Redirects the user.
}
}