Inserting radio buttons values in database.
Posted: Thu Apr 17, 2008 1:05 pm
Hi there. Thanks for reading this. I am new to php and I have to construct a photo manager which displays all images from an sql database, also displays a radio button next to each image and users are able to check that radio button so the particular image becomes the main photo. I am trying to succeed that by inserting a new value in the database field 'main' but I am stuck
. How do I get the values from the radio buttons to insert them in the database?This is what I have done so far...
Code: Select all
if (isset($_POST['submit'])) {
............here is where i am stuck.....
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Manage / Add your photos</title>
</head>
<body>
<?php include "/usr/home/mysite.com/htdocs/inc/dbconn.php";
$codeno=$_GET["estateid"];
echo '<p><left><a href="edit.php">Back to Estate List</a></left></p>';
$sql = "select brief from estateinfo where codeno = '$codeno'";
$result=mysql_query($sql);
if (!$result){
die ("<p>query error"."</P>");
}
$row=mysql_fetch_array($result);
$brief = $row['brief'];
echo '<center>';
echo "<h1>PHOTO MANAGER - ESTATE ID : $codeno</h1>";
echo '</br>';
echo "<table width=\"750\" align=\"center\">";
echo '<tr>';
echo "<th>BRIEF : ".ucfirst($brief).'</th>';
echo '</tr>';
echo '<tr>';
echo '<th> </th>';
echo '</tr>';
echo '<tr>';
echo "<td align=\"center\">";
echo "<form enctype=\"multipart/form-data\" action=\"uploader.php?id=$codeno\" method=\"POST\">";
$maxsize = ini_get('upload_max_filesize');
if (!is_numeric($maxsize))
{
if (strpos($maxsize, 'M') !== false)
$maxsize = intval($maxsize)*1024*1024;
elseif (strpos($maxsize, 'K') !== false)
$maxsize = intval($maxsize)*1024;
elseif (strpos($maxsize, 'G') !== false)
$maxsize = intval($maxsize)*1024*1024*1024;
}
echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . $maxsize.'\" />';
echo 'INSERT A NEW IMAGE : ';
echo "<input name=\"uploadedfile\" type=\"file\" class=\"Button\" />";
echo "<input type=\"submit\" class=\"Button\" value=\"Upload File\" />";
echo "<input type=\"hidden\" name=\"codeno\" value=\"$codeno\" />";
echo '</form>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo '</table>';
echo '</center>';
$q = "select id, filename, main from attachment where attachmentid = '$codeno'";
$res=mysql_query($q);
if (!$res){
echo "<p>Error while displaying an image</p>";
}?>
<form action="<?php echo $PHP_SELF;?>" method="get"/>
<?php
echo "<table align=\"center\" width=\"700\" cellpadding=\"3\">
<tr>
<th width=\"250\" align=\"center\">IMAGE</th>
<th align=\"center\">MAIN PHOTO</th>
<th width\"175\" align=\"left\">NAME</th>
<th width\"87.5\" align=\"left\">ACTION</th>
</tr>
<tr>
<td colspan=\"4\"></td>
</tr>";
echo '<center>';
while ($row=mysql_fetch_array($res)){
$id=$row["id"];
$filename=$row['filename'];
[color=#BF0000]$main[/color]=$row['main'];
if (empty($main)){
$status="";
}
else {$status="checked";}
echo ("<tr>
<td width=\"250\" align=\"center\" border=\"1\"><a href=\"gallery.php?attachmentid=$id\"><img src=\"gallerysm.php?attachmentid=$id\" class=\"photo-border-green\"/></a></td>
");
echo "<td align=\"center\">";
echo "<input type=\"checkbox\" name=\"check\" value=\"$id\" $status/>$id</td>";
echo ("<td width\"175\">$filename</td>
<td width\"87.5\"><a href=\"deleteimage.php?photoid=".urlencode("$id,$codeno,$filename")."\">Delete</td>
</tr>");
}
echo '<tr>';
echo "<td colspan=\"4\" align=\"right\">";
echo "<input type=\"button\" name=\"submit\" value=\"Apply Changes\"></td>";
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</center>';
?>
</body>
</html>