Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
[1] HTML Page :-

<form name="choice" method="POST" action="test_table.php?command=list" enctype="multipart/form-data">
<select name="category" id="cat_nm">
<option>Living_Room</option>
<option>Kitchen</option>
<option>Bedroom</option>
</select>
<input type="submit" name="btnChoice" id="btnChoice" value="Okay"/>
</form>

[2] test_table.php :-

Quote:
$conn=@mysql_connect('localhost','root','') or die ('Not Connected...');
$db=mysql_select_db('project_interior',$conn);
$command = isset($_GET['command']) ? $_GET['command'] : 'list';
// $choice=$_POST['category'];

switch($command)
{
case "list":
test_table_list();
break;
case "add":
test_table_add();
break;
case "insert":
test_table_insert();
break;
}

function test_table_list()
{
if(isset($_POST['category']))
{
$choice = $_POST['category'];

$selQuery = "SELECT * FROM $choice";
$rsQuery = mysql_query($selQuery) or die('Query Not Executed');
$htmlTable = '
Add';
while($rowQuery = mysql_fetch_array($rsQuery))
{
$htmlTable .= '';
}
$htmlTable .= '
EditDeleteIDPicturePrice
' . $rowQuery['id'] . '<img src="' . $rowQuery['snap'] . '" height="150" width="150">' . $rowQuery['price'] . '
';
echo $htmlTable;
}
}

function test_table_insert()
{
if(isset($_POST['category']))
{
$choice=$_POST['category'];
$price1=$_POST['txtPrice'];
$filename=$_FILES['fileSnap']['name'];
$path="./images1";
$type=$_FILES['fileSnap']['type'];
$str=substr($type,0,5);

if($str=="image")
{
if(move_uploaded_file($_FILES['fileSnap']['tmp_name'],$path."/".$filename))
{
$mysql_path=$path."/".$filename;
$sql="INSERT INTO $choice(snap,price) VALUES ('$path','$price1')";

if(mysql_query($sql))
{
echo "Uploaded successfully...";
test_table_list();
}
else
{
echo "Sorry plz try again...";
}
}
else
{
echo "There was an error uploading the file, please try again!";
}
}
else
{
echo "select image";
}
}
}

function test_table_add()
{
?>

<form method="post" action="test_table.php?command=insert">

Picture <input type="file" name="fileSnap"/>
Price <input type="text" name="txtPrice"/>
<input type="submit" name="btnAdd" value="Add"/>

</form>

}
?>
Posted
Updated 28-Aug-14 1:47am
v3
Comments
W Balboos, GHB 29-Aug-14 11:56am    
One thing you might try one it comes to accessing the value of a <select> element:
You need to give them (i.e., the <options> values to access)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900