Pull value from selected option and put it in the action

Discussion in 'PHP' started by software4, Oct 12, 2009.

  1. #1
    I have this form and when the user selectes the option, i want to be able to put the value in the action of the post. If i add something like id=<?php $row['id'];?> "> the id comes up blank. How can i adjust this?


     <form name="form1" method="POST" action="">
                          <p align="center">
                            <input type="hidden" name="join_event_id" id="join_event_id" value="<?php echo $event ?>">
                            <br>
                          </p>
    			      <p align="center"> <span class="text">Choose Candidate: &nbsp;</span><span class="style6">&nbsp;  
    			        <select name="candidate" class="text" id="position">
    			          <?php
    					  $sql =  "SELECT
    						`id`, `name`
    					FROM
    						`bio` 
    					WHERE
    						`event` = '$event'";
    					$result2 = mysql_query($sql);
    					if(mysql_affected_rows() > 0) {
    						while ($row = mysql_fetch_assoc($result2)) {  
    							echo '<option value="' . $row['id'] . '" '; if($id == $row['id']) echo 'selected="selected"'; echo '>' . $row['name'] . '</option>';
    						}
    					}
     
    ?>
      </select>
    			        </span>
    			        &nbsp; 
    			        <input name="Submit" type="submit" onClick="MM_validateForm('can_name','','R');return document.MM_returnValue" value="Submit">
    PHP:
     
    software4, Oct 12, 2009 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Use $id not the $row['id']. Like:

    <form name="form1" method="POST" action="id=<?php echo $id;?>">
     
    ThePHPMaster, Oct 12, 2009 IP
  3. software4

    software4 Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So i tried just using Id, but it returns the Id that was used at the top of the page, not the changed Id from the option. Basically what i am trying to accomplish is when you choose the option from the menu and hit submit, all of their data comes to the screen and when you choose another option their data comes to the screen. Here is my whole file. Line 166 is where the form starts.
    Thanks in advanced...

    <?php 
    require_once('Connections/config.php');
    require_once('includes/system_values.php');
    require_once('includes/admin_login.php'); 
    
    $id = (isset($_GET['join_id'])) ? $_GET['join_id'] : $_POST['candidate'];
    $event = (isset($_GET['join_event_id'])) ? $_GET['join_event_id'] : $_POST['join_event_id'];
    
    $id = (int) strip_tags($id);
    $event = (int) strip_tags($event);
    
    $id = (isset($id)) ? $id : 0;
    $event = (isset($event)) ? $event : 0;
    $query = "SELECT
    						`bio`.*, `join2`.`join_candidate` as `name` 
    					FROM
    						`bio` 
    					LEFT JOIN 
    						`join2` 
    					ON
    						(`join2`.`join_id` = `bio`.`id`)
    					WHERE
    						`bio`.`id`='$id'";
     
    if(isset($_POST['upload'])) {
    $message = mysql_real_escape_string(strip_tags($_POST['message']));
    $hobby = mysql_real_escape_string(strip_tags($_POST['hobby']));		
    		if($_FILES["file"]["size"] > $imgSize) { $content .= "File is to large, submit a smaller image!"; }
    		elseif(empty($_FILES["file"]["name"])) { $content .= "No File Uploaded!"; }
    						else
    							{
    								if ((($_FILES["file"]["type"] == "image/gif")
    									|| ($_FILES["file"]["type"] == "image/jpeg")
    									|| ($_FILES["file"]["type"] == "image/pjpeg")
    									|| ($_FILES["file"]["type"] == "image/png")
    									|| ($_FILES["file"]["type"] == "image/jpg")
    									|| ($_FILES["file"]["type"] == "image/x-png"))
    									&& ($_FILES["file"]["size"] < $imgSize))
    										{
    										$image = str_replace(' ','_',$_FILES["file"]["name"]);
    										$image = str_replace("'",'',$image);
    											if ($_FILES["file"]["error"] > 0)
    												{
    													$content .=  "Return Code: " . $_FILES["file"]["error"] . "<br />";
    												}
    											else
    												{
    													
    													if (file_exists("images/" . $_FILES["file"]["name"]))
    													    {
    															    $content .=  $_FILES["file"]["name"] . " already exists. If this is not the correct image, <br> change your file name and upload again.";
    													    }
    													else
    														{
    																$uploadedfile = $_FILES["file"]["tmp_name"];
    																$size = getimagesize($uploadedfile);
    																$type = $size['mime'];
    																$width = $size[0];
    																$height = $size[1];
    																       if($height > $setHeight || $width > $setWidth) //setWidth, setHeight is pulled from includes/system_values.php
    																			{ 
    																				$newwidth=$setWidth;
    																				$newheight=($height/$width)*$setWidth;
    																				$tmp=imagecreatetruecolor($newwidth,$newheight);
    																				$filename = "images/$image";
    																				
    																					if($size[2] == IMAGETYPE_GIF)
    																						{
    																						    $src = imagecreatefromgif($uploadedfile);
    																							imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    																							imagegif($tmp,$filename,100);
    																						}
    																					elseif($size[2] == IMAGETYPE_JPEG)
    																						{
    																						    $src = imagecreatefromjpeg($uploadedfile);
    																							imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    																							imagejpeg($tmp,$filename,100);
    																						}
    																					elseif($size[2] == IMAGETYPE_PNG) 
    																						{
    																							$src = imagecreatefrompng($uploadedfile);
    																							imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    																							imagepng($tmp,$filename,9);
    																						}
    																				$content .=  "Image has been resized to $newwidth X $newheight<br/>";
    																			imagedestroy($src);
    																			imagedestroy($tmp);
    																			}
    																		else
    																			{      
    																			     move_uploaded_file($uploadedfile, "images/$image");																				  
    																			}
    												
    													}
    												}
    											
    										}
    									else { $content .=  "Invalid file"; }
    							}
    		//$image = mysql_real_escape_string($image);
    		$imageUpload = (isset($image)) ?  ",`image`=	'$image' " : NULL;
    		$update = "UPDATE `bio` SET `message` = '$message', `hobby` = '$hobby' $imageUpload WHERE `id` = '$id'";
    		//echo $update;
    		mysql_query($update) or die(mysql_error());
    }
     $result = mysql_query($query) or die(mysql_error());
    $returnedValue = mysql_fetch_assoc($result);	
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Voting 4 Students</title>
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript">
    <!--
    function confirmSubmit()
    {
    var agree=confirm("Are you sure you wish to delete?");
    if (agree)
    	return true ;
    else
    	return false ;
    }
    function MM_validateForm() { //v4.0
      if (document.getElementById){
        var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
        for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
          if (val) { nm=val.name; if ((val=val.value)!="") {
            if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
              if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
            } else if (test!='R') { num = parseFloat(val);
              if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
              if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
          } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
        } if (errors) alert('The following error(s) occurred:\n'+errors);
        document.MM_returnValue = (errors == '');
    } }
    //-->
    </script>
    
    </head>
    <bocy>
    <?php require_once('includes/header_cp.php'); ?>
    
        <td width="14">&nbsp;</td>
        <td width="727" height="400" align="center" valign="top" bgcolor="#FFFFFF">
          <div align="center">
    
      </div>
    	        <table width="699" border="0" align="center" cellpadding="0" cellspacing="5">
              <tr>
                <td valign="top"><div align="left"></div>	
    			<div align="left">
    			  <p align="right">&nbsp;</p>
    			  <p align="center" class="style1">Biography:
    			    <span class="style2"><?php echo $returnedValue['name']; ?></span>			    <br>
    			  </p>
    			  <table width="700" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>
                  
                        <form name="form1" method="POST" action="addBio.php?join_event_id=<?php echo $event;?>&join_id=<?php echo $id; ?>">
                          <p align="center">
                            <input type="hidden" name="join_event_id" id="join_event_id" value="<?php echo $event ?>">
                            <br>
                          </p>
    			      <p align="center"> <span class="text">Choose Candidate: &nbsp;</span><span class="style6">&nbsp;  
    			        <select name="candidate" class="text" id="position">
    			          <?php
    					  $sql =  "SELECT
    						`id`, `name`
    					FROM
    						`bio` 
    					WHERE
    						`event` = '$event'";
    					$result2 = mysql_query($sql);
    					if(mysql_affected_rows() > 0) {
    						while ($row = mysql_fetch_assoc($result2)) {  
    							echo '<option value="' . $row['id'] . '" '; if($id == $row['id']) echo 'selected="selected"'; echo '>' . $row['name'] . '</option>';
    						} 
    					}
     
    ?>
      </select>
    			        </span>
    			        &nbsp; 
    			        <input name="Submit" type="submit" onClick="MM_validateForm('can_name','','R');return document.MM_returnValue" value="Submit">
    			      </p>
       			          
    		              <div align="center">
      <input type="hidden" name="MM_insert" value="form1">
    		              </div>
                        </form>
    
                        
                        </td>
                    </tr>
                  </table>
    			  <br>
    			  <br>
    			  <br>
    			  <hr width="500">
    			  <br>
    			  <p align="center" class="SubHeaderMain">
    			 
    </p>
    			<form method="post" action="" enctype="multipart/form-data">
    			  <p align="center">Image:  
                     <?php if(isset($content)) { echo $content . '<br/><br/>' . "\n"; } ?> 
    			    <input type="file" name="file" id="file" /></p>
    			  <div align="center">
    			  <?php 
    			  	
    			   if(!empty($returnedValue['image'])) { echo '<p>Current Image is:</p><p><img src="images/'. $returnedValue['image'] .'" alt="' . $returnedValue['image'] . '"/></p>'; } ?>
    			    <br>
    			    <br>
    			    </div>
    			  <p align="left"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $message_bio;?></p>
    				<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea cols="60" rows="10" name="message"><?php echo $returnedValue['message']; ?></textarea>
    				  <br>
    				</p>
    				<p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $hobbies_bio;?></p>
    				<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea cols="60" rows="10" name="hobby"><?php echo $returnedValue['hobby']; ?></textarea>
    				</p>
    				<input type="hidden" name="candidate" value="<?php echo $id ?>">
    				<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="upload" value="Update"></p>
    			  </form>
    	          </div>
    			<table width="627" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
    
    
                    </tr>
                  </table>
                  <p align="left"><span class="SubHeaderMain"><strong><br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Image</strong>: </span><span class="text">Acceptable file types are .gif,  .jpg, &amp; .png. </span>The maximum size and dimensions <br>
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; can be set on  the system values page.</p>
                  <p align="center"><br>
                      <br>
                    <br>
                                <a href="<?php echo $logoutAction ?>">Log out</a></p>
          </td>
              </tr>
            </table>
            <br>
              </td>
        <td width="15">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3"><table width="750" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="750" height="69" background="images/footer_back_tmp.png"><div align="center" class="footer">Copyright &copy;2009 <a href="http://www.software4schools.com" target="_blank">Software 4 Schools</a> </div></td>
          </tr>
        </table></td>
      </tr>
    </table>
    </body>
    </html>
    PHP:
     
    software4, Oct 12, 2009 IP