my question is how come everytime i select delete, another table is added? there are no errors thats why im confused. here's my code:
<?php
$username = "user";
$password = "pass";
$hostname = "localhost";
$db = mysql_connect($hostname, $username, $password)
or die ("Unable to connect to mySQL".mysql_error());
mysql_select_db('mynewdbase') or die(mysql_error());
$flag = $_GET['flag'];
if($flag=="1")
{
$id = $_GET['id'];
$del = "DELETE FROM newdbase WHERE id = '$id'";
$nres = mysql_query($del);
if(!$nres)
echo " Failed to delete:" . mysql_error();
else
echo " Deleting successful";
}
?>
<HTML>
<BODY>
<form method = "get" action = "act1.php">
Storename:<input type = "text" name = "store"><br>
Sales <input type = "text" name = "sales"><br>
Date <input type = "text" name = "month" size = "3" value = "<?php echo date('m'); ?>">
-<input type = "text" name = "day" size = "3" value = "<?php echo date('d'); ?>">
-<input type = "text" name = "year" size = "3" value = "<?php echo date('Y'); ?>"><br>
<input type = "submit" name = "submit" value = "Save">
<input type = "reset" name = "clear" value = "Cancel">
</form>
</BODY>
</HTML>
<?php
$store = $_GET['store'];
$sales = $_GET['sales'];
$year = $_GET['year'];
$month = $_GET['month'];
$day = $_GET['day'];
$ans = "INSERT INTO newdbase VALUES ('','$store', '$sales', '$year' ,'$month', '$day')";
$result = mysql_query($ans);
if($result!='')
echo '<br>Saving Successful';
else
echo '<br>Failed'. mysql_error();
$queryshow = "SELECT * FROM newdbase";
$result2 = mysql_query($queryshow);
$c = count($result2);
echo '<table border ="1">';
echo '<th>Action</th><th>Storename</th><th>Sales</th><th>Date</th>';
if ($c>0)
{
while ($a=mysql_fetch_array($result2))
{
echo '<tr>';
echo '<td><a href = "act1.php?id= $id & flag = 1">Delete</a></td>';
echo '<td>'. $a['store'] . '</td>';
echo '<td>'. $a['sales'] . '</td>';
echo '<td>'. $a['month'] . '-'.$a['day'].'-'.$a['year'].'</td>';
echo '</tr>';
}
}
echo '</table>';
?>
my id value is set on my database. my database is consist of 6 fields naming id, store, sales, year, month and day
your code works but it only delete the value inside the table., i need to delete the whole table
so where will i put mysql_query("DROP TABLE IF EXISTS 'newdbase'");?
i still have errors., sorry, just learning php
im having this erros:
FailedTable 'mynewdbase.newdbase' doesn't exist
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\blah.php on line 63
don't know what to do, but ill try! tnx moxi =p
<?php
$username = "user";
$password = "pass";
$hostname = "localhost";
$db = mysql_connect($hostname, $username, $password)
or die ("Unable to connect to mySQL".mysql_error());
mysql_select_db('mynewdbase') or die(mysql_error());
$flag = $_GET['flag'];
if($flag=="1")
{
$id = $_GET['id'];
$del = "DELETE FROM newdbase WHERE id = '$id'";
$nres = mysql_query($del);
if(!$nres)
echo " Failed to delete:" . mysql_error();
else
echo " Deleting successful";
}
?>
<HTML>
<BODY>
<form method = "get" action = "act1.php">
Storename:<input type = "text" name = "store"><br>
Sales <input type = "text" name = "sales"><br>
Date <input type = "text" name = "month" size = "3" value = "<?php echo date('m'); ?>">
-<input type = "text" name = "day" size = "3" value = "<?php echo date('d'); ?>">
-<input type = "text" name = "year" size = "3" value = "<?php echo date('Y'); ?>"><br>
<input type = "submit" name = "submit" value = "Save">
<input type = "reset" name = "clear" value = "Cancel">
</form>
</BODY>
</HTML>
<?php
$store = $_GET['store'];
$sales = $_GET['sales'];
$year = $_GET['year'];
$month = $_GET['month'];
$day = $_GET['day'];
$ans = "INSERT INTO newdbase VALUES ('','$store', '$sales', '$year' ,'$month', '$day')";
$result = mysql_query($ans);
if($result!='')
echo '<br>Saving Successful';
else
echo '<br>Failed'. mysql_error();
$queryshow = "SELECT * FROM newdbase";
$result2 = mysql_query($queryshow);
$c = count($result2);
echo '<table border ="1">';
echo '<th>Action</th><th>Storename</th><th>Sales</th><th>Date</th>';
if ($c>0)
{
while ($a=mysql_fetch_array($result2))
{
echo '<tr>';
echo '<td><a href = "act1.php?id= $id & flag = 1">Delete</a></td>';
echo '<td>'. $a['store'] . '</td>';
echo '<td>'. $a['sales'] . '</td>';
echo '<td>'. $a['month'] . '-'.$a['day'].'-'.$a['year'].'</td>';
echo '</tr>';
}
}
echo '</table>';
?>
my id value is set on my database. my database is consist of 6 fields naming id, store, sales, year, month and day
your code works but it only delete the value inside the table., i need to delete the whole table
so where will i put mysql_query("DROP TABLE IF EXISTS 'newdbase'");?
i still have errors., sorry, just learning php
im having this erros:
FailedTable 'mynewdbase.newdbase' doesn't exist
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\blah.php on line 63
don't know what to do, but ill try! tnx moxi =p