4 Replies - 2626 Views - Last Post: 08 February 2012 - 06:43 AM Rate Topic: -----

#1 saz09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-February 12

Combo Box not submitting

Posted 08 February 2012 - 06:30 AM

Hi, Iíve been creating a website with a linked MySQL database system. The only problem I have been is that i need to populate a combo box with values from the database. I have managed to populate it, but every time I press submit it just doesn't do anything.


<?php
include("Connection.php");

// Write out our query.
$query = "SELECT Show_Title FROM tblShows";

// Execute it, or return the error message if there's a problem.
$result = mysql_query($query) or die(mysql_error());

$dropdown = "<select name='Show_Title'>";

while($row = mysql_fetch_assoc($result)) {
  $dropdown .= "\r\n<option value='{$row['Show_Title']}'>{$row['Show_Title']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;

?>




I've tried using a submit button on a form to then insert it in to a table but it just isn't working. I am fairly new to PHP and it has been racking my brains. :(

So far the combo box will show with the data that is required but nothing else will happen.

I am guessing I will then need an INSERT query and a submit button to run it. Just have no idea where to enter this information as I've tried but the page just refreshes and no data is submitted.

Is This A Good Question/Topic? 0
  • +

Replies To: Combo Box not submitting

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,025
  • Joined: 08-June 10

Re: Combo Box not submitting

Posted 08 February 2012 - 06:38 AM

that's the code to create the dropdown, but the form's submission is defined in the form's HTML code (which you didn't show). and on the receiving end is probably another PHP script ...

PS. codeprada has made a nice tutorial about populating dropdowns.
Was This Post Helpful? 2
  • +
  • -

#3 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: Combo Box not submitting

Posted 08 February 2012 - 06:39 AM

View Postsaz09, on 08 February 2012 - 01:30 PM, said:

Hi, I’ve been creating a website with a linked MySQL database system. The only problem I have been is that i need to populate a combo box with values from the database. I have managed to populate it, but every time I press submit it just doesn't do anything.

[code]
I am guessing I will then need an INSERT query and a submit button to run it. Just have no idea where to enter this information as I've tried but the page just refreshes and no data is submitted.


Your code generates the drop down - but includes no <form></form> tags so can't submit anywhere.

The submit page would then need to do an insert based on the data contained in $_POST['Show_Title'].

Damn you Dormilich - beat me to it :(.

This post has been edited by KingCuddles: 08 February 2012 - 06:41 AM

Was This Post Helpful? 2
  • +
  • -

#4 saz09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-February 12

Re: Combo Box not submitting

Posted 08 February 2012 - 06:42 AM

View PostDormilich, on 08 February 2012 - 06:38 AM, said:

that's the code to create the dropdown, but the form's submission is defined in the form's HTML code (which you didn't show). and on the receiving end is probably another PHP script ...

PS. codeprada has made a nice tutorial about populating dropdowns.


I had the HTML code at the bottom but removed it.


$Show_Title = $_POST['Show_Title'];

//Attempting to insert it into database
$sql="INSERT INTO tblRequests (Show) VALUES ('$Show_Title')";

} else {
?>

//Form
<h1>Request</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="Submit" value="Add" />
</form>

<?php } ?>




Sorry for not being very clear.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,025
  • Joined: 08-June 10

Re: Combo Box not submitting

Posted 08 February 2012 - 06:43 AM

there is no dropdown inside that form. bear in mind that a form only submits what's inside its <form> tags. everything else/outside is omitted.


View PostKingCuddles, on 08 February 2012 - 02:39 PM, said:

Damn you Dormilich - beat me to it :(.

though you have the grace to have the form issue explained better.

This post has been edited by Dormilich: 08 February 2012 - 07:04 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1