Jump to content

option value as part of form block


buchberg
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hello, and thank you in advance for looking at this.  I am trying to write a piece of code for an input value using an option dropdown box.  In my mind I am obviously in need of some assistance.    

 

This is my set up:

 

Apache 2.21 

PHP:  5.3.5

MySql:  5.6 (I think)

 

The following code has been working well for the mysql fetch array and display, but is outside my formblock.  The problem that I am having is I would like it to be placed inside my form block.   

 

Option Value code

// setting up fetch row for OWNER 19 //
$result_engineer= mysql_query("SELECT organization, l_name, f_name FROM $table_name WHERE type='municipality'") or die (mysql_error());
 
echo '<select name="owner[]">'; // Open your drop down box
 
while ($row_engineer = mysql_fetch_array($result_engineer)) {
echo '<option value>'.$row_engineer['organization'].', '.$row_engineer['l_name'].', '.$row_engineer['f_name'].'</option>';
}
 
echo '</select>';// Close your drop down box

 

My form block code starts as follows:

 

$form_block="
<FORM METHOD=\"POST\"ACTION=\"do_add_design_XXXXXX.php\">
<P><b>Project Status:</b>
<br>
<FIELDSET> 
<br>
<P><small><small>Project Name:</small></small>
<INPUT type=\"text\" NAME=\"project_name\" SIZE=100></P>
 
(it continues ad nauseum)
 

There seems to be an error once I place the Option value code inside the form block code.  My suspicion is I am not using a proper <TAG>.  I am new, but have been trying.  Security is not much of an issue as this is on a local machine only.  

 

Any assistance is greatly appreciated.  Thank you and have a nice day.

 

Best regards

Link to comment
Share on other sites

Rather echo out the the <select>/</option> tags assign them to a variable

$engineerList = '<select name="owner[]">'; // Open your drop down box
 
while ($row_engineer = mysql_fetch_array($result_engineer)) {
   $engineerList .= '<option value>'.$row_engineer['organization'].', '.$row_engineer['l_name'].', '.$row_engineer['f_name'].'</option>';
}
 
$engineerList .= '</select>';// Close your drop down box

Now place $engineerList in the $form_block string where you want the select menu to appear. Example

$form_block="
<FORM METHOD=\"POST\"ACTION=\"do_add_design_XXXXXX.php\">
...
<P>Engineer: $engineerList</P> <!-- add engineer list -->
...
</FORM>";
Edited by Ch0cu3r
Link to comment
Share on other sites

  • 2 weeks later...

Thank you.  It worked awesome.  

 

My value is showing up as an Array on my confirmation html page with command

 

echo $_POST[engineer];

 

However, it shows nothing in my phpmyadmin.  I would expect Array to show up.  

 

