Jump to content

[SOLVED] Need help with echo error code


nosher

Recommended Posts

Dear All  ;D

 

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

 

Link to comment
https://forums.phpfreaks.com/topic/100638-solved-need-help-with-echo-error-code/
Share on other sites

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)

Thank you so Much ;D

 

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 :o

 

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.

 

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.