bdweb 0 Report post Posted July 28, 2005 T1 and t2 is the name of a two text field Like I created a form in that forum I create a two text field given the name t1 and t2 and a submit button and save it as test.htm Now I want to get the value of t1 and t2 and put it in the MYSQL database through PHP script.Or I want to search the database with the value of t1 and t2 through PHP scriptCan any one give me the solution in a simple way it will be great help for meThanks in adv Share this post Link to post Share on other sites
leiaah 0 Report post Posted July 28, 2005 If what you need to do is get the values from the 2 textfields and store them in 2 string variables to be used later, then maybe I can help you. It's probably the same as the code in a typical guestbookput this under your body tag in your test.html <form method="post" action="getString.php"> <input type="text" name="t1"> <input type="text" name="t2"> <input type="submit" value="Get String" name="submit"></form> create a file called getString.php This file will get the values of your testfields (from test.html) and then assigns them to your variables (stringT1 and stringT2) and then insert them to the TABLE_NAME in your database.<?php //create short variable names $stringT1 = $HTTP_POST_VARS['t1']; $stringT2 = $HTTP_POST_VARS['t2']; $DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];?><html><body><?php @ $db = mysql_pconnect('localhost', 'your user', 'your password'); //Connect to your databaseif (!$db){echo 'Error: Could not connect to database. Please try again later.';exit;}mysql_select_db('database name'); $query = "insert into TABLE_NAME(field1,field2) values ('".$stringT1."', '".$stringT2."')"; $result = mysql_query($query); if ($result) echo 'Success!'; ?></body></html> getString.php inserts or adds the values of the textfields in the database but if you want to use those values to search in the database, all you need to do is replace the sql query with a select statement like this:$query = "Select * in TABLE_NAME where field1=".$stringT1; Hope this helped. Notice from BuffaloHELP: Merged instead of deleting as requested. Share this post Link to post Share on other sites
sachavdk 0 Report post Posted July 31, 2005 getString.php inserts or adds the values of the textfields in the database but if you want to use those values to search in the database, all you need to do is replace the sql query with a select statement like this: $query = "Select * in TABLE_NAME where field1=".$stringT1; I think to search you'd better use:$query = "Select * in TABLE_NAME where field1 LIKE '%".$stringT1."%'";The LIKE method is better for search queries since it isn't case sensitive. Ofcourse if you want it to be casesensitive use "=" and if you want to search exactly for a string don't use the "%". Share this post Link to post Share on other sites