14 Replies - 520 Views - Last Post: 07 March 2012 - 08:09 AM Rate Topic: -----

#1 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

<option> and php

Posted 06 March 2012 - 11:49 PM

hey guys...

I'm having a problem with the <option> and <select>...I go to the table to fetch the data but I can't seem to put it on the "combobox", combobox comes empty!

Any idea what it might be?

here is the code I'm using:

echo "<select>";
		
                
                
                echo "<option"; if($row['emplacement'] == 1) echo "value ='1'>place 1</option>";
                echo "<option"; if($row['emplacement'] == 2) echo "value ='2'>place 2</option>";
                echo "<option"; if($row['emplacement'] == 3) echo "value ='3'>place 3</option>";
                
                echo "<option"; if($row['emplacement'] == 4) echo "value ='4'>place 4</option>";
                echo "<option"; if($row['emplacement'] == 5) echo "value ='5'>place 5</option>";
                echo "<option"; if($row['emplacement'] == 6) echo "value ='6'>place 6</option>";
		echo "</selected>";



Is This A Good Question/Topic? 0
  • +

Replies To: <option> and php

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: <option> and php

Posted 07 March 2012 - 01:09 AM

Well yes, did you look at the produced HTML?

It will be something like this:
<select><option<optionvalue='2'>place 2</option><option<option<option</selected>


Does that look right to you?

It should be (provided I understand what you're doing):
<select>
    <option value="1">place 1</option>
    <option value="2" selected="selected">place 2</option>
    <option value="3">place 3</option>
</select>


1; Add a space
2; Change <selected> to <select> because that is the tag you're creating
3; Always output the value because at the moment you have a lot of malformed HTML being output
3; I think that you could be missing the point of what this is doing, you're going to have a lot of options without values if you use this code. Your code, I think, should look more like this:
?><select>
    <option value="1"<?php if ($row['emplacement'] == 1) { ?> selected="selected"<?php } ?>>place 1</option>
    <option value="2"<?php if ($row['emplacement'] == 2) { ?> selected="selected"<?php } ?>>place 2</option>
    <option value="3"<?php if ($row['emplacement'] == 3) { ?> selected="selected"<?php } ?>>place 3</option>
    <option value="4"<?php if ($row['emplacement'] == 4) { ?> selected="selected"<?php } ?>>place 4</option>
    <option value="5"<?php if ($row['emplacement'] == 5) { ?> selected="selected"<?php } ?>>place 5</option>
    <option value="6"<?php if ($row['emplacement'] == 6) { ?> selected="selected"<?php } ?>>place 6</option>
</select><?php


or even better (short tags/PHP 5.4 permitting):
?><select>
    <?php for($i = 1; $i < 7; $i++): ?>
        <option value="<?= $i ?>"<?= ($row['emplacement'] == $i) ? 'selected="selected"' : '') ?>>
            place <?= $i ?>
        </option>
    <?php endfor ?>
</select>

This post has been edited by RudiVisser: 07 March 2012 - 01:10 AM

Was This Post Helpful? 2
  • +
  • -

#3 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

Re: <option> and php

Posted 07 March 2012 - 01:34 AM

You are right...My code was a bit "confussing" for the least...thanks for the explenation it really helped me understand the code...I had it all wrong in my head!
Was This Post Helpful? 0
  • +
  • -

#4 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

Re: <option> and php

Posted 07 March 2012 - 02:31 AM

Not I'm having another problem with this combobox.

when I click in the submit button it goes to my page "update_ligne.php" but when I declare a variable to have the value from emplacement it gives me this

( ! ) Notice: Undefined index: emplacement in C:\wamp\www\PHP\update_ligne.php on line 32
Call Stack
#	Time	Memory	Function	Location
1	0.0375	374496	{main}( )	..\update_ligne.php:0





and this is my ligne 32

$emplacement = 	($_POST['emplacement']);



