Talk martial arts at

Bookmark and Share

How to Add/Edit Your Own SQL Queries Without phpmyadmin

How to Add/Edit Your Own SQL Queries Without phpmyadmin

Postby TailstheEnchidna » November 3rd 2004, 9:18 pm

This tutorial will help users make or edit their own SQL queries without using phpmyadmin. All you have to do is simply create a new .php file, upload anywhere on your server, and execute it from there. This is what you have to do:

Step 1: Make a new .php file, named whatever you want (I name it mysql_send.php), with the code below:

Code: Select all
<title>SQL Query</title>

if (@$form == "yes")  
   $query = stripSlashes($query) ;
   $result = mysql_query($query);
   echo "Database Selected: <b>$database</b><br>
          Query: <b>$query</b>
   if ($result == 0)
      echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");

   elseif (@mysql_num_rows($result) == 0)
      echo("<b>Query completed. No results returned.</b><br>");
     echo "<table border='1'>
             for ($i = 0; $i < mysql_num_fields($result); $i++) 
                 echo("<th>" . mysql_field_name($result,$i) . "</th>");
     echo " </tr>
             for ($i = 0; $i < mysql_num_rows($result); $i++) 
                echo "<tr>";
                $row = mysql_fetch_row($result);
                for ($j = 0; $j < mysql_num_fields($result); $j++) 
                  echo("<td>" . $row[$j] . "</td>");
                echo "</tr>";
             echo "</tbody>
   echo "<hr><br>
         <form action=$PHP_SELF method=post>
          <input type=hidden name=query value=\"$query\">
          <input type=hidden name=database value=$database>
          <input type=submit name=\"queryButton\" value=\"New Query\">
          <input type=submit name=\"queryButton\" value=\"Edit Query\">

@$query = stripSlashes($query);
 if (@$queryButton != "Edit Query")  
   $database = " ";
   $query = " ";

<form action=<?php echo $PHP_SELF ?>?form=yes method="post">
   <td align="right"><b>Type in database name</b></td>
     <input type=text name="database" value=<?php echo $database ?> >
   <td align="right" valign="top"><b>Type in SQL query</b></td>
	 <td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea>
   <td colspan="2" align="center"><input type="submit" value="Submit Query"></td>

All you would have to change there are the variables user(username of database), host of database, and database password.

Step 2: Upload the file onto yor server. Once there, run it off of your browser.

You should see a page with 2 forms to fill out: Database name and Query

Step 3: Fill out the database name and SQL query and hit Submit Query. If everything went well, the following message should appear "Query completed". It might also say "Query completed. No results returned." if it doesn't need to show you anything.

Well that's the end of my tutorial. I hope you find this helpful.

Not So New User
Posts: 72
Joined: December 26th 2003, 8:41 am

Return to phpBB 2: Tools and Related Topics

Who is online

Users browsing this forum: No registered users and 0 guests