Hi,
I have a text box, in that i have given the mysql query. I can able to get the query in variable. But after submit button i want to get data to be printed on a same page. But how can i print the rows of the table according to the query.
can any one assist me with some examples or some sample Programmes.
Thanks with Regards,
Yudha2008
php mysql query from input textbox
Moderator: General Moderators
- markusn00b
- Forum Contributor
- Posts: 298
- Joined: Sat Oct 20, 2007 2:16 pm
- Location: York, England
Re: php mysql query from input textbox
Run a mysql_query() based on the input data.
Check out these tutorials on mysql & php.
Post back with your attempt.
Mark.
Check out these tutorials on mysql & php.
Post back with your attempt.
Mark.
Re: php mysql query from input textbox
Hi,
I have tried myself and find solution for the question what i asked in previews post.
Now i can able to get with filed name and rows also. I have posted this because it will help to some one.
Thanks with Regards,
Yudha2008
I have tried myself and find solution for the question what i asked in previews post.
Code: Select all
<table width="703" border="1" with="500" cellpadding="5" cellspacing="5">
<tr bgcolor="#466275">
<td width="200" style="color:#FFFFFF"><b>Mysql Query </b></td>
<td width="450"></td>
</tr>
<tr><td><h3>Query</h3></td><td><textarea name="qry" cols="100" rows="7" class="font"></textarea></td></tr>
<tr><td></td><th scope="col"><input type="submit" name="submit" value="Report" class=butt></th></tr>
</table>
<br/>
<br/>
<?php
include("conn.php");
$qry = $_POST['qry'];
$submit = $_POST{'submit'};
if($submit == 'Report')
{
$result=mysql_query("$qry") or die ("could not run Query1");
$num_rows = mysql_num_rows($result);
$fields_num = mysql_num_fields($result);
//echo "There are $num_rows records.<P>";
echo "<table width=400 border=1>\n";
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
while ($get_info = mysql_fetch_row($result))
{
echo "<tr>\n";
foreach ($get_info as $field)
echo "\t<td><font face=arial size=1/>$field</font></td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
?>
</center>
</form></td></tr></table>
</center>
Now i can able to get with filed name and rows also. I have posted this because it will help to some one.
Thanks with Regards,
Yudha2008
- markusn00b
- Forum Contributor
- Posts: 298
- Joined: Sat Oct 20, 2007 2:16 pm
- Location: York, England
Re: php mysql query from input textbox
By the way, you're wide open to SQL injection.