Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating the Value in a textbox against MYSQL Table, then returning 4

Status
Not open for further replies.

IanNav

Programmer
Feb 26, 2001
79
Hi,

I have a bit of an Odd one... And i think its quite hard to explain.

I'll try and explain anyway.

I am trying to write a simple order entry system.

On my main order entry screen i have the following input fields

- Media Code
- Customer ID
- Customer Payer ID (which can be different)
- Order Source (ie Telephone, Web, Mail-order, Fax)


For each of these i would like a "check" or "validate" hyperlink next to the text box (or submit button, but i want to limit the amount of nested submits for simplicity).

When the user click the "check" link, i would ideally like it to call a PHP function that checks the value is valid. (I’ve written the functions, see below a example one for the customer ID)

check_customer($custid)
{
include ("../includes/connect_db.php");

$sqlstr = "SELECT * FROM customer WHERE id='$custid'";
$result = mysql_query($sqlstr);
$data = mysql_fetch_array($result);
$num = mysql_numrows($result);
mysql_close();

if($num =1)
{
return true;
}
else
{
return false;
}
}


Then based on whether id returns true or false i would like to

true : Change the text box with the value inside to a label (so it is not editable).

false : alert("Customer not Valid), then it blanks the box and set focus again.

The main problem i am having is passing what is in the textbox with using the submit button and passing it to my function for evaluation.

I also then need help in changing the pages appearance based on the true or false returned.

I realise i haven't explained this very well - apologies.

Any help would be appreciated.

Since i have 3 or 4 things to check on this 1 page as well as the submit to continue to the next step i think nesting multiple submits would be too messy. There must be an easier way!

Cheers

Ian
 
this sounds to me like you need some ajax to do some real-time validation,I would start there.

If not I would have 1 submit at the bottom that just checks all the fields at the end.
 
Thanks for the quick response guys, but i really wanted to do this using html, js & php any other ideas apart from the submit all then done...?

cheers
 
Thanks Steve,

Don't i have to install lots of new things on my webserver though, or will it run through the exsisting installation settings.

I just looked up AJAX (Asynchronous JavaScript And XML), but i've not heard of it before....

LOL I';ve only just got used to PHP!

can't stay still for a second in this indutry can you :)

What i ment i suppose is, how do people do what i require (at top) just with html/php or is it not possible.

Thanks again.

 
Obviously AJAX is the tool to use for this type of process, but if you are seriously opposed to learning AJAX on the spot or time constraints will not allow it, you could always do it the old fashioned way. This means that the entire form would need to be submitted and the page refreshed, but it can be done.

Put a hidden input tag in the form and name it something like 'process_value'. Place your 'check' links in the form, these links 'onClick' will call a js function, which will set the 'process_value' to the correct value, and submit the form using 'document.form_name.submit()'.

On the server-side, you would need to setup a script to check the value of 'process_value' (switch statements are great for this)and perform the correct validation routines, finally send the appropriate output back to the browser.
 
Thanks for all your help everyone.

I have enough options now to solve my prolbem...

All the best. Have a nice weekend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top