Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
ThePiston
Worker
Worker



Joined: Dec 22, 2004
Posts: 135

PostPosted: Mon Oct 17, 2005 10:28 pm Reply with quote

I have a form that uses radio inputs to get a result. This is the code for the relevant part of the form
Code:
      ."<input type=\"radio\" name=\"locationid\" value=\"1\" $sel1> "._FW."<br>"      

      ."<input type=\"radio\" name=\"locationid\" value=\"2\" $sel1> "._NW." <br>"
      ."<input type=\"radio\" name=\"locationid\" value=\"3\" $sel1> "._N." <br>"
      ."<input type=\"radio\" name=\"locationid\" value=\"4\" $sel1> "._S." <br>"
      ."<input type=\"radio\" name=\"locationid\" value=\"5\" $sel1> "._E." <br>"
      ."<input type=\"radio\" name=\"locationid\" value=\"6\" $sel1> "._CH." <br>"
      ."<input type=\"radio\" name=\"locationid\" value=\"7\" $sel1> "._RF." <br>";
What I'd like to do is have each input submit 2 values for 2 different variables. So, if the first radio button was checked, then a value of '1' would be placed for the 'locationcode', but I'd also like a value of "Far West End" to be placed in the 'description' variable inside same table. Could I do something like this?
Code:
if ($locationid == '1') {

   $description = 'Far West End';
}
then in the query do this
Code:
$query = "insert into table (locationid, description) values ($locationid, $description)"; 
 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Mon Oct 17, 2005 11:03 pm Reply with quote

Absolutely. Another way would be something like this
Code:
."<input type=\"radio\" name=\"locationid\" value=\"1/Far West End\" $sel1> "._FW."<br>"

Then instead of the if test logic, you could do this
Code:
$locArray = explode('/',$locationid);

$locationid = $locArray[0];
$description = $locArray[1];
$query = "insert into table (locationid, description) values ($locationid, $description)";

or even simpler
Code:
$locArray = explode('/',$locationid);

$query = "insert into table (locationid, description) values ($locArray[0], $locArray[1])";
 
View user's profile Send private message
ThePiston







PostPosted: Tue Oct 18, 2005 8:42 am Reply with quote

so this code
Code:
$locArray = explode('/',$locationid);

$query = "insert into table (locationid, description) values ($locArray[0], $locArray[1])";
goes into the form or the "saveoffice" code? I know I need to add $description to globals, etc too. Also, would I need to change this code:
Code:
    case 'saveoffice':

   saveoffice($locationid, $description, $offname, $add1, $add2, $city, $state, $zip, $phone, $fax, $website);
   break;
to this:
Code:
    case 'saveoffice':

   saveoffice($locarray[0], $locarray[1], $offname, $add1, $add2, $city, $state, $zip, $phone, $fax, $website);
   break;
?


Last edited by ThePiston on Tue Oct 18, 2005 8:51 am; edited 1 time in total 
Raven







PostPosted: Tue Oct 18, 2005 8:46 am Reply with quote

It goes wherever you actually run the query from. $description does not have to be global, necessarily, since you are passing it via a function call.
 
ThePiston







PostPosted: Tue Oct 18, 2005 9:14 am Reply with quote

Raven wrote:
It goes wherever you actually run the query from. $description does not have to be global, necessarily, since you are passing it via a function call.
Do I have to chaneg the "case saveoffice" code to this
Code:
    case 'saveoffice':

   saveoffice($locarray[0], $locarray[1], $offname, $add1, $add2, $city, $state, $zip, $phone, $fax, $website);
   break;

?
 
ThePiston







PostPosted: Tue Oct 18, 2005 9:47 am Reply with quote

nm, got it, thanks again Raven, you rule
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©