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
Moderators: macek, egami, gesf

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
<?
echo $_GET['some'];
?><?
echo $_POST['some'];
?>


<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> $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> ".$arr[$i]." </td>";
}
$table .= "</tr>\n";
}
$table .="</table>\n";
echo("Affected rows: $affr, Number of rows: $numr, Number of fields: $numf<br>");
echo("$table");
}
?>
</body>
</html>
Users browsing this forum: No registered users and 1 guest