Jump to content

Insert 2 Values From Drop Down Menu?


justlukeyou

Recommended Posts

Yeah thanks, but that doesn't help.

 

Could someone please explain it very simple terms what I need to do.

 

Do I select "Reception Room" from the drop down menu and then convert one into "reception-room" and then enter that into 'linkcategory'?

 

WHY DIDN'T YOU TRY DOING THIS?

 

I smell a troll at this point.

Or...., he/she doesn't understand EN very well.

Link to comment
Share on other sites

  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

1. He understands just fine. Look at the responses.

2. Based on his posts and your posts, I think you are the one who doesn't speak or understand English very well. I mean that as purely observational, not an insult. Also, most people aren't going to know what you mean by EN so write the whole word.

Link to comment
Share on other sites

1. He understands just fine. Look at the responses.

2. Based on his posts and your posts, I think you are the one who doesn't speak or understand English very well. I mean that as purely observational, not an insult. Also, most people aren't going to know what you mean by EN so write the whole word.

@off absolutely right  :D

Link to comment
Share on other sites

This is the code I am using. As you can see I have tried to follow the process of adding 'Reception Room' and 'reception-room' into the 2 different columns.

 

Should this process be working?

 

<?php

if(isset($_POST['form_id'])){
    $category = mysql_real_escape_string(trim($_POST['category']));
    $linkcategory = mysql_real_escape_string(trim($_POST['linkcategory']));
    $firstname = mysql_real_escape_string(trim($_POST['firstname']));
    $surname = mysql_real_escape_string(trim($_POST['surname']));
    $email = mysql_real_escape_string(trim($_POST['email']));
    $website = mysql_real_escape_string(trim($_POST['website']));
    $company = mysql_real_escape_string(trim($_POST['company']));
    $building = mysql_real_escape_string(trim($_POST['building']));
    $streetname = mysql_real_escape_string(trim($_POST['streetname']));
    $state = mysql_real_escape_string(trim($_POST['state']));
    $postcode = mysql_real_escape_string(trim($_POST['postcode']));
    $country = mysql_real_escape_string(trim($_POST['country']));
    $aboutcompany = mysql_real_escape_string(trim($_POST['aboutcompany']));
    $error = false;
    
       if(!isset($category) || empty($category)) {
  $error = "Please select a category.";
    }

    if(!isset($firstname) || empty($firstname)) {
  $error = "Please enter a First Name.";
    }

    if(!isset($surname) || empty($surname)) {
  $error = "Please enter a Surname.";
    }

    if(!isset($email) || empty($email)) {
  $error = "Please enter an email.";
    }

    if(!isset($website) || empty($website)) {
  $error = "Please enter a Website Domain.";
    }

    if(!isset($company) || empty($company)) {
  $error = "Please enter a Company Name.";
    }

    if(!isset($building) || empty($building)) {
  $error = "Please enter a Building Name or Number.";
    }

    if(!isset($streetname) || empty($streetname)) {
  $error = "Please enter a Street Name.";
    }

    if(!isset($state) || empty($state)) {
  $error = "Please enter a State.";
    }

    if(!isset($postcode) || empty($postcode)) {
  $error = "Please enter a Zip Code/Post Code.";
    }

      if(!isset($country) || empty($country)) {
  $error = "Please select your country.";
    }

    if(!isset($aboutcompany) || empty($aboutcompany)) {
  $error = "Please enter details about your company.";
    }


    if(!$error) {

        $query = mysql_query("INSERT INTO organiserdbase (category, linkcategory, firstname, surname, email, website, company, building, streetname, state, postcode, country, aboutcompany) VALUES ('".$category."', '".$linkcategory."', '".$firstname."', '".$surname."', '".$email."', '".$website."', '".$company."', '".$building."', '".$streetname."', '".$state."', '".$postcode."', '".$country."', '".$aboutcompany."')");
        if($query) {
        } else {
$error = "There was a problem with the submission. Please try again.";
        }
    }
}

?>



<div id="registerpagecell">
<div id="registerpageheaderorganiser">
Create Your Organiser Profile 
</div>
<div id="registerform">

<form id="form_id"  class="appnitro"  method="post" action="">

    
<?php if($error) echo "<span style=\"color:#ff0000;\">".$error."</span><br /><br />"; ?>		
<ul >


	<div id="forminputcell">
<li id="li_1" >
	<div id="forminputleft">
<label class="description" for="element_3">Your Job Role:</label>
</div>
	<div id="forminputright">
<select  class="element select medium" id="category, linkcategory" > 			
			</div> 	
<option value="" selected="selected">Venue:</option>

<option VALUES('Reception Room', 'reception-room') >Reception Room</option>

Link to comment
Share on other sites

Yes, even in the few lines of form code you've posted there are many errors.  <div> within <ul> and "nesting" issues with </div> within <select> tags etc.  Get tidy validator for firefox or another validator to check your code.  Another issue is the <select> tag is not named.  Any input field should be uniquely named.  I'm sure it's been mentioned that creating an array would solve many of the issues you are trying to answer in having both a category name and link value.  You can then easily check posted value against this array and use the array key to get the name.  Here's a sample.

<?php
include "access.php"; 
$categories = array("reception-room"=>"Reception Room","hotel"=>"Hotel","night-club"=>"Night Club");

