Jump to content

help add a image upload field in form


$php_mysql$

Recommended Posts

could someone be kind to help add a image upload field in the form? below my source

 

///////////////////////////////////////auto delete ads

$time_count = 7*24*60*60; // count the 7 days Ads will be deleted 

$match_time = time()-$time_count; 


$query = "SELECT id FROM classifieds WHERE time<'".$match_time."' ORDER BY RAND() LIMIT 1";  
  $result = mysql_query($query); 

  while($ad_id = mysql_fetch_array($result)) 

$delete =$ad_id[0]; 

mysql_query("DELETE FROM classifieds WHERE id='$delete'"); 


////////////////////////////////////////MAIN PAGE 
if($action=="main") 
{ 
$result=mysql_query("select * from classifieds where cat='career_jobs'"); 
$career_jobs = mysql_num_rows($result); 

$result=mysql_query("select * from classifieds where cat='realestate'"); 
$realestate = mysql_num_rows($result); 

$result=mysql_query("select * from classifieds where cat='vehicles'"); 
$vehicles = mysql_num_rows($result); 

$result=mysql_query("select * from classifieds where cat='buy_sell'"); 
$buy_sell = mysql_num_rows($result); 

$result=mysql_query("select * from classifieds where cat='services'"); 
$services = mysql_num_rows($result); 

$result=mysql_query("select * from classifieds where cat='pets'"); 
$pets = mysql_num_rows($result); 

$result=mysql_query("select * from classifieds where cat='events_announcements'"); 
$events_announcements = mysql_num_rows($result); 


echo "<center><br/><big>Wapvibes Classifieds</big><br/><br/></center>"; 
echo "<big><u><b>Classifieds</b></u></p>"; 

echo "<p>»<a href=\"classifieds.php?action=show_ads&sid=$sid&cat=career_jobs\">Career/Jobs</a>($career_jobs)<br/>"; 

echo "»<a href=\"classifieds.php?action=show_ads&sid=$sid&cat=realestate\">Real Estate</a>($realestate)<br/>"; 

echo "»<a title=\"Enter\" href=\"classifieds.php?action=show_ads&sid=$sid&cat=vehicles\">Vehicles</a>($vehicles)<br/>";

echo "»<a title=\"Enter\" href=\"classifieds.php?action=show_ads&sid=$sid&cat=buy_sell\">Buy/Sell</a>($buy_sell)<br/>"; 

echo "»<a title=\"Enter\" href=\"classifieds.php?action=show_ads&sid=$sid&cat=services\">Services</a>($services)<br/>"; 

echo "»<a title=\"Enter\" href=\"classifieds.php?action=show_ads&sid=$sid&cat=pets\">Pets</a>($pets)<br/>"; 

echo "»<a title=\"Enter\" href=\"classifieds.php?action=show_ads&sid=$sid&cat=events_announcements\">Events/Announcements</a>($events_announcements)<br/>"; 

echo "<br/><a title=\"Enter\" href=\"classifieds.php?action=post&sid=$sid\">Post Your Ads</a>"; 
   
} 
//////////////////////////////////////////////////
else if($action=="show_ads") 
{ 
echo "<h3 align=\"center\">Classifieds</h3>\n";
$cat=$_GET["cat"]; 
$page=$_GET["page"]; 
if($page=="") 
    { 
        $page=1; 
    } 
$max_results = 7; 
$from = (($page * $max_results) - $max_results); 
$total_results = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM classifieds WHERE cat='$cat'")); 
if($total_results[0]<1) 
{ 
    echo "<p>Sorry No Ads to show yet!!!</p><br/>"; 
}else{ 
$total_pages = ceil($total_results[0] / $max_results); 
echo "$page Of $total_pages<br/><br/>"; 

$sql = mysql_query("SELECT * FROM classifieds WHERE cat='$cat'  ORDER BY id desc LIMIT $from, $max_results"); 
while($row = mysql_fetch_array($sql)){ 
$name = $row['uid']; 
$name2 = $row['itemname']; 
$key = $row['id']; 

echo "<a href=\"classifieds.php?action=details&sid=$sid&cat=$cat&key=$key\">$name2</a><br/>" ; 


} 

if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"classifieds.php?action=show_ads&sid=$sid&page=$next&cat=$cat\">Next</a><br />"; 
} 
if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"classifieds.php?action=show_ads&sid=$sid&page=$prev&cat=$cat\">Prev</a><br/>"; 
} 
$i = 1; $i <= $total_pages; $i++ ; 
} 
echo "<p align=\"center\">";
echo "<h3 align=\"center\"><a href=\"index.php?action=main&sid=$sid\">Home</a></h3>\n";

