8 Replies - 801 Views - Last Post: 24 January 2016 - 06:22 PM Rate Topic: -----

#1 ahuby09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-October 14

How to get the text value of a select form

Posted 24 January 2016 - 05:42 PM

im wanting to get the value of my select form and make the variable title = $_POST["title"]; but everything i have tried hasn't worked. here is my code
<?php

include_once("../../includes/connect.php");


$sqli = "SELECT * FROM cms ORDER BY id DESC";
 			
$result = $link->query($sqli); 
echo "
<form action='DoEdit.php' method='POST' >
<select name='title'>";
foreach($result as $row) {

	
    echo "
		<option value=" . $row['title'] .">".$row['Title']."</option>
	";
	
}

echo "
<input type='submit' name='submit' />
</select>
</form>";

?>



Is This A Good Question/Topic? 0
  • +

Replies To: How to get the text value of a select form

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2541
  • View blog
  • Posts: 10,180
  • Joined: 03-December 12

Re: How to get the text value of a select form

Posted 24 January 2016 - 05:48 PM

And DoEdit.php is???
Was This Post Helpful? 0
  • +
  • -

#3 ahuby09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-October 14

Re: How to get the text value of a select form

Posted 24 January 2016 - 05:52 PM

<?php

//get the data by its id (make variable for title then select * from database whats got that title echo the paramaters into a text box, after add asubmit button submit a update query to the database)

if(isset($_POST['title'])){
	$title = $_POST['title'];
}
echo $title;
?>


Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2541
  • View blog
  • Posts: 10,180
  • Joined: 03-December 12

Re: How to get the text value of a select form

Posted 24 January 2016 - 05:54 PM

I am not seeing anything incorrect. What is it doing?
Was This Post Helpful? 0
  • +
  • -

#5 ahuby09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-October 14

Re: How to get the text value of a select form

Posted 24 January 2016 - 05:55 PM

View Postastonecipher, on 24 January 2016 - 05:54 PM, said:

I am not seeing anything incorrect. What is it doing?

It just wont show what i selected and willsay title is undefined
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2541
  • View blog
  • Posts: 10,180
  • Joined: 03-December 12

Re: How to get the text value of a select form

Posted 24 January 2016 - 05:57 PM

Inspect the select element and see if the values are displaying.

You have $row['title'] and $row['Title'], that may be causing an issue. The other thing is not surrounding the value in quotes.
Was This Post Helpful? 0
  • +
  • -

#7 ahuby09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-October 14

Re: How to get the text value of a select form

Posted 24 January 2016 - 06:00 PM

View Postastonecipher, on 24 January 2016 - 05:57 PM, said:

Inspect the select element and see if the values are displaying.

You have $row['title'] and $row['Title'], that may be causing an issue. The other thing is not surrounding the value in quotes.

Still getting the error undefind index could it be cause im looping through a database and putting it into a select ? if so how could I fix this
Was This Post Helpful? 0
  • +
  • -

#8 ahuby09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-October 14

Re: How to get the text value of a select form

Posted 24 January 2016 - 06:15 PM

Managed to fix it thanks
$title = $_POST['Title'];
	echo $title;



this fixed the problem
Was This Post Helpful? 0
  • +
  • -

#9 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2541
  • View blog
  • Posts: 10,180
  • Joined: 03-December 12

Re: How to get the text value of a select form

Posted 24 January 2016 - 06:22 PM

do a print_r( $result ); just after you get the results.

Nevermind. Glad you got it working.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1