In using the suggested code ($engineerList = '<select name="owner[]">'; // Open your drop down box), I changed "ower[]" to "engineer[]".

 

.

 

As I am seeing in my confirmation page the value Array.  I did use the following code to grab the values:

 

foreach ($_POST[engineer] as $key=>$v_eng){
$v_eng=implode(',',$_POST['engineer']);
}
 
It has worked on other variables except this one  Is there a difference in the way the list is generated that doesn't allow it to POST in the same way?
 
Thank you in advance, and have a good day.
Link to comment
Share on other sites

Your help is very much appreciated, but this is frustrating me to no end.  The mysql fetch side of $engineerList works great.  However, I am still having issues with getting a $_POST[engineer] value recognized/saved in the form.  

 

I implemented the following code as we discussed, and removed the [] in $engineerList ='<select name="engineer">'.

 
// setting up fetch row for OWNER 19 //
$result_engineer= mysql_query("SELECT organization, l_name, f_name FROM $table_name WHERE type='engineer'") or die (mysql_error());
 
$engineerList = '<select name="engineer"> '; // Open your drop down box
while ($row_engineer = mysql_fetch_array ($result_engineer)) {
$engineerList .= '<option value>'.$row_engineer['organization'].', '.$row_engineer['l_name'].', '.$row_engineer['f_name'].'</option>';
}
$engineerList .= '</select> ';// Close your drop down box
 
This displays all values in the MySQL table associated with engineers.  But whatever engineer I select from this list, it isn't saved and doesn't have a value to INSERT into my table in MySQL.
 
To verify, I have tried  echo $_POST[engineer]; and there is no value.
 
Am I looking for the wrong variable to be stored, does the code not recognize the $engineerList as an input?
 
 
Please let me know any suggestions that you have.  Thank you and I know this is frustrating.  I really appreciate your input, and have a good day.
Link to comment
Share on other sites


The $engineerList is within the $form_block, but it is not recognized by the server side code.  On the ser.ver side, I have error checks if the value of $_POST$engineerList = "".

 

Please let me know where I am going wrong.  Thank you and I look forward to your reply.

 

<HTML>

<HEAD>

<TITLE>Project Bid Interface</TITLE>

</HEAD>

<BODY>

<br>

<div style="text-align: right;">

<div style="text-align: left;"><img

style=" width: 250px; height: 150px;" alt="This is family pic" src="family_pic.jpg"><big><big><big><big><span

style="font-weight:">    <small>This is my Work!!!<br>

<br>

 

<?

$db_name="XXXXX";

$table_name="yyyyyy";

$connection=mysql_connect("localhost", "root", "password") or die (mysql_error());

mysql_select_db("$db_name") or die (mysql_error());

 


// setting up fetch row for OWNER 19 //

$result_engineer= mysql_query("SELECT organization, l_name, f_name FROM $table_name WHERE type='engineer'") or die (mysql_error());

 

$engineerList = '<select name="engineer"> '; // Open your drop down box

while ($row_engineer = mysql_fetch_array ($result_engineer)) {

$engineerList .= '<option value>'.$row_engineer['organization'].', '.$row_engineer['l_name'].', '.$row_engineer['f_name'].'</option>';

}

$engineerList .= '</select>';// Close your drop down box

 

// line 28

 

$form_block="

<FORM METHOD=\"POST\"ACTION=\"do_add_design_XXXXX.php\">

<P><b>Project Status:</b>

<br>

<FIELDSET> 

<br>

<P><small><small>Project Name:</small></small>

<INPUT type=\"text\" NAME=\"project_name\" SIZE=100></P>

<P><small><small>Date (yyyy/mm/dd):</small></small>

<input type=\"text\" name=\"date\" size=\"15\" maxlength=\"10\">  

</P>

 

</fieldset>

<P><b>Contact Information:</b>

<fieldset>

<P><small><small>Rep Territory:</small></small>

<br>

<INPUT TYPE=\"radio\" NAME=\"rep\" Value=\"XX\"><small><small>Michael Buchberg</small></small><br>

<INPUT TYPE=\"radio\" NAME=\"rep\" Value=\"XY\"><small><small>Mike Krebs</small></small><br>

<INPUT TYPE=\"radio\" NAME=\"rep\" Value=\"XZ\"><small><small>Tom McNamara</small></small><br>

 

<P><small><small>Owner:</small></small><br>

<INPUT TYPE=\"radio\" NAME=\"owner\" Value=\"XX\"><small><small>Mike Krebs</small></small><br>

<INPUT TYPE=\"radio\" NAME=\"owner\" Value=\"YY\"><small><small>Tom McNamara</small></small><br>

 

<P><small><small>Engineer:</small></small>

<p>$engineerList</p> <!-- add engineer list -->

</FIELDSET>

<br>

 

<br>

<FIELDSET> 

<P><small><small>Equipment:</small></small><br>

<INPUT TYPE=\"checkbox\" NAME=\"equipment[]\" Value=\"none \"><small><small>No Equipment</small></small>

<INPUT TYPE=\"checkbox\" NAME=\"equipment[]\" Value=\"odor\"><small><small>Odor Control</small></small>

<INPUT TYPE=\"checkbox\" NAME=\"equipment[]\" Value=\"pumps\"><small><small>Pumps</small></small>

<INPUT TYPE=\"checkbox\" NAME=\"equipment[]\" Value=\"service\"><small><small>Service</small></small>

 

<br>

<small><small>Odor Control</small></small> 

<input type=\"text\" name=\"odor\" <input name=\"v_odor\" <input=\"\"

onkeyup=\"this.value=this.value.replace(/[^\d]/,'')\"><br>

<small><small>Pumps</small></small>

<input name=\"v_pumps\" <input=\"\"

onkeyup=\"this.value=this.value.replace(/[^\d]/,'')\"

type=\"text\"><br>

<small><small>Service</small></small>

<input name=\"v_service\" <input=\"\"

onkeyup=\"this.value=this.value.replace(/[^\d]/,'')\"

type=\"text\"><br><br>

</fieldset>

 

<P><b>Comments & Follow Up:</b>

<br>

 

<textarea cols=\"2000\" name=\"comments\" value=\"comments\" rows=\"20\"></textarea>

<big><big><span style=\"font-weight: bold;\" ><=\"\" span=\"\"></span>

 

<br><br>

<INPUT type=\"hidden\" NAME=\"op\" value=\"ds\">

<INPUT type=\"submit\" NAME=\"input_project\" value=\"Input!\">

 

</FORM>";

 

if ($_POST[op]!="ds") {

// 18 they need to see the form

echo "$form_block";

} else if ($_POST[op] == "ds") {

}

 

?>

</body>

</div>

</div>

</body>

</html>

 

server side (portion relating to inserting into table)

 


$db_name="XXXXX";

$table_name="yyyyyy";

$connection=mysql_connect("localhost", "root", "password") or die (mysql_error());

$db=mysql_select_db($db_name, $connection) or die (mysql_error());

 

foreach ($_POST[bid_status] as $key=>$v_bs){

$v_bs=implode(',',$_POST['bid_status']);

}

 

foreach ($_POST[equipment] as $key=>$v_e){

$v_e=implode(',',$_POST['equipment']);

}

echo "about to insert into database";  

//line 62

$sql="INSERT INTO $table_name 

(project_name, date, bid_status, engineer, owner, equipment, odor_value, pumps_value, service_value, project_value, comments) VALUES

('$_POST[project_name]','$_POST[date]','$v_bs','$_POST[engineer]', '$_POST[owner]', '$v_e','$v_odor', '$v_pumps', '$v_service', '$project_value', '$_POST[comments]')";

$result=mysql_query($sql, $connection) or die (mysql_error());

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.