iRush Posted October 4, 2011 Share Posted October 4, 2011 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/ Share on other sites More sharing options...
iRush Posted October 4, 2011 Author Share Posted October 4, 2011 sorry Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275818 Share on other sites More sharing options...
mikesta707 Posted October 4, 2011 Share Posted October 4, 2011 The select form named "weeks" is outside of the form tags and thus are not included in the $_POST data that the form submits also, please use code tags when posting code, and dont double post Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275821 Share on other sites More sharing options...
iRush Posted October 4, 2011 Author Share Posted October 4, 2011 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275824 Share on other sites More sharing options...
mikesta707 Posted October 5, 2011 Share Posted October 5, 2011 is it the same error? Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275834 Share on other sites More sharing options...
iRush Posted October 5, 2011 Author Share Posted October 5, 2011 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275838 Share on other sites More sharing options...
mikesta707 Posted October 5, 2011 Share Posted October 5, 2011 you could use the style attribute <body style="background-color:#4682b4"> Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275839 Share on other sites More sharing options...
iRush Posted October 5, 2011 Author Share Posted October 5, 2011 Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\results2.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275842 Share on other sites More sharing options...
iRush Posted October 5, 2011 Author Share Posted October 5, 2011 how hard would it be to have an image come up instead Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275843 Share on other sites More sharing options...
mikesta707 Posted October 5, 2011 Share Posted October 5, 2011 um can you post the line that creates that error? I'm not sure what what i posted has to do with PHP as its just html. and what do you mean by "Have an image come up instead"? Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275845 Share on other sites More sharing options...
iRush Posted October 5, 2011 Author Share Posted October 5, 2011 like when i click the create ad button an image comes up for the background..and i fixed the color by the way Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275847 Share on other sites More sharing options...
mikesta707 Posted October 5, 2011 Share Posted October 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275849 Share on other sites More sharing options...
iRush Posted October 5, 2011 Author Share Posted October 5, 2011 last thing that i have to do is create a link on the second page to go back to the previous page to start over Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275856 Share on other sites More sharing options...
the182guy Posted October 5, 2011 Share Posted October 5, 2011 To use a background image just use <body style="background-image:url(/path/to/image.jpg);background-repeat:no-repeat;"> Quote Link to comment https://forums.phpfreaks.com/topic/248446-php-classified-ad-script/#findComment-1275915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.