PDA

View Full Version : [tut] online mysql command line [/tut]



Hypertext
16-03-2008, 12:55 AM
Ok today we're going to create a quick and simple mysql command line via php. first we need to make our form:


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="cmdline">
<fieldset><legend>MySQL Command Line</legend>
<input type="text" style="background-color:#000000; color:#FFFFFF" name="line" />
</fieldset>
<fieldset><legend>Execute</legend>
<input type="submit" name="commandline" value="Execute Query" />
</fieldset>
</form>

Ok heres the lodown we choose an action of the page itself, and the method as post, we then have an input for the command line itself, and a submit button named commandline. now we need to input that data:

<?php
if(isset($_POST['commandline'])) {
$comm = stripslashes($_POST['line']);
if(mysql_query($comm) or die(mysql_error())) {
echo "Query executed successfully!";
}
}
?>
Here what we're doing is first checking if the form is posted, then we're taking the data and stripping any slashes, then we're checking if it was able to, else we die and echo the error, if succesful we echo Query executed successfully!, now let's try putting all this together:



if(isset($_POST['commandline'])) {
$comm = stripslashes($_POST['line']);
if(stripslashes(mysql_query($comm)) or die(mysql_error())) {
echo "Query executed successfully!";
}
}
else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="cmdline">
<fieldset><legend>MySQL Command Line</legend>
<input type="text" style="background-color:#000000; color:#FFFFFF" name="line" />
</fieldset>
<fieldset><legend>Execute</legend>
<input type="submit" name="commandline" value="Execute Query" />
</fieldset>
</form>
<?php } ?>

There you go! :)

Hope you understand this, have fun!

QuickScriptz
16-03-2008, 01:02 PM
Note to anyone who plans to use that anywhere...

SECURE SECURE SECURE

Note that if anyone ever got a hold of that and you had directly connected it to your database, well, to put it lightly, you're screwed. Just a thought :)

Want to hide these adverts? Register an account for free!