Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/62797-solved-clear-table/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.