echo "</p>";

echo "</body>";
} 
///////////////////////////////////////////////////
else if($action=="details") 
{

echo "<h3 align=\"center\">Ad Details</h3>\n"; 
$key=$_GET["key"]; 
$cat=$_GET["cat"]; 
$sql = mysql_fetch_array(mysql_query("SELECT * FROM classifieds WHERE id='$key'")); 
$usid=$sql["uid"]; 
$who=$usid; 
$name=getnick_uid($usid); 
$ad=$sql["ad"]; 
$price=$sql["price"]; 
$contact=$sql["contact"]; 
$location=$sql["location"]; 
$posted=$sql["time"]; 
$wapvibes_ad_time = date("d/m/Y h:i:s A", $posted); 
echo "<br/>"; 
echo "<p>"; 
echo "<big><b>*Seller</b><br/> <a href=\"index.php?action=viewuser&sid=$sid&who=$usid\">$name</a><br/><br/>"; 
echo "<b>*Description*</b><br/> $ad<br/><br/>"; 
echo "<b>*Price*</b><br/> $price<br/>"; 
echo "<b>*Contact*</b><br/> $contact<br/><br/>"; 
echo "<b>*Location*</b><br/> $location<br/>"; 
echo "<b>*Posted on</b><br/> $wapvibes_ad_time<br/>"; 


echo "<br/>"; 
echo "<a href=\"inbox.php?action=sendpm&who=$usid&sid=$sid\">[send $name A PM]</a><br/><br/>"; 
if (isowner($uid)){ 
echo "<p><a href=\"classifieds.php?action=delete44&who=$who&sid=$sid\">Delete This Ad</a></p>"; 
} 

echo "<a href=\"classifieds.php?action=show_ads&sid=$sid&cat=$cat\">Back to Category</a>"; 
echo "<p align=\"center\">";
echo "<h3 align=\"center\"><a href=\"index.php?action=main&sid=$sid\">Home</a></h3>\n";

echo "</p>";

echo "</body>"; 

} 
////////////////////////////////////////////////////
else if($action=="post") 
{ 
echo "<h3 align=\"center\">Post An Advertisement</h3>\n";
echo "<form action=\"classifieds.php?action=post2&sid=$sid\" method=\"post\">"; 
echo "<p>"; 
echo "What is the Name of Your Item<br/>"; 
echo "<br/>"; 
echo "<textarea class=\"inputText\" name=\"name\"></textarea><br/>"; 
echo "Describe Your Item<br/>"; 
echo "<br/>"; 
echo "<textarea class=\"inputText\" name=\"ad\"></textarea><br/>"; 
echo "Choose Category"; 
echo "<br/><select name=\"listing\">"; 
echo "<option value=\"select\">select</option>"; 
echo "<option value=\"career_jobs\">Career/Jobs</option>"; 
echo "<option value=\"realestate\">Real Estate</option>"; 
echo "<option value=\"vehicles\">Vehicles</option>"; 
echo "<option value=\"buy_sell\">Buy/Sell</option>"; 
echo "<option value=\"services\">Services</option>"; 
echo "<option value=\"pets\">Pets</option>";
echo "<option value=\"events_announcements\">Events/Announcements</option>";  
echo "</select><br/>"; 
echo "what is Your Price<br/>"; 
echo "<textarea class=\"inputText\" name=\"price\"></textarea><br/>"; 
echo "How can You be contacted:"; 
echo "<br/><textarea class=\"inputText\" name=\"contact\"></textarea><br/>"; 
echo "Where Are You Located"; 
echo "<br/><textarea class=\"inputText\" name=\"location\"></textarea><br/>"; 
$ui=getuid_sid($sid); 
echo "<input type=\"hidden\" name=\"ui\" value=\"$ui\"/>"; 
echo "<br/><input name=\"submit\" value=\"Submit Your Ad\" type=\"submit\"/><br/></p></form><p>"; 

echo "<p align=\"center\">";
echo "<h3 align=\"center\"><a href=\"index.php?action=main&sid=$sid\">Home</a></h3>\n";

echo "</p>";

echo "</body>";

} 
///////////////////////////////////////////////////////
else if($action=="delete44") 
{  
echo "<h3 align=\"center\">Ad Deleted</h3>\n";
echo "<p>"; 
echo "<big>Ad was successfully Deleted From the system</p>"; 

mysql_query("DELETE FROM classifieds WHERE uid='".$who."'"); 

echo "<p align=\"center\">";
echo "<h3 align=\"center\"><a href=\"index.php?action=main&sid=$sid\">Home</a></h3>\n";

echo "</p>";

echo "</body>";

} 
/////////////////////////////////////////////////////////////////
else if($action=="post2") 
{ 

$name=$_POST["name"]; 
$ad=$_POST["ad"]; 
$price=$_POST["price"]; 
$contact=$_POST["contact"]; 
$cat=$_POST["listing"]; 
$location=$_POST["location"]; 
$ui=$_POST["ui"];

if(empty($name) || empty($ad) || empty($price) || empty($contact) || empty($location)) {
echo "<h3 align=\"center\">Error!</h3>\n";
echo "<img src=\"images/notok.gif\" alt=\"x\"/><br/>";
echo "All fields are must<br/>";
die ("SmS Not Sent! <br/><br/><a href=\"classifieds.php?action=post&sid=$sid\">Return Back</a><br/> <h3 align=\"center\"><a href=\"index.php?action=main&sid=$sid\">Home</a></h3>\n"); 
}

$result=mysql_query("select * from classifieds where uid='$ui' and cat='$cat'"); 
$number_of_rows = mysql_num_rows($result); 
if ($number_of_rows>0){ 
echo "<h3 align=\"center\">Error!</h3>\n";
$problems="1"; 
echo "<img src=\"images/notok.gif\" alt=\"x\"/> You already have a Ad in our system Please wait until your Ad expire in 7 days! <br/>"; 
} 
if ($problems==""){
echo "<h3 align=\"center\">Advertisement Added Successfully</h3>\n"; 
$sql = "INSERT INTO classifieds (uid, cat, ad, itemname, time, price,contact,location) VALUES ('$ui','$cat','$ad','$name','".time()."','$price','$contact','$location')"; 
$result = mysql_query($sql); 
echo "<img src=\"images/ok.gif\" alt=\"O\"/> Your Advertisement was Successfully Posted it will be in the Classified for 7 days, After that it will expire<br/><br/>"; 
echo "<br/><a href=\"classifieds.php?action=main&sid=$sid\">classified Main</a><br/>"; 
} 

echo "<p align=\"center\">";
echo "<h3 align=\"center\"><a href=\"index.php?action=main&sid=$sid\">Home</a></h3>\n";

echo "</p>";

echo "</body>";

 

and the sql

 

CREATE TABLE IF NOT EXISTS `classifieds` (

  `id` mediumint(4) NOT NULL auto_increment,

  `uid` varchar(20) NOT NULL default '',

  `cat` varchar(100) NOT NULL default '',

  `ad` text NOT NULL,

  `price` text NOT NULL,

`time` int(100) NOT NULL,

`contact` text NOT NULL,

`itemname` text NOT NULL,

`location` text NOT NULL,

  PRIMARY KEY  (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=207 ;

 

everything works fine just need to add a image upload along with form and also that it gets deleted from directory when posts auto deletes in 7 dyas.

 

thanks  ;)

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.