Click here to Skip to main content
15,888,977 members
Home / Discussions / Web Development
   

Web Development

 
QuestionMVCCodeRouting Pin
#realJSOP30-Nov-17 6:39
mve#realJSOP30-Nov-17 6:39 
AnswerRe: MVCCodeRouting Pin
Nathan Minier1-Dec-17 1:43
professionalNathan Minier1-Dec-17 1:43 
GeneralRe: MVCCodeRouting Pin
#realJSOP1-Dec-17 8:13
mve#realJSOP1-Dec-17 8:13 
GeneralRe: MVCCodeRouting Pin
Nathan Minier4-Dec-17 1:15
professionalNathan Minier4-Dec-17 1:15 
QuestionMVC and Custom Routes Pin
#realJSOP30-Nov-17 5:08
mve#realJSOP30-Nov-17 5:08 
AnswerRe: MVC and Custom Routes Pin
Richard Deeming30-Nov-17 8:24
mveRichard Deeming30-Nov-17 8:24 
GeneralRe: MVC and Custom Routes Pin
#realJSOP1-Dec-17 1:04
mve#realJSOP1-Dec-17 1:04 
QuestionHow do I insert dropdown Text, not the value, into the database? Pin
samflex17-Nov-17 9:58
samflex17-Nov-17 9:58 
Can someone please give a hand?

I am stumped on this.

In ASP.NET, for instance, if you have the following dropdownlist:

PHP
<ASP:DropDownList ID="DropDownList1" runat="server">
  ListItem Value="Pastorsname">PastorName</ListItem>
</ASP:DropDownList>


and I wish to grab the text called PastorName and insert into the database, all I would need to do is this simple syntax:
PHP
DropDownList1.SelectedItem.Text


I am trying to do something similar in PHP:

 //Markup
       <table id="dataTable">
                      <tbody>
                    <tr>
                     <td>
                      <?php
						$conn=mysqli_connect("localhost","xphiasuser","xphiasadmin","xphias_sermon");
						 // Check connection
						 if (mysqli_connect_errno())
						   {
						   echo "Failed to connect to MySQL: " . mysqli_connect_error();
				         }
                        $select_query="Select pastorname, ministryname from xphias_clients";
						$select_query = mysqli_query( $conn,$select_query);
						echo "<select name='pastorsname' id='pastorsname' class='form-control'>";
						echo "<option value=' '></option>";
						while ($rc=   mysqli_fetch_array($select_query) )
						{
						   echo "<option value='" .$rc['ministryname'] . "'>" . $rc['pastorname'] . "</option>";
						}
						echo "</select>"; ?></td>
                     <td><INPUT TYPE="TEXT" class="form-control" NAME="ministriesname" id="ministriesname" SIZE="16"></td>
                     <td><INPUT TYPE="TEXT" class="form-control" NAME="sermondate" SIZE="10"></td>
                     <td><INPUT TYPE="TEXT" class="form-control" NAME="sermonname" SIZE="16"></td>
                     <td><INPUT INPUT="TEXT" class="form-control" NAME="scriptures" SIZE="16"></td>
                     <td><INPUT INPUT="TEXT" class="form-control" NAME="videoname" SIZE="10"></td>
                     <td><INPUT INPUT="TEXT" class="form-control" NAME="sermonnotes" SIZE="16"></td>
                    </tr>
                   </table>
                   <table>
                    <tr>
                     <td><INPUT type="file" class="form-control" name="fileToUpload" /></td>
                     <td><INPUT TYPE="submit" value="Save" SIZE="14" name="upd"></td>
                    </tr>
                  </tbody>
                 </table>
                 
		   <script type="text/javascript">
		      $(document).ready(function(){
		      $('#pastorsname').change(function(){
		      var ministriesname = $(this).val();
		      $('#ministriesname').val(ministriesname);
		    });
	          });
	         </script> 
	         
	   //  process.php