Can't seem to find error cus I I'm using pretty much the same code as in my creation form and there it is working fine!!

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#5 Macjohn  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 80
  • View blog
  • Posts: 407
  • Joined: 10-April 09

Re: <option> and php

Posted 07 March 2012 - 02:42 AM

Try putting it like this:

$emplacement =  (isset($_POST['emplacement']));


:dozingoff:
Was This Post Helpful? 1
  • +
  • -

#6 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

Re: <option> and php

Posted 07 March 2012 - 02:47 AM

Thanks, it solved my problem with ligne 32!.

But now I'm having another error. I think it is my UPDATE function!
Was This Post Helpful? 0
  • +
  • -

#7 Macjohn  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 80
  • View blog
  • Posts: 407
  • Joined: 10-April 09

Re: <option> and php

Posted 07 March 2012 - 02:50 AM

show us your UPDATE code and we may be able to help you!
Was This Post Helpful? 0
  • +
  • -

#8 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

Re: <option> and php

Posted 07 March 2012 - 02:51 AM

$qry = "UPDATE INTO computers(machine, ip, emplacement) VALUES('$machine','$ip','$emplacement')";
	$result = @mysql_query($qry);
	
	//Check whether the query was successful or not
	if($result) {
		header("location: index.php");
	
		exit();
	}else {
	echo('Query failed');
		die("Query result failed");
	}

Was This Post Helpful? 0
  • +
  • -

#9 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

Re: <option> and php

Posted 07 March 2012 - 03:14 AM

i tried this too...

$qry = "UPDATE computers SET machine='$machine' ip='$ip'";
	$result = @mysql_query($qry);



Not working
Was This Post Helpful? 0
  • +
  • -

#10 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: <option> and php

Posted 07 March 2012 - 03:22 AM

mysql_error()

Not to be funny, but I think you should go learn PHP basics.
Was This Post Helpful? 1
  • +
  • -

#11 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

Re: <option> and php

Posted 07 March 2012 - 03:37 AM

Sorry but I don't understand what you mean...
I know I still need to learn alot but where should i put that mysql_error()

top, bottom

its ok...found it...
Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: <option> and php

Posted 07 March 2012 - 04:27 AM

View PostRudiVisser, on 07 March 2012 - 05:22 AM, said:

mysql_error()

Not to be funny, but I think you should go learn PHP basics.


Totally agree. Seems like 90% of the people posting here have absolutely NO concept of the basics at all, and NO logical or debugging skills of their own. It's extremely frustrating.

Like this:

Quote

I know I still need to learn alot but where should i put that mysql_error()


Seriously??? No sense of logic at ALL!

"Here's a function that will print out an error."

"Hurr durr...where do I put it?"

Where the HELL do you THINK you'd put a function that prints an ERROR???

Sorry if you think that's harsh, but that's just so ridiculous on its face. I'm guessing you're just copying and pasting your way to a solution.
Was This Post Helpful? 1
  • +
  • -

#13 Macjohn  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 80
  • View blog
  • Posts: 407
  • Joined: 10-April 09

Re: <option> and php

Posted 07 March 2012 - 08:00 AM

Ok, I see you still didn't found your error (cus if you did try to post it here to help some other people in the future!)

try to write it like this:

$qry = "UPDATE computers SET machine='$machine', ip='$ip'";



You forgot a small thing ","

cya mate
Was This Post Helpful? 1
  • +
  • -

#14 Macjohn  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 80
  • View blog
  • Posts: 407
  • Joined: 10-April 09

Re: <option> and php

Posted 07 March 2012 - 08:06 AM

oh, and try to read before asking...google is a really good friend!
Search first, ask later!

But don't take it the wrong way!

Cya
Was This Post Helpful? 1
  • +
  • -

#15 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

Re: <option> and php

Posted 07 March 2012 - 08:09 AM

Ok, sorry for before, I'll try to search a bit better next time I have a stupid question!

Oh, and I found the answer by myself but thanks again for the time!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1