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
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();
}

?>

Link to comment
Share on other sites

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>";

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.