if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {

    $sql = "INSERT INTO xphias_sermons (pastorname, ministriesname, sermon_name, scripture, video_name, sermon_notes,sermon_date)
    SELECT ministryname, pastorname, ?, ?, ?, ?, ? FROM xphias_clients WHERE ministryname = ?;
//    VALUES (?, ?, ?, ?, ?, ?, ?)";
    $stmt = $conn->prepare($sql);

    $stmt->bind_param('sssssss', $pastorname, $ministriesname, $sermonname, $scriptures, $videoname, $sermonnotes, $sermondate);
}

//$video_path=$_FILES['fileToUpload']['name'];

//$ministriesname = isset($_POST['pastorsname']) ? $_POST['pastorsname'] : false;
$pastorname = $_POST['pastorsname'];
$ministriesname= $_POST['ministriesname'];
$sermondate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $_POST['sermondate'])));
//echo "Input: {$_POST['xstartdate'][$i]}, Start date: {$startdate}<br>\n"; //For debugging
$sermonname= $_POST['sermonname'];
$scriptures= $_POST['scriptures'];
$videoname= $_POST['videoname'];
$sermonnotes= $_POST['sermonnotes'];


In this PHP code, the <select...>.., the SELECT Value is pastorname and the text is ministryname.

How do I grab the value of text of ministryname and insert that into the database?

Your help is greatly appreciated.
AnswerRe: How do I insert dropdown Text, not the value, into the database? Pin
W Balboos, GHB6-Dec-17 7:27
W Balboos, GHB6-Dec-17 7:27 
GeneralMessage Closed Pin
24-Jan-19 11:19
Sarah George24-Jan-19 11:19 
GeneralRe: How do I insert dropdown Text, not the value, into the database? Pin
W Balboos, GHB25-Jan-19 1:14
W Balboos, GHB25-Jan-19 1:14 
GeneralRe: How do I insert dropdown Text, not the value, into the database? Pin
Richard Deeming25-Jan-19 2:33
mveRichard Deeming25-Jan-19 2:33 
QuestionOne Step Forward, Two Steps Back - Can't create controller using scaffolding Pin
#realJSOP10-Nov-17 2:04
mve#realJSOP10-Nov-17 2:04 
AnswerRe: One Step Forward, Two Steps Back - Can't create controller using scaffolding Pin
#realJSOP11-Nov-17 11:16
mve#realJSOP11-Nov-17 11:16 
QuestionSys.WebForms.Res is undefined when javascript executed inside updatepanel Pin
Claudio Trenca8-Nov-17 4:38
professionalClaudio Trenca8-Nov-17 4:38 
QuestionMVC5 - Logoff does not work in Chrome Pin
#realJSOP7-Nov-17 1:59
mve#realJSOP7-Nov-17 1:59 
AnswerRe: MVC5 - Logoff does not work in Chrome Pin
Richard Deeming7-Nov-17 2:22
mveRichard Deeming7-Nov-17 2:22 
GeneralRe: MVC5 - Logoff does not work in Chrome Pin
#realJSOP7-Nov-17 2:39
mve#realJSOP7-Nov-17 2:39 
GeneralRe: MVC5 - Logoff does not work in Chrome Pin
Richard Deeming7-Nov-17 2:45
mveRichard Deeming7-Nov-17 2:45 
GeneralRe: MVC5 - Logoff does not work in Chrome Pin
#realJSOP7-Nov-17 2:47
mve#realJSOP7-Nov-17 2:47 
GeneralRe: MVC5 - Logoff does not work in Chrome Pin
Richard Deeming7-Nov-17 2:53
mveRichard Deeming7-Nov-17 2:53 
GeneralRe: MVC5 - Logoff does not work in Chrome Pin
#realJSOP7-Nov-17 2:59
mve#realJSOP7-Nov-17 2:59 
GeneralRe: MVC5 - Logoff does not work in Chrome Pin
Richard Deeming7-Nov-17 3:03
mveRichard Deeming7-Nov-17 3:03 
GeneralRe: MVC5 - Logoff does not work in Chrome Pin
#realJSOP7-Nov-17 3:01
mve#realJSOP7-Nov-17 3:01 
AnswerRe: MVC5 - Logoff does not work in Chrome Pin
aijaj hussain18-Nov-17 20:09
aijaj hussain18-Nov-17 20:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.