Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

How to asking user input data in TEXT BOX and run a Query

Codes here !

Moderators: macek, egami, gesf

How to asking user input data in TEXT BOX and run a Query

Postby sarjanajava » Wed Nov 27, 2002 11:07 pm

:oops:

Hi there!

Can i get an advise about how to asking user input data in text box and then query will perform according the data inputed by user. For example here is the website, regarding the matter


http://www.kopkastam.org.my/ahli
User avatar
sarjanajava
New php-forum User
New php-forum User
 
Posts: 41
Joined: Wed Nov 27, 2002 10:59 pm

Re: How to asking user input data in TEXT BOX and run a Quer

Postby Oleg Butuzov » Thu Nov 28, 2002 4:09 am

sarjanajava wrote::oops:

Hi there!

Can i get an advise about how to asking user input data in text box and then query will perform according the data inputed by user. For example here is the website, regarding the matter


http://www.kopkastam.org.my/ahli


<input type=text name=some value='variable'>

result page

Code: Select all
<?
echo $_GET['some'];
?>


or if you use POST method


Code: Select all
<?
echo $_POST['some'];
?>
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Thanks

Postby sarjanajava » Thu Nov 28, 2002 9:24 am

:lol:
Thanks for your advice
User avatar
sarjanajava
New php-forum User
New php-forum User
 
Posts: 41
Joined: Wed Nov 27, 2002 10:59 pm

i try but can't :please help me!

Postby sarjanajava » Thu Nov 28, 2002 10:03 am

Can you describe step by step instruction ?

here is coding to perform FORM for user input data into text box
filename: input.html
-------
<body>

<form action="data.php" method="post">
Name:
<input type=text name=some value='variable'>


<input type="submit" name="" value="find">

</form>
-----------
and this is coding for data.php
<?php

echo $_POST['some'];


//connect to database

if(!($dbLink = mysql_pconnect("localhost", "", "")))
{
print("Failed to connect to database!<BR>\n");
print("Aborting!<BR>\n");
exit();
}
//QUERY
$Query = "SELECT 'data that user input'";
$Query .= "FROM tablename;
if(!($dbResult = mysql_query($Query, $dbLink)))
{
print("Couldn't execute query!<BR>\n");
print("MySQL reports: " . mysql_error() . "<BR>\n");
print("Query was: $Query<BR>\n");
exit();
}

HOW TO GET what user input from input.html and then process with data.php especially SQL statement in $Query about variable that have been inputed by user
User avatar
sarjanajava
New php-forum User
New php-forum User
 
Posts: 41
Joined: Wed Nov 27, 2002 10:59 pm

Postby webwired » Thu Nov 28, 2002 7:16 pm

I found this the other day, if I'm right about what you're asking, this will work great.
Code: Select all
<html>
<body>
Homesite:<a href="http://www.watkins-farm.com/php/">http://www.watkins-farm.com/php/</a><br>
<form action="sqler.php" method="post">
  <TEXTAREA cols=70 name=sql rows=5><?PHP echo(stripslashes($_POST["sql"])); ?></TEXTAREA>
  <input type="submit" name="sql_post">
</form>
<?PHP

$db_host   ="localhost";
$db_user   ="username";
$db_pwd      ="password";
$db_db      ="database";

$ok = $_POST["sql_post"];
if($ok){
   $sql = $_POST["sql"];
//$sql="SELECT * cl_ip LIMIT 10"; //DEMO restriction

   $dbh=mysql_connect ("$db_host", "$db_user", "$db_pwd") or die ('I cannot connect to the database.');
   $res=mysql_select_db("$db_db") or die("Wrong DB<br>");
   $sql = stripslashes ( $sql );
echo("$sql<hr>");
   $res = mysql_query($sql) or die(mysql_error()."<hr>");
   $affr = @mysql_affected_rows($res);
   $numr = @mysql_num_rows($res);
   $numf = @mysql_num_fields($res);
   if(!$affr)$affr=0;
   if(!$numr)$numr=0;
   if(!$numf)$numf=0;
   $table =<<< ETT
      <table border=1><tr><td colspan=$numf>Results:</td></tr>
ETT;


   if ($numf > 0){
      $table .= "<tr>";
   }
   
   for($i=0;$i<$numf;$i++){
      $fn = mysql_field_name($res,$i);
      $table .="<td><b>&nbsp;$fn</b></td>";
   }

   if ($numf > 0){
   $table .= "</tr>\n";
   }

   while($arr = @mysql_fetch_array($res) ){
      $table .= "<tr>";
      for($i=0;$i<$numf;$i++){
         $table .= "<td>&nbsp;".$arr[$i]."&nbsp;</td>";
      }
      $table .= "</tr>\n";

   }
   $table .="</table>\n";
   echo("Affected rows: $affr, Number of rows: $numr, Number of fields: $numf<br>");
   echo("$table");
}
?>
</body>
</html>
User avatar
webwired
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Nov 23, 2002 5:20 pm
Location: St. Louis, Missouri


Return to mySQL & php coding

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.