nosher Posted April 11, 2008 Share Posted April 11, 2008 Dear All I am a complete beginner with PHP and would love some help with this issue if possible? We had a calculator made for us by someone who has now left the country, so no way of contacting him. Basically if nothing is entered into the filed it displays the error: **You did not enter a Property Price. Please go back and try again** If any letter is entered into the filed it makes a calculation, so what I would really like to be able to do is anything that is inputted into the filed other then numbers is shown the error code. Is this at all possible? Am I missing something stupid here ? :'( This is the error code below <?php $error="The following errors occurred while processing your Quotation.<ul>"; if($electric==""){$errors=1; $error.="<li>You did not enter a Property Price. Please go back and try again.<BR><BR>";} if($errors==1) echo $error; Any help with this issue would be greatly appreciated Nosher Link to comment https://forums.phpfreaks.com/topic/100638-solved-need-help-with-echo-error-code/ Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 $errors=1; if($electric=="") {$errors=1; $error="<li>You did not enter a Property Price. Please go back and try again.<BR><BR>"; } if($errors==1) { echo $error; } might be helping you Link to comment https://forums.phpfreaks.com/topic/100638-solved-need-help-with-echo-error-code/#findComment-514679 Share on other sites More sharing options...
friedemann_bach Posted April 11, 2008 Share Posted April 11, 2008 If you want to display the entered value within the error message, try this: $error_code = 0; $error="The following errors occurred while processing your Quotation.<ul>"; if($electric=="") { $error_code=1; $error.="<li>You did not enter a Property Price.</li>"; } elseif (!is_numeric($electric)) { $error_code=2; $error.="<li>You did not enter a numeric value ('$electric').</li>"; } if($error_code) echo $error."</ul>\n"."Please go back and try again.<br>"; (don't forget to close the <ul> and <li> tags) Link to comment https://forums.phpfreaks.com/topic/100638-solved-need-help-with-echo-error-code/#findComment-514682 Share on other sites More sharing options...
nosher Posted April 11, 2008 Author Share Posted April 11, 2008 Thank you so Much The following errors occurred while processing your Quotation. • You did not enter a numeric value ('test'). Please go back and try again. Now the error code is being displayed lovely, but a calculation is still being displayed under the error message is there anyway to stop the calculation being displayed Just asking if this cant be done that’s fine Many Thanks Nosher Link to comment https://forums.phpfreaks.com/topic/100638-solved-need-help-with-echo-error-code/#findComment-514698 Share on other sites More sharing options...
friedemann_bach Posted April 11, 2008 Share Posted April 11, 2008 The shortest way to modify your script would be like this: if($error_code) { echo $error."</ul>\n"."Please go back and try again.<br>"; // any page footer exit; } This terminates the script after any form validation error. If you have a footer on your page, you might want to echo it before exit;-ing. Link to comment https://forums.phpfreaks.com/topic/100638-solved-need-help-with-echo-error-code/#findComment-514723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.