Jump to content

how to add selected dropdown option in database with php


aavik

Recommended Posts

mysql.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ckeditor",$con);
?>
---------------------------------------------------------
add.php
<?php
include("mysql.php");


if(isset($_POST["button2"]))
{
$sql="INSERT INTO cktext (section)
VALUES
('$_POST[select2]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

?>

-----------------------------------------------------------------
home.php

<form id="form1" name="form1" method="post" action="add.php">
<tr>
    <td>Section:</td>
    <td><select name="select2" id="select2">
     <option selected="selected" value="MALE">Male</option>
  <option selected="" value="FEMAIL">FEMAIL</option>
    </select></td>
  </tr>
<input type="submit" name="button2" id="button2" value="Upload" />
  </form>

In DATABASE :- cktext table attribute "section" is varchar type.

BUT IT RETURN ME BLANK OUTPUT.

Link to comment
Share on other sites

 

 

BUT IT RETURN ME BLANK OUTPUT.

In add.php you are only running a query to insert a record into your ckeditor table. There is no other code in add.php to "output" anything. So that would be expected output if the script ran successfully.

 

You need to be aware that using raw $_POST data (or any data from a user) in a query is extremely dangerous. You should sanitize any user input before using it in a query to protect yourself from SQL injection.

 

I would strongly advise you to not use the mysql_* functions as these are now deprecated meaning they are no longer supported and could soon be removed from future versions of php. Instead use either MySQLi or PDO. Using prepared queries when using user input in a query.

Link to comment
Share on other sites

THIS IS MY FULL CODE ..

 EVERY VALUE TYPE IN THE FORM GET STROE BUT.

<select name="select" id="select">
     <option selected="selected" value="MALE">Male</option>
  <option selected="" value="FEMAIL">FEMAIL</option>
    </select>

MALE or FEMAIL DOESN'T GET STORED in DATABASE.

In DATABASE :- cktext table attribute "section" is varchar type.

 

 

<form id="form1" name="form1" method="post" action="add.php">
<table width="958" height="372">
  <tr>
    <td width="69">Name:</td>
    <td width="608"><input name="textfield" type="text" id="textfield" size="40" /></td>
  </tr>


<tr>
    <td width="69">Email:</td>
    <td width="608"><input name="te" type="text" id="te" size="40" /></td>
  </tr>


  <tr>
    <td>Section:</td>
    <td><select name="select" id="select">
     <option selected="selected" value="MALE">Male</option>
  <option selected="" value="FEMAIL">FEMAIL</option>
    </select></td>
  </tr>
  <tr>
    <td>Subject:</td>
    <td><select name="select2" id="select2">
<option selected="selected" value="MA">Ma</option>
  <option selected="" value="FE">FE</option>
    
    </select></td>
  </tr>
  <tr>
    <td height="53">Description</td>
    <td><textarea name="textarea" id="textarea" cols="45" rows="3"></textarea></td>
  </tr>
  <tr>
    <td>Upload</td>
    <td>
      <label for="fileField"></label>
      <input name="fileField" type="file" id="fileField" size="40" />
    </td>
  </tr>
  <tr>
    <td> </td>
    <td>
      <input type="submit" name="button2" id="button2" value="Upload" />
    </td>
  </tr>
</table>

</form>
 

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.