l3asturd Posted August 1, 2007 Share Posted August 1, 2007 Some of you know I'm new to PHP. I'm starting to understand a little, even writing code that works! I wanted to write a simple .php that clears out a specified dbtable. Here's what I have: <?php // database information - set this to what your database login information is $host = 'hidden'; $user = 'hidden'; $password = 'hidden'; // This is the name of the database you will be connecting to. Might want to name it Tournaments or something $dbName = 'DVDB3'; $dbTable = 'TLB'; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); $select_result = mysql_query("SELECT Name,Score,Purse FROM $dbTable", $conn); $list = mysql_fetch_assoc($select_result); echo <<<FORMENT <br> <table width="100" border="1"> <th width="50">Name</th> <th width="25">Score</th> <th width="25">Winnings</th> FORMENT; while($list = mysql_fetch_assoc($select_result)) { echo <<<EOF <tr> <td align=center width=100>{$list['Name']}</td> <td align=center width=50>{$list['Score']}</td> <td align=center width=50>{$list['Purse']}</td> </tr> EOF; } echo "</table>"; $DELETEYES = ($_POST['DELETE']); if (($DELETEYES) == "1") { $delete_result = mysql_query("DELETE ** FROM $dbTable", $conn); echo "Table cleared"; } { } echo <<<FORMENT <br> Clear out table? <br> <form action = "{$_SERVER['PHP_SELF']}" method = "post"> <input type = "checkbox" name = "DELETE" value="1"> <input type = "submit" value = "CLEAR"> </form> FORMENT; ?> OK so this displays a small html table with the TLB table values nested in. The table look funny though, after the header it has several blank lines before the actual data begins. Anyone see anything wrong with the code? As fas as displaying the data goes? Also why can't I delete everything from the table? I'm echoing "Table Cleared" if the statement is true, but the table remains populated. Is (DELETE * FROM TLB) not valid? I've tried (DELETE FROM TLB *) too with the same result. Maybe it's not mysql_query? Is there such thing as mysql_delete? Please help. Also, take a look at the other code and tell me if I'm doing anything ridiculous. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/62797-solved-clear-table/ Share on other sites More sharing options...
l3asturd Posted August 1, 2007 Author Share Posted August 1, 2007 omg, I just figured it out. (DELETE FROM $dbtable) so easy. Quote Link to comment https://forums.phpfreaks.com/topic/62797-solved-clear-table/#findComment-312607 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.