guys,
after a couple of hit and trials i'm now able to insert the photo filename into the photo field in the database....using this code...
<?php
//This is the directory where images will be saved
$target = "C://www//html//xxx//xxx/photos/";
$target = $target . basename( $_FILES['photo']['file']);
include('dbconn.php');
if( !empty($_POST) )
{
$sql = sprintf("INSERT INTO attorney_profiles(firstname,lastname,email,biography,username,password,areas_business,areas_litigation,areas_land_use,areas_real_estate,areas_senior_law,areas_estates,areas_PI,areas_employment,areas_family,areas_criminal,areas_LLT,photo) VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[biography]','$_POST[username]','$_POST[password]','{$_POST[areas_business][0]}','{$_POST[areas_litigation][0]}','{$_POST[areas_land_use][0]}','{$_POST[areas_real_estate][0]}','{$_POST[areas_senior_law][0]}','{$_POST[areas_estates][0]}','{$_POST[areas_PI][0]}','{$_POST[areas_employment][0]}','{$_POST[areas_family][0]}','{$_POST[areas_criminal][0]}','{$_POST[areas_LLT][0]}','{$_FILES['photo']['name']}')");
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{
header("Location: index.php");
echo "1 record added";
}
if(!$sql)
{
echo "No data.";
}
}
The above code inserts the filename to the database, but doesn't move the files to the photo folder i have and also it doesn't display the photo.....i use the following code for displaying the photos and other data...
<?php
include('dbconn.php');
$sql = "SELECT * FROM attorney_profiles";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
// how many rows to show per page
$rowsPerPage = 5;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$result = mysql_query("SELECT * FROM attorney_profiles LIMIT $offset,$rowsPerPage");
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$attorney_id=mysql_result($result,$i,"attorney_id");
$firstname=mysql_result($result,$i,"firstname");
$lastname=mysql_result($result,$i,"lastname");
$email=mysql_result($result,$i,"email");
$biography=mysql_result($result,$i,"biography");
$username=mysql_result($result,$i,"username");
$password=mysql_result($result,$i,"password");
$areas_business=mysql_result($result,$i,"areas_business");
$areas_litigation=mysql_result($result,$i,"areas_litigation");
$areas_land_use=mysql_result($result,$i,"areas_land_use");
$areas_real_estate=mysql_result($result,$i,"areas_real_estate");
$areas_senior_law=mysql_result($result,$i,"areas_senior_law");
$areas_estates=mysql_result($result,$i,"areas_estates");
$areas_PI=mysql_result($result,$i,"areas_PI");
$areas_employment=mysql_result($result,$i,"areas_employment");
$areas_family=mysql_result($result,$i,"areas_family");
$areas_criminal=mysql_result($result,$i,"areas_criminal");
$areas_LLT=mysql_result($result,$i,"areas_LLT");
$photo=mysql_result($result,$i,"photo");
if($areas_business=="on") {
$areas_business="Business"; }
if($areas_litigation=="on") {
$areas_litigation="Litigation"; }
if($areas_land_use=="on") {
$areas_land_use="Land Use"; }
if($areas_real_estate=="on") {
$areas_real_estate="Real Estate"; }
if($areas_senior_law=="on") {
$areas_senior_law="Senior Law"; }
if($areas_estates=="on") {
$areas_estates="Estates"; }
if($areas_PI=="on") {
$areas_PI="P.I."; }
if($areas_employment=="on") {
$areas_employment="Employment"; }
if($areas_family=="on") {
$areas_family="Family"; }
if($areas_criminal=="on") {
$areas_criminal="Criminal"; }
if($areas_LLT=="on") {
$areas_LLT="LL/T"; }
echo "<b>Attorney Name:</b> <a href=\"profile_edit_neel.php?attorney_id=$attorney_id\">$firstname $lastname</a>"; echo "<br>";
echo "<b>E-Mail:</b> $email"; echo "<br>";
echo "<b>Biography:</b> $biography"; echo "<br>";
echo "<b>Practice Areas:</b> "; echo "$areas_business"; echo " ";
echo "$areas_litigation"; echo " ";
echo "$areas_land_use"; echo " ";
echo "$areas_real_estate"; echo " ";
echo "$areas_senior_law"; echo " ";
echo "$areas_estates"; echo " ";
echo "$areas_PI"; echo " ";
echo "$areas_employment"; echo " ";
echo "$areas_family"; echo " ";
echo "$areas_criminal"; echo " ";
echo "$areas_LLT";
echo "<br>";
echo "<img src=C://www//html//xxx//xxx//photos/" . $photo . ">";
echo "<br>"; echo "<br>";
$i++;
}