mark_c Posted April 16, 2010 Share Posted April 16, 2010 Hi All, Is there any way to validate a text field in php to allow only values already in the Mysql table. If the user add new thing error message has to come up. I know drop down is the best. But I like to use text field. Link to comment https://forums.phpfreaks.com/topic/198725-form-validation/ Share on other sites More sharing options...
Sergey Popov Posted April 16, 2010 Share Posted April 16, 2010 Assuming your text field named my_form_field, you can validate like this: $r=@mysql_query("select * from my_table where my_db_field='".addslashes($_REQUEST["my_form_field"])."'"); if(!@mysql_num_rows($r)){ echo 'Value is not valid!'; } Link to comment https://forums.phpfreaks.com/topic/198725-form-validation/#findComment-1042914 Share on other sites More sharing options...
mark_c Posted April 16, 2010 Author Share Posted April 16, 2010 Hi Sergey, Thank you for your help. I'm new in php. I'm attaching my file. Is it possible to add the codes to the file. Is going to be great help for me. Text field is 'type' Thanks, Mark Link to comment https://forums.phpfreaks.com/topic/198725-form-validation/#findComment-1042928 Share on other sites More sharing options...
mark_c Posted April 16, 2010 Author Share Posted April 16, 2010 My working file [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/198725-form-validation/#findComment-1042929 Share on other sites More sharing options...
mark_c Posted April 16, 2010 Author Share Posted April 16, 2010 Where I have to place this code.? Can anyone help me. Link to comment https://forums.phpfreaks.com/topic/198725-form-validation/#findComment-1042942 Share on other sites More sharing options...
mark_c Posted April 16, 2010 Author Share Posted April 16, 2010 Hi Sergey, Thank you for the help... It's working fine Mark Link to comment https://forums.phpfreaks.com/topic/198725-form-validation/#findComment-1042967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.