Good day fellow programmers, please i need your help. I have a hidden field that holds both the destination and the id of the destination, i need help on how to send both the id and and value of the destination to the database

The code for the form is


<table width="489" height="141" align="center" cellpadding="3" cellspacing="3" bordercolor="#B1C3D9" class="textf1">
            <th height="37" colspan="2" bgcolor="#FFFFFF" scope="col"><table width="466" class="textff">
                <tr bordercolor="#75A8C7">
                  <td width="458" bgcolor="#990100" scope="col"><div align="center"><span class="style94">ADD DESTINATIONS </span>FROM</div></td>
            <td width="258" height="5" scope="col"><div align="left"><span class="style103">Select Destination From: </span></div></td>
            <td width="206" scope="col"><label>
                <div align="left">
                  <select name="destinationfrom" id="destinationfrom">
                        $query = "SELECT * FROM destinationfrom ORDER BY destination ASC";
						$result = mysql_query($query) or die("Error ".mysql_errno().": ".mysql_error()."<br><br>$query");
						$index = 0;
						while($row = mysql_fetch_assoc($result)) {
							$var =$row['hiddendestination']; 
                <option value="<?php echo $row['id'] ?>" selected="selected"><?php echo $row['destination'] ?></option>
				 <?php }   
                  <input name="hiddenid" type="hidden" id="hiddenid" value="<?php echo $row['hiddenid'] ?>" />
                  <input name="hiddendestinationfrom" type="hidden" id="hiddendestinationfrom" value="<?php echo $row['hiddendestination'] ?>" />
            <td height="7" scope="col"><div align="left"><span class="style103">Enter Destination To: </span></div></td>
            <td scope="col"><div align="left">
                <input name="destination" type="text" class="textf1" id="destination"/>
            <th height="7" scope="col">&nbsp;</th>
            <td scope="col"><input name="Submit" type="submit" class="style92" value="Submit" /></td>


The form action is done by transactform and the action is


include "function.php";
$error= array();
$destinationfrom=isset($_POST['destinationfrom'])? trim($_POST['destinationfrom']):'';
$destination=isset($_POST['destination'])? trim($_POST['destination']):'';
$var= "select * from destinationfrom where id=$destinationfrom";

$error[]=urlencode("Field Required!");
$query= "insert into destinationto(destinationid,destinationfrom,destination) values('$destinationfrom','$var','$destination')";
else {
header('Location:adddestinationto.php?action=adddestinationto'.' &error='.join($error, urlencode('<br>')));
 $msg="<strong> Destination-to was added successfully... </strong>";
 $result= mysql_query($query);
 header('Location:adddestinationto.php?action=adddestinationto'.' & error='.$msg);




Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

7 Years
Discussion Span
Last Post by EvolutionFallen

If you were my fellow programmer you would use code tags for better readability. And you would boil down your code to the problem without having us to spell our way through lots of irrelevant HTML. Be a good fellow and try again.

Votes + Comments
Was thinking the same thing
well put

Building on smantscheff's response, you'd also have an informative subject line instead of a vague plea for assistance, so I would know if I can help before I click the link.


Without wanting to post a 'me too' post, I'll just say that forms usually need to be sent to another page to deal with the submitted fields. Reloading a page with a form and form handling script can cause resubmission - which is bad. The form tag has a default method attribute of 'get'. You don't seem to have used form tags at all. When you do, use the method="post" so you can use $_POST array in the form handling script.

Anyway, to reiterate, use code tags, cut out the needless code and use a meaningful title.


Don't lie ardav, you wanted to write a "me too" post ;)
On a serious note, good points. I'll have to look into that about submitting forms to the same page, I never heard there could be a problem with that.

Some small details:
1. On line 21 of the first code segment you declare a variable $var, but never use it again in that section of code.

2. Note that on lines 31 & 33 you reference the $row array. I'm not sure about PHP's scope rules (don't have time to look them up this sec), but you're either a) accessing a variable that no longer exists, or b) creating 2 hidden fields whose values are based on the last row you retrieved from the database. Unless I'm missing something, I don't think that's the goal you're trying to achieve. You probably need to use JavaScript to populate these fields with different "hiddenid" and "hiddendestination" values based on what users select from the drop-down menu.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.