Jump to content

Php Classified Ad Script


iRush

Recommended Posts

Here i have this script with php and html posting out to the same php page but it seems that i get an error when i run this code:

 

 

This is the error im getting:

 

Notice: Undefined index: weeks in C:\xampp\htdocs\results.php on line 61

 

Your ad is 1 words.

 

Your ad will run for week(s).

 

Your cost is $0.00 ($4 per week).

 

Here is the code

 

<?php

function new_ad( $ad, $weeks ) {

$count = str_word_count( $ad );
$price = 4;
$weeks = $weeks

if( $count > 25 ) {
	$adcount = $count - 25;
	$adprice = $adcount * .10;
	$price = $price + $adprice;

}

$totalprice = $price * $weeks;

echo "<html><head><title>Ad Space</title></head>";

echo "<body><br>Your ad is $count words.</br>";

echo "<br>Your ad will run for $weeks week(s).</br>";

echo "<br>Your cost is $" . number_format( $totalprice, 2 ) . " ($". $price . " per week).</br>";

echo "<br>Your Classified Ad:</br>";

echo "<textarea>$ad</textarea></body></html>";

}



function create_ad() {

echo "<html><head><title>Ad Space</title></head>";

echo "<body><br><b>Classified Ads are $4.00 for 25 words and</br>";
echo "10¢ for each additional word</b></p><br />";

echo "<select name= \"weeks\">";
echo "<option value=\"1\">1 Week</option>";
echo "<option value=\"2\">2 Weeks</option>";
echo "<option value=\"3\">3 Weeks</option>";
echo "</select><br /><br />";



echo "Type Your Ad Here:<br /><br />";

echo '<form method="post" action="results2.php">';

echo '<textarea name="ad" rows= "10" cols="50"></textarea><br /><br />';

echo '<br><input type="submit" value="Create Ad" /></br>';

echo "</form></body></html>";
}


if( isset( $_POST['ad'] ) && ! is_null( $_POST['ad'] ) ) {
new_ad( $_POST['ad'], $_POST['weeks'] );
} else {
create_ad();
}

?>

Link to comment
https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/
Share on other sites

I moved it around and it still comes up with an error..

 

function create_ad() {



echo "Type Your Ad Here:<br /><br />";
    echo '<form method="post" action="results2.php">';
    echo '<textarea name="ad" rows= "10" cols="50"></textarea><br /><br />';
    echo '<br><input type="submit" value="Create Ad" /></br>';
    echo "<html><head><title>Ad Space</title></head>";

	echo "<body><br><b>Classified Ads are $4.00 for 25 words and</br>";
	echo "10¢ for each additional word</b></p><br />";

	echo "<select name= \"weeks\">";
	echo "<option value=\"1\">1 Week</option>";
	echo "<option value=\"2\">2 Weeks</option>";
	echo "<option value=\"3\">3 Weeks</option>";
echo "</select><br /><br />";

echo "</form></body></html>";
}


if( isset( $_POST['ad'] ) && ! is_null( $_POST['ad'] ) ) {
new_ad( $_POST['ad'], $_POST['weeks'] );
} else {
create_ad();
}

?>

nevermind i got it fixed now..but im trying to incorportate background color how can i do this in this part of the code :

 

echo "<body bgcolor = "4682B4"><br><b><center><H1>Classified Ads</H1></center</b></br>";
       echo "<br>Your ad is $count words.</br>";
        echo "<br>Your ad will run for $weeks week(s).</br>";
    echo "<br>Your cost is $" . number_format( $totalprice, 2 ) . " ($". $price . " per week).</br>";
       echo "<br>Your Classified Ad:</br>";
        echo "<textarea>$ad</textarea></body></html>";

if you want to set a background image dynamically (IE without a page reload) you will have to use Javascript.  With PHP I suppose you could pass a hidden field or something and use that field as a flag to decide whether or not to set a background image.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.