Jump to content

insert 2 values into 1 field


jacko_162

Recommended Posts

is it possible to have a form with 2x inputs (a text field and a drop down)

 

then the value from BOTH fields be inputted into 1x field in the database;

 

for example user types: "150" into text area, and selects "PPM" from the drop down, and this Updates database with: "150 PPM"

Link to comment
Share on other sites

Well, abitter didnt really explain it so for the complete beginner some information regarding POST Values and Form Meta Data.

 

In PHP forms are created using HTML. The form can contain numerous data values in the form of either simple variables: key=>value or arrays: array ( key1=>value, key2=>value).

 

Wether you choose to use arrays (name="key[1]") or simple variables (name="key1"), depends on how that data is used in the processor script.

 

-------

 

When a form is submitted, the data usually ends up in the POST Global Variable of PHP. For example,

 

$key1 = $_POST['key1']; // This would make $key1 contain the data submitted by the form data named key1.

$key2 = $_POST['key2']; // This is the same but for the data named key2.

 

Now with these two variables you can manipulate them however you wish.

For instance:

 

$result = $key1 + $key2; // Use math

$string = $key1 . " is not the same as " . $key2; // Use concatenation

 

Then you can echo the result via one of php's output functions:

echo($string);

 

Good Luck.

Try to learn some simple tutorials for PHP:

http://www.lmgtfy.com/?q=PHP Beginner Tutorial

 

-CB-

Link to comment
Share on other sites

thank you for the detailed information, i assume i have to use an array to collect the data then an INSERT query to insert array[1] and array[2] into the same field.

 

i have a form already that submits the information to the database;

 

