<?php
// deletestudents.php - a customised php page that works from a snippet call to list web users in the
// database and provide functionality for the students to be deleted from the database
// author: sarah vardy
// Establish a connection to the MySQL DBMS
$connection = mysql_connect("localhost", "root", "s0laspie");
// Use the modx database
mysql_select_db("modx", $connection);
// Run a query through the connection
$result = mysql_query("SELECT id, username FROM modx_web_users", $connection);
// Fetch each row of the results into an array $row
while ($row = mysql_fetch_array($result))
{
echo "{$row["username"]}\n\n";?><input name="checked" type="checkbox" value="id">
<?php
// deletestudents.php - a customised php page that works from a snippet call to list web users in the
// database and provide functionality for the students to be deleted from the database
// author: sarah vardy
// Establish a connection to the MySQL DBMS
$connection = mysql_connect("localhost", "root", "s0laspie");
// Use the modx database
mysql_select_db("modx", $connection);
//If cmd has not been initialized
if(!isset($cmd))
{
// Run a query through the connection
$result = mysql_query("SELECT id, username FROM modx_web_users ORDER BY id", $connection);
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$username=$r["username"];//take out the title
$id=$r["id"];//take out the id
//make the title a link
echo "<a href='index.php?id=44?cmd=delete&id=$id'>$username - Delete</a>";
echo "<br>";
}
}
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM modx_web_users WHERE id=$id";
$result = mysql_query($sql);
echo "Row deleted!";
}
?>$sql = "DELETE FROM modx_web_users WHERE id=$id";
$sql = "DELETE FROM modx_web_users WHERE id=$_GET['id']";

<?php
// deletestudents.php - a customised php page that works from a snippet call to list web users in the
// database and provide functionality for the students to be deleted from the database
// author: sarah vardy
// Establish a connection to the MySQL DBMS
$connection = mysql_connect("localhost", "root", "s0laspie");
// Use the modx database
mysql_select_db("modx", $connection);
//If cmd has not been initialized
if(!isset($cmd))
{
// Run a query through the connection
$result = mysql_query("SELECT id, username FROM modx_web_users ORDER BY id", $connection);
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$username=$r["username"];//take out the title
$id=$r["id"];//take out the id
//make the title a link
echo "<a href='index.php?id=44?cmd=delete&id=$id'>$username - Delete</a>";
echo "<br>";
}
}
if($_GET["cmd"]=="delete")
{
echo $_GET['id'];
//$sql = "DELETE FROM modx_web_users WHERE id=$id";
$sql = "DELETE FROM modx_web_users WHERE id=" . $_GET['id'];
$result = mysql_query($sql);
echo "Row deleted!";
}
?>
echo "<a href='index.php?id=44?cmd=delete&id=$id'>$username - Delete</a>";
It’s better to use $modx->makeUrl(44, ’’, ’cmd=delete’); and you cannot use id= or q= in your query string for passing the record id you want to delete; id and q are used by MODx and will mess up it’s ability to direct you to the proper page.
echo "<a href='index.php?id=44?cmd=delete&id=$id'>$username - Delete</a>";
Notice that you have double ? in the query string. If you are using friendly URLS, ?cmd=delete is OK, but if you aren’t it has to be &cmd=delete.
Best is to create a variable based on the site’s configuration (using FURLs or not) and use that instead of ? or & for the cmd key.

<table border="2" cellspacing="2" cellpadding="2" width="50%">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
</tr>
<?php
// deletestudents.php - a customised php page that works from a snippet call to list web users in the
// database and provide functionality for the students to be deleted from the database
// author: sarah vardy
// Establish a connection to the MySQL DBMS
$connection = mysql_connect("localhost", "root", "s0laspie");
// Use the modx database
mysql_select_db("modx", $connection);
//If cmd has not been initialized
if(!isset($cmd))
{
// Run a query through the connection
$result = mysql_query("SELECT id, username FROM modx_web_users ORDER BY id", $connection);
//run the while loop that grabs all the users
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the user
$username=$r["username"];//take out the title
$Uid=$r["id"];//take out the id
?>
<tr><td>
<?php
$url = $modx->makeUrl(44, '', "cmd=delete&Uid=$Uid");
//make the title a link
echo "<a href='$url'>$username - Delete</a>";
?>
</td>
</tr>
<?php
}
if($_GET["cmd"]=="delete")
{
assert (false);
echo $_GET['Uid'];
$sql = "DELETE FROM modx_web_users WHERE id=" . $_GET['Uid'];
$result = mysql_query($sql);
echo "Row deleted!";
}
}
?>
<?
echo "</table>";
?>
if(isset($_GET['cmd']) && isset($_GET['Uid']) && $_GET['cmd'] == 'delete' && is_numeric($_GET['Uid'])) { // always validate everything
$from = $modx->getFullTableName('web_users');
$where = "id=".$_GET['Uid'];
$modx->db->delete($from,$where); // see manager/includes/extenders/dbapi.mysql.class.inc.php
$url = $modx->makeUrl($modx->documentIdentifier);
$modx->sendRedirect($url); // reload the original page after deleting
} else {
$links = '<table cellspacing="0" cellpadding="0" id="listTable"><tr><th>Name</th></tr>'; // style with CSS
$from = $modx->getFullTableName('web_users');
$result = $modx->db->select("id,username", $from);
while($row = $modx->db->getRow($result)) {
$url = $modx->makeUrl($modx->documentIdentifier,'','cmd=delete&Uid='.$row['id']);
$links .= '<tr><td><a href="'.$url.'">'.$row['username'].' - Delete</a></td></tr>';
}
$links .= '</table>';
}
return $links;