Jump to content

Classified script help


phpnewbiy

Recommended Posts

I have a classified script that doesn't post all the information it needs to.  It posts all but the 'information'.  Not sure why, the title, price, location, picture, all post fine, just the information doesn't.

 

I looked in my database, and it doesn't post the information in there either - so my guess is it doesn't get to the database to be pull to the ad itself.

 

Here's the code:

 

<?php
class CAd
{
//Constructor for CAd. Gives this class access to MySQL.
function CAd(&$sql)
{
	$this->sql = $sql;
}

//Load all of the ad information from the db into class member variables
function LoadAd($id)
{
	//Query for the info
	$this->sql->query("SELECT * FROM ads where ID = '%s'", $id);
	$ad = $this->sql->getrowset();

	//"Extract" it into member variables
	class_extract($ad[0], $this);

	//Throw the ad's category's name into $this->category_name
	$this->sql->query("SELECT name FROM categories WHERE ID = '%s'", $this->category);
	$this->category_name = $this->sql->getresult();
}

function LoadOwner()
{
	//Throw the ad's owner's name into $this->owner_name
	$this->sql->query("SELECT * FROM users WHERE ID = '%s'", $this->owner);
	$this->owner_data = $this->sql->getrow();
}

//Create a new ad in the MySQL table, and upload the given image. $image is a reference to the image in $_FILES
function NewAd($owner_id, $title, $image, $category, $price, $info, $location)
{
	$this->sql->query("SELECT * FROM ads WHERE title = '%s'", $title);

	//Die if there's another ad with the same name
	if($this->sql->num_rows != 0)
	{
		echo "<script>alert('Sorry. Another ad exists with this title. Please choose another title.');</script>";
		return FALSE;
	}
	//If $image is an array (i.e. not a link to an offsite hosted image)
	if(is_array($image))
	{
		move_uploaded_file($image['tmp_name'], AD_IMAGES.addslashes($title));
		$image_url = SERVER_ROOT.AD_IMAGES.addslashes($title);
	}
	//If $image is the URL to an image hosted elsewhere.
	else
		$image_url = $image;

	//Query to add this information into the db
	$this->sql->query("INSERT INTO ads SET owner = '%s', title = '%s', image = '%s', category = '%s', price = '%s', info = '%s', date = '%s', location = '%s'", $owner_id, $title, $image_url, $category, $price, $info, time(), $location);

	return TRUE;
}

//Delete an ad from the MySQL db, and delete the image that accompanies it.
function DeleteAd()
{
	//If image is hosted on this server...
	if(!!strstr($this->image, SERVER_ROOT.AD_IMAGES.addslashes($this->title)))
		unlink(AD_IMAGES.addslashes($this->title)); //Delete it...

	//Delete the ad from MySQL
	$this->sql->query("DELETE FROM ads WHERE ID = '%s'", $this->ID);

	return TRUE;
}

//Change an ad's title, price, and info in MySQL
function EditAd($title, $price, $info, $category)
{
	$this->sql->query("UPDATE ads SET title = '%s', price = '%s', info = '%s', category = '%s' WHERE ID = '%s'", $title, $price, $info, $category, $this->ID);

	return TRUE;
}

//Return the HTML code to output the ad on the category page. (Small sized)
function OutputAd()
{
	$out = '<table width="98%" align="center" border="0">';
	$out .= '<tr><td bgcolor="#AFD5FC"><b>Category:</b> <a href="index.php?cat='.$this->category.'">'.$this->category_name.'</a> - <b>Post Date:</b> '.date(DATE_FORMAT, $this->date).'</td></tr>';
	$out .= '<tr><td bgcolor="#D6D6D6">';
	$out .= '<table><tr valign="center"><td width="10%" bgcolor="#D6D6D6"><img width="75" height="56" src="'.$this->image.'"></td><td width="80%"><a href="ad_details.php?ad='.$this->ID.'">'.strtoupper($this->title).'</a><p><b>AD #:</b>'.$this->ID.'</td><td width="10%"><font color="red">$'.number_format($this->price, 2).'</font><br>'.$this->location.'</td></tr></table></td></tr></table>';

	return $out;
}

//Return the HTML code to output the ad on the ad page. (Full sized)
function OutputFullAd()
{
	//Increase ad views by 1. (For "Hottest Ads")
	$this->sql->query("UPDATE ads SET views = views+1 WHERE ID = '%s'", $this->ID);

	$out = '<table width="100%"><tr><td class="#AFDFC">';
	$out .= '<b>Ad #</b>'.$this->ID.' - <b>Posted Date: </b>'.date(DATE_FORMAT, $this->date);
	$out .= '</td></tr><tr><td class="#D6D6D6">';
	$out .= '<center><img src="'.$this->image.'" height=300 width=420><br><font color="red"><b>$'.number_format($this->price, 2).'</b></font><p><font size="+1">'.strtoupper($this->title).'</font><p></center>'.$this->info.'<p>';
	if($this->phone != '')
		$out .= '<b>Contact Info: </b>'.$this->phone.'<br>';
	$out .= '<b>Location: </b>'.$this->location.'<br>';
	$out .= '<b>Posted By: </b>'.$this->owner_data['name'].'<br>';
	$out .= '<a href="contact.php?i='.$this->ID.'">E-mail Seller</a><br>';
	$out .= '</td></tr></table>';

	return $out;
}

//Return the HTML code for creating a new ad
function OutputNewAd()
{
	$out = '<br><br><br><table width="98%" align="center"><tr><td bgcolor="#D6D6D6"><h3><center>Post a New Ad</center></h3></td></tr><form action="'.PHP_SELF.'" method=POST enctype="multipart/form-data">';


	$out .= '<tr><td bgcolor="#AFD5FC" align="center"><b>Category</b>:     <select name=category>';

	//Grab an array of bottom level categories [0] => ID; [1] => name;
	$cat = new CCategory($this->sql);
	$cats = $cat->OutputCategoryArray();

	//Add each one to a <select>
	foreach($cats as $category)
		$out .= '<option value="'.$category[0].'">'.$category[1].'</option>';
	$out .= '</select></td></tr><tr><td bgcolor="#AFD5FC"></td></tr>';
	$out .= '<tr><td bgcolor="#D6D6D6" align="center"><b>Title</b>:            <input type=text name=title></td></tr><tr><td bgcolor="#D6D6D6"></td></tr>';
	$out .= '<tr><td bgcolor="#AFD5FC" align="center"><b>Price</b>:           <input type=text name=price></td></tr><tr><td bgcolor="#AFD5FC"></td></tr>';
	$out .= '<tr><td bgcolor="#D6D6D6" align="center"><b>Location</b>:      <input type=text name=location></td></tr>';
	$out .= '<tr><td bgcolor="#AFD5FC" align="center"><b>Information</b>:             <br><textarea name=info cols=50 rows=10></textarea></td></tr><tr><td bgcolor="#AFD5FC"></td></tr>';
	$out .= '<tr><td bgcolor="#D6D6D6" align="center"><b>Image Upload</b>: <input type=hidden name="MAX_FILE_SIZE" value="10000000"><input type=file name="image_f"></td></tr><tr><td bgcolor="#D6D6D6"></td></tr>';
	$out .= '<tr><td bgcolor="#AFD5FC" align="center"><input type=submit name=NewAd value="Create Ad"></form></td></tr></table>';

	return $out;
}

function OutputEditAd()
{
	$out = '<form action="'.$_SERVER['REQUEST_URI'].'" method=POST>';
	$out .= '<b>Title</b>: <input type=text name=title value="'.$this->title.'"><br>';
	$out .= '<b>Category</b>: <select name=category>';

	//Grab an array of bottom level categories [0] => ID; [1] => name;
	$cat = new CCategory($this->sql);
	$cats = $cat->OutputCategoryArray();

	//Add each one to a <select>, making it selected if it's the current category
	foreach($cats as $category)
		$out .= '<option value="'.$category[0].'"'.(($this->category == $category[0]) ? ' selected' : '').'>'.$category[1].'</option>';
		$out .= '<option value="'.$category[0].'"'.(($this->category == $category[test]) ? ' selected' : '').'>'.$category[2].'</option>';
		$out .= '<option value="'.$category[0].'"'.(($this->category == $category[1212]) ? ' selected' : '').'>'.$category[3].'</option>';
	$out .= '</select><br>';
	$out .= '<b>Price</b>: <input type=text name=price value="'.$this->price.'"><br>';
	$out .= '<b>Location</b>: <input type=text name=location value="'.$this->location.'"><br>';
	$out .= '<b>Information</b>: <br><textarea name=info cols=50 rows=10>'.$this->info.'</textarea>';
	$out .= '<p><a href="ad_details.php?ad='.$this->ID.'">View Ad</a><hr>';
	$out .= '<input type=submit name=EditAd value="Edit Ad"> <input type="submit" name="DeleteAd" value="Delete Ad"></form>';

	return $out;
}
}
?>

 

I couldn't find anything wrong with it... can anyone help?

 

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.