if(isset($_POST['category'])){

$_POST['category'] = trim($_POST['category']);

if(!array_key_exists($_POST['category'],$categories)) {
	$error = "Please select a category.";
}

if(!isset($error)) {
	$category = mysql_real_escape_string($categories[$_POST['category']]);
	$linkcategory = mysql_real_escape_string($_POST['category']);
	$sql = "INSERT INTO organiserdbase (category, linkcategory) VALUES ('$category','$linkcategory')";
	echo "$sql";
	/*
	$query = mysql_query($sql);
	if($query) {
	} else {
		$error = "There was a problem with the submission. Please try again.";
	}
	*/		
}
}

?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title></title>  
</head>
<body>
<div id="registerpagecell">
	<div id="registerpageheaderorganiser">
	Create Your Organiser Profile 
	</div>
	<div id="registerform">
		<form id="form_id" name="form_id" class="appnitro" method="post" action="">
			<?php if(isset($error)){ echo "<span style=\"color:#ff0000;\">".$error."</span><br /><br />";}?>
			<div id="forminputcell">
				<div id="forminputleft">
					<label class="description" for="element_3">Your Job Role:</label>
				</div>
				<div id="forminputright">
					<select class="element select medium" name="category" id="category" > 
						<option value="" selected="selected">Venue:</option>
						<?php
						foreach($categories as $key => $value){
							$selected=(isset($_POST['category']) && $_POST['category']==$key ? ' selected="selected"' : ''); 
							echo "<option value=\"$key\"$selected>$value</option>";
						}
						?>
					</select> 			
				</div> 				
			</div> 	
			<input type="submit" value="Submit" />
		</form>				
	</div> 				
</div> 
</body>
</html>

Link to comment
Share on other sites

And with the str_replace() and strtolower() option as suggested several times.

<?php
include "access.php"; 

if(isset($_POST['category'])){

$_POST['category'] = trim($_POST['category']);

if(!empty($_POST['category'])) {
	$error = "Please select a category.";
}

if(!isset($error)) {
	$category = mysql_real_escape_string($categories[$_POST['category']]);
	$linkcategory = str_replace(' ', '-',strtolower($_POST['category']);
	$linkcategory = mysql_real_escape_string($linkcategory);
	$sql = "INSERT INTO organiserdbase (category, linkcategory) VALUES ('$category','$linkcategory')";
	echo "$sql";
	/*
	$query = mysql_query($sql);
	if($query) {
	} else {
		$error = "There was a problem with the submission. Please try again.";
	}
	*/		
}
}

?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title></title>  
</head>
<body>
<div id="registerpagecell">
	<div id="registerpageheaderorganiser">
	Create Your Organiser Profile 
	</div>
	<div id="registerform">
		<form id="form_id" name="form_id" class="appnitro" method="post" action="">
			<?php if(isset($error)){ echo "<span style=\"color:#ff0000;\">".$error."</span><br /><br />";}?>
			<div id="forminputcell">
				<div id="forminputleft">
					<label class="description" for="element_3">Your Job Role:</label>
				</div>
				<div id="forminputright">
					<select class="element select medium" name="category" id="category" > 
						<option value="" selected="selected">Venue:</option>
						<option value="Event Manager" >Event Manager</option>
						<option value="Event Managent Courses" >Event Managent Courses</option>
						<option value="Event Management Software" >Event Management Software</option>
						<option value="Entertainment Staff" >Entertainment Staff</option>
					</select> 			
				</div> 				
			</div> 	
			<input type="submit" value="Submit" />
		</form>				
	</div> 				
</div> 
</body>
</html>

Link to comment
Share on other sites

Well it's your html markup that really needed help.  A good IDE editor will tell you when you have errors in your php.  NetBeans is one option.  Most of the errors I noticed had to do with nesting.  For example if you want to "position" a selection box you don't put div tags around the <option> tags but rather the <selection> tags and you certainly need to watch nesting for example <b><i>word</i></b> not <b><i>word</b></i>.

Link to comment
Share on other sites

Drummin,

 

Thanks you ever so much for putting that code up.  Being able to see what I should  be doing helps massively.  It was very good of you to do that.

 

IMHO people being prepared to show people what to do is that makes this a fantastic forum.  It turns gobbledeegook into something visual.  Thanks big time.

 

I tried the first one and it returned the message "INSERT INTO organiserdbase (category, linkcategory) VALUES ('Reception Room','reception-room')" but didn't enter anything into the DB.

 

I tried the second but it returned a syntax error, unexpected ';'

 

I shall go through but its brilliant to see what I should be doing.

 

Big Thanks.

 

 

 

 

Link to comment
Share on other sites

If you notice in my samples, I just echo the query so you can SEE that the values are as expected.  It's a good practice especially when having problems to echo the query to make sure all values are as expected.  You can comment out or remove that "test" echo and un comment the query execution lines so it actually should do the query.

Link to comment
Share on other sites

Actually, there is a Fx plugin for debugging PHP scripts. However, you'll need to have Zend Server with the debug module loaded in order for it to do anything. Never tried it myself, as I just use Zend Studio's remote debugging feature whenever I need that kind of functionality.

For checking the syntax, however, any IDE and/or PHP-enabled interpreter will do that for you; If you have a syntax problem, you get an error and the script won't execute.

 

Asking for a PHP syntax validator is like asking for a test to find out if your car will start or not, without actually trying to start it.

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.