Verify form textbox value is in DB before navigation

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 31
Joined: Mon Mar 28, 2011 7:52 am

Sat May 25, 2013 2:37 pm

I want a simple form textbox on hello.php that the user enters a code into and on button submit verify the textbox value is in a MySQL database. If it is... navigate to hello2.php with the value of the textbox in the url as name=


user enters in 1234 into the textbox verifies it is in the database...they navigate to /hello2.php?name=1234

user enters in 1235 which is not.....nothing happens

In addition when hello2.php is navigated to it first verifies that name=1234 is in the url before it shows.

New php-forum User
New php-forum User
Posts: 44
Joined: Tue May 28, 2013 10:04 pm
Location: India,Lucknow

Fri May 31, 2013 2:32 am

Here is code for achieving what you want
if ($_POST ['b_submit'])
$row1=mysql_fetch_array (mysql_query ("select * from yourtable where yourcolumn='".$_POST ['input_value']."'"));

if ($row1 ['yourcolumn']) echo "<script language='javascript'>window.location='yoururl.php'</script>";else echo "";

<form method="post">
<textarea name="input_value"></textarea>
<input type="submit" name='b_submit' value="Submit">

If any problem friend, please do revert to me i will be there to help you out

php-forum Fan User
php-forum Fan User
Posts: 974
Joined: Mon Oct 01, 2012 12:32 pm

Fri May 31, 2013 10:09 am

If you want to check without leaving the page you're going to have to go with an Ajax solution. A solution like developerahusain is suggesting would work also and be a little easier. I want to point out that I mean one LIKE, but not necessarily the one offered. I make the distinction because the solution offered suggests the use of deprecated mysql_functions, and uses an implied form action instead of explicit that may not work as intended with all browsers. The spirit of the suggestion is a good one though, let the navigation happen, and then let your form processor determine where it lands, instead of trying to do it before the navigation which would require AJAX

Post Reply