Today we will learn how to create cms using ckeditor and how to save selected data of dropdown value in php?How To: Insert Data into MySQL Database Using Drop Down Box in PHP?How to save values from Dynamic Drop Down List into MySQL database?
simple example
simple example
<select name="color">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Black">Black</option>
<option value="White">White</option>
</select>
<input type="submit" name="submit" />
<?php
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$color=$_POST['color'];
if($name!="" && $color!="")
{
$query=mysql_query("insert into tb(color) values('$color')");
if($query)
{
echo "Updated successfully!";
}
color is table attribute give its TYPE varchar(25).
----------------------------------------------------------
HOME.php
<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Page </title >
<meta http-equiv="content-type" content="text/html; charset=utf-8"/ >
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
</head>
<body>
<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>
<label for="textarea2"></label>
<textarea class="ckeditor" cols="20" id="editor1" name="editor1" rows="10"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="button2" id="button2" value="Upload" />
</td>
</tr>
</table>
</form>
</body>
</html>
</code>
-----------------------------
add.php
<?php
include("mysql.php");
if(isset($_POST["button2"]))
{
$sql="INSERT INTO cktext (papername,email,subject,section,description,upload,uploadtext)
VALUES
('$_POST[textfield]','$_POST[te]','$_POST[select2]',
'$_POST[select]',
'$_POST[textarea]','$_POST[fileField]','$_POST[editor1]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{
echo "Question paper uploaded Successfully</br> YOUR TEXT IS";
$data = mysql_query("SELECT * FROM cktext") or die(mysql_error()); Print "<table border cellpadding=3>";
while($row = mysql_fetch_array( $data ))
{
Print "<tr>"; Print "<th>Name:</th> <td>".$row['papername'] . "</td></tr>";
Print "<tr>"; Print "<th>Blog:</th> <td>".$row['uploadtext'] . " </td></tr>";
echo "--------------------------------<br>";
echo "EMAIL ID :{$row['email']} <br> ".
"description : {$row['description']} <br> ".
"upload : {$row['upload']} <br> ".
"--------------------------------<br>";
} // end of while
Print "</table>";
}//else
}//first if isset
?>
---------------------------------
mysql.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ckeditor",$con);
?>
----------------------------------------
IMP NOTE :- In database subject,section will be of varchar type for words or char.
DOWNLOAD CODE HERE
No comments:
Post a Comment