Verify form textbox value is in DB before navigation

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

Verify form textbox value is in DB before navigation

Postby coderneeded » 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=

Example:

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.

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

Re: Verify form textbox value is in DB before navigation

Postby developerahusain » 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">
</form>

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

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

Re: Verify form textbox value is in DB before navigation

Postby seandisanti » 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


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests