Php 单击图标时删除行
这是用于查看表的userTable.phpPhp 单击图标时删除行,php,mysql,sql,Php,Mysql,Sql,这是用于查看表的userTable.php 当用户单击glyphicon remove时,会出现一条消息,说明行已被删除,但当我单击它时,它会重定向到空白页和url <?php $welcome="Hello, " . $name ."!"; include("../db/dbconn.php"); $sql = "SELECT artistCD.cdID, artistCD.cdTitle, artistcd.cdPrice, sdetails.qty, sum(art
当用户单击glyphicon remove时,会出现一条消息,说明行已被删除,但当我单击它时,它会重定向到空白页和url
<?php
$welcome="Hello, " . $name ."!";
include("../db/dbconn.php");
$sql = "SELECT artistCD.cdID, artistCD.cdTitle, artistcd.cdPrice,
sdetails.qty, sum(artistCD.cdPrice * sdetails.qty)
as TotalSales FROM artistCD NATURAL JOIN sdetails NATURAL JOIN cdsales
WHERE
day(cdSales.dSales) = day(Now()) AND
month(cdSales.dSales)=month(Now()) AND year(cdSales.dSales)=year(Now())
AND
cdSales.uID = '$uID' GROUP BY artistCD.cdID";
//WHERE ORNum
$result = $conn->query($sql);
$total = null;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>".$row["cdID"]."</td><td>".$row["cdTitle"]."</td>
<td>".$row["cdPrice"]."</td><td>".$row["qty"]."</td>
<td>".$row["TotalSales"]."</td>
<td>
<a href='artistcd.php?action=edit&cdID='".$row['cdID']."><i
class='glyphicon glyphicon-pencil'> </i></a>
<a href='../util/deleteRow.php?
action=cdID='".$row['cdID']."title='Are you sure you want to remove this CD?
data-toggle='confirmation' data-singleton='true' data-
placement='left' data-popout='true'>
<i class='glyphicon glyphicon-remove'> </i></a>
</td>
</tr>";
$total += $row["TotalSales"];
$GLOBALS['total'] = $total;
}
echo"
<tr>
<td></td><td></td><td></td><td class='text-right'>Grand Total:</td>
<td>".$total.".00</td><td></td>
</tr>";
}
else{
echo "No records found.";
}
$conn->close();
?>
请尝试以下操作
<?php
$welcome = "Hello, " .
$name .
"!";
include( "../db/dbconn.php" );
$sql = "SELECT artistCD.cdID,
artistCD.cdTitle,
artistCD.cdPrice,
sdetails.qty,
SUM( artistCD.cdPrice *
sdetails.qty ) AS TotalSales
FROM artistCD
NATURAL JOIN sdetails
NATURAL JOIN cdsales
WHERE DATE( cdSales.dSales ) = CURDATE()
AND cdSales.uID = '$uID'
GROUP BY artistCD.cdID";
$result = $conn->query( $sql );
$total = null;
if ( $result->num_rows > 0 )
{
// output data of each row
while( $row = $result->fetch_assoc() )
{
echo "<TR>\n
<TD>" . $row[ "cdID" ] . "</TD>\n
<TD>" . $row[ "cdTitle" ] . "</TD>\n
<TD>" . $row[ "cdPrice" ] . "</TD>\n
<TD>" . $row[ "qty" ] . "</TD>\n
<TD>" . $row[ "TotalSales" ] . "</TD>\n
<TD>\n
<A HREF = 'artistcd.php?action=edit&cdID=" .
$row[ 'cdID' ] .
"'>\n
<I CLASS = 'glyphicon glyphicon-pencil'> </I>\n
</A>\n\n
<A HREF = '../util/deleteRow.php?action=cdID=" .
$row[ 'cdID' ] .
"
TITLE = 'Are you sure you want to remove this CD?'
DATA-TOGGLE = 'confirmation'
DATA-SINGLETON = 'true'
DATA-PLACEMENT = 'left'
DATA-POPOUT = 'true' >\n
<I CLASS = 'glyphicon glyphicon-remove'> </I>\n
</A>\n
</TD>\n
</TR>\n";
$total += $row[ "TotalSales" ];
$GLOBALS[ 'total' ] = $total;
}
echo "<TR>\n
<TD></TD>\n
<TD></TD>\n
<TD></TD>\n
<TD CLASS = 'text-right'>Grand Total:</TD>\n
<TD>" .
$total .
".00</TD>\n
<TD></TD>\n
</TR>\n";
}
else
{
echo "No records found.";
}
$conn->close();
?>
不应在编写UI代码的同一位置编写数据库代码。我建议您使用MVC或MVP模式。make href#value。然后使用默认javascript警报?如果确认,则将用户指向deleteRow.phpfile@Troyer固定了锚。但它仍然重定向到一个黑色页面,没有消息。
<?php
$welcome = "Hello, " .
$name .
"!";
include( "../db/dbconn.php" );
$sql = "SELECT artistCD.cdID,
artistCD.cdTitle,
artistCD.cdPrice,
sdetails.qty,
SUM( artistCD.cdPrice *
sdetails.qty ) AS TotalSales
FROM artistCD
NATURAL JOIN sdetails
NATURAL JOIN cdsales
WHERE DATE( cdSales.dSales ) = CURDATE()
AND cdSales.uID = '$uID'
GROUP BY artistCD.cdID";
$result = $conn->query( $sql );
$total = null;
if ( $result->num_rows > 0 )
{
// output data of each row
while( $row = $result->fetch_assoc() )
{
echo "<TR>\n
<TD>" . $row[ "cdID" ] . "</TD>\n
<TD>" . $row[ "cdTitle" ] . "</TD>\n
<TD>" . $row[ "cdPrice" ] . "</TD>\n
<TD>" . $row[ "qty" ] . "</TD>\n
<TD>" . $row[ "TotalSales" ] . "</TD>\n
<TD>\n
<A HREF = 'artistcd.php?action=edit&cdID=" .
$row[ 'cdID' ] .
"'>\n
<I CLASS = 'glyphicon glyphicon-pencil'> </I>\n
</A>\n\n
<A HREF = '../util/deleteRow.php?action=cdID=" .
$row[ 'cdID' ] .
"
TITLE = 'Are you sure you want to remove this CD?'
DATA-TOGGLE = 'confirmation'
DATA-SINGLETON = 'true'
DATA-PLACEMENT = 'left'
DATA-POPOUT = 'true' >\n
<I CLASS = 'glyphicon glyphicon-remove'> </I>\n
</A>\n
</TD>\n
</TR>\n";
$total += $row[ "TotalSales" ];
$GLOBALS[ 'total' ] = $total;
}
echo "<TR>\n
<TD></TD>\n
<TD></TD>\n
<TD></TD>\n
<TD CLASS = 'text-right'>Grand Total:</TD>\n
<TD>" .
$total .
".00</TD>\n
<TD></TD>\n
</TR>\n";
}
else
{
echo "No records found.";
}
$conn->close();
?>