<?php
session_start();
include('Includes/auth.php');
require_once('header.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf8"/>
<title>Index</title>
</head>

<body class="cloudy">
<table width="60%" border="0" align="center" cellpadding="2" cellspacing="2">
      <tr>
        <td width="40%" valign="top">
        <div class="content-box column-left">
	<div class="content-box-header">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="80%"><h3>Add New Test Results</h3></td>
    <td width="20%"><strong>Date: 
        <?php // Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date("F j, Y"); ?>
        <br />
Time: 
<?
//get current timestamp and subtract one <strong class="highlight">hour</strong>
$dat = time() - 3600;
//output time
echo date("g:ia", $dat);
?>
    </strong></td>
  </tr>
</table>

				  </div>
			<div class="content-box-content">
			  <div>
                  <?php
  {
    $result2=mysql_query("SELECT * FROM members WHERE member_id=$_SESSION[sESS_MEMBER_ID]");
    $row2 = mysql_fetch_array($result2);
    $arr = array();
    $arr = explode(';',$row2['settings']);
    $member_id = $row2['member_id'];
    ?>

<?php 
if (isset($_POST['submit'])) {

$insert = "INSERT INTO tests SET 
member_id='$_SESSION[sESS_MEMBER_ID]', 
test1='$test1', 
test2='$test2',
test3='$test3',
test4='$test4',
test5='$test5',
test6='$test6',
test7='$test7',
test8='$test8',
test9='$test9',
test10='$test10',
test11='$test11',
test12='$test12',
test13='$test13',
test14='$test14',
month='$month', 
day='$day', 
date='$date', 
time='$time'"; 

if (@mysql_query($insert))
{
?>
                          <script type="text/javascript">
document.location.replace('tests.php');
                          </script>
                          <?php
}
else {
echo('Error in you submission:' . mysql_error() . "<br />" . $sql);
}} 

?>
				  <table width="100%" border="0" cellspacing="0" cellpadding="2">
                              <tr>
                                <td>
          <form action="<?=$_SERVER['PHP_SELF']?>" method="post">

                                <input type="hidden" name="date" value="<?php echo date("F j, Y"); ?>" />
                                <input type="hidden" name="month" value="<?php echo date("F"); ?>" />
                                <input type="hidden" name="day" value="<?php echo date("j"); ?>" />
                                <input type="hidden" name="time" value="<?
//get current timestamp and subtract one <strong class="highlight">hour</strong>
$dat = time() - 3600;
//output time
echo date("g:ia", $dat);?>" />  

							<br />
                                <table width="100%" border="0" align="center" cellpadding="4" cellspacing="0">
                                  <tr>
                                    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
<?php
echo (in_array("test1",$arr) ? "<tr><td><div align='right'><strong><em>Salinity:</em></strong></div></td><td><input class='InputBox' name='test1' value='' /></td></tr>" : '');
echo (in_array("test2",$arr) ? "<tr><td><div align='right'><strong><em>PH:</em></strong></div></td><td><input  class='InputBox' type='text' name='test2' value='' /></td></tr>" : '');
echo (in_array("test3",$arr) ? "<tr><td><div align='right'><strong><em>Ammonia:</em></strong></div></td><td><input  class='InputBox' type='text' name='test3' value='' /></td></tr>" : '');
echo (in_array("test4",$arr) ? "<tr><td><div align='right'><strong><em>Nitrite:</em></strong></div></td><td><input  class='InputBox' type='text' name='test4' value='' /></td>" : '');
echo (in_array("test5",$arr) ? "<tr><td><div align='right'><strong><em>Nitrate:</em></strong></div></td><td><input  class='InputBox' type='text' name='test5' value='' /></td></tr>" : '');
echo (in_array("test6",$arr) ? "<tr><td><div align='right'><strong><em>Calcium:</em></strong></div></td><td><input  class='InputBox' type='text' name='test6' value='' /></td></tr>" : '');
echo (in_array("test7",$arr) ? "<tr><td><div align='right'><strong><em>Magnesium:</em></strong></div></td><td><input  class='InputBox' type='text' name='test7' value='' /></td></tr>" : '');
?>  
                                    
                                    </table></td>
                                    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
<?php
echo (in_array("test8",$arr) ? "<tr><td><div align='right'><strong><em>Alkalinity:</em></strong></div></td><td><input  class='InputBox' type='text' name='test8' value='' /></td></tr>" : '');
echo (in_array("test9",$arr) ? "<tr><td><div align='right'><strong><em>Phosphate:</em></strong></div></td><td><input  class='InputBox' type='text' name='test9' value='' /></td></tr>" : '');
echo (in_array("test10",$arr) ? "<tr><td><div align='right'><strong><em>potassium:</em></strong></div></td><td><input  class='InputBox' type='text' name='test10' value='' /></td></tr>" : '');
echo (in_array("test11",$arr) ? "<tr><td><div align='right'><strong><em>Iodine:</em></strong></div></td><td><input  class='InputBox' type='text' name='test11' value='' /></td></tr>" : '');
echo (in_array("test12",$arr) ? "<tr><td><div align='right'><strong><em>Strontium:</em></strong></div></td><td><input  class='InputBox' type='text' name='test12' value='' /></td></tr>" : '');
echo (in_array("test13",$arr) ? "<tr><td><div align='right'><strong><em>Silica:</em></strong></div></td><td><input  class='InputBox' type='text' name='test13' value='' /></td></tr>" : '');
echo (in_array("test14",$arr) ? "<tr><td><div align='right'><strong><em>Temperature:</em></strong></div></td><td><input  class='InputBox' type='text' name='test14' value='' /></td></tr>" : '');
?>
</table>
</td>
                                  </tr>
                                </table>                                   
							 <div align="right"><br />
                                   <table border="0" cellspacing="0" cellpadding="8">
                                     <tr>
                                       <td><input class="Button" type="submit" name="submit" value="Submit" /></td>
                                       <td><input class="Button-alt" type="reset" name="reset" value="Reset" /></td>
                                     </tr>
                                   </table>
                               </div>
                               </form><?php
}
?>
				</td>
                              </tr>
                            </table>
			  </div> 
			  <!-- End #tab3 -->        

			</div> <!-- End .content-box-content -->
        </td>
      </tr>
</table>
<?php
require_once('footer.php');
?>
</body>
</html>

 

this is a simple form that adds upto 14 results, the "if" commands before each textfield check if the users has set each test in the members settings array in the members table.

 

do you have any code available where i can see what i need to do to manipulate the second drop down after each result? the data for the dropp downs is simple i need the following which can be done manually in the code itself;

 

ppm

sg

degrees

farenheit

 

im a semi-beginer in php but i seem to work better if i can see some example coding, this way i can see what its calling for and what need to be edited and changed to suit my needs.

 

many thanks :)

Link to comment
Share on other sites

Ok from what i got from your last reply, is that you want one drop-down box, to control what is shown in a second drop-down box?

 

Well if you want this without having to go to another page, then your going to have to learn AJAX as well.

 

I would reccomend getting more familiar with php before attempting a PHP/Java Real-Time Interface.

 

For instance, i would have the page check the $_POST array for the first drop-down selection, then print the second if so.

 

-CB-

 

Note:

Its good practice when learning php to search for 'Tutorials" on the thing your trying to do. for example;

PHP Tutorial Arrays

PHP Tutorial Form Arrays

PHP Tutorial Advanced Forms

PHP Tutorial Security <- Most Important.

 

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.