Bech100 | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I have attempted to add confirm messages before deletes on my website,but they don't work properly, here is my code:Code: Select all
<?php
function ClientsForm()
{//Display the DataBase Clients Form
//Select the required fields in the database
$query = "SELECT client_id, client_name, client_description, client_password FROM clients ORDER BY client_id";
$result = @mysql_query($query); //Run the query.
if ($result) //If it ran ok, display the table
{
$admin = "<script language="JavaScript" type="text/javascript"><!--\n";
$admin .= "function areYouSure() {\n";
$admin .= "window.location.href='admin.php?act=clients';\n";
$admin .= "var answer = confirm ('Are you sure you want to delete XYZZY?');\n";
$admin .= "if (answer);\n";
$admin .= "alert (alright then);\n";
$admin .= "}\n";
$admin .= "--></script>\n";
$admin .= "<form id="ClientsForm" title="Clients Administration" action="admin.php?act=clients" method="post">";
$admin .= "<br /><fieldset class="field"><legend class="leyenda"> Clients Administration </legend> <br />";
$admin .= "<table width="100%" summary="Table that shows all the clients with their associated information">";
$admin .= "<thead><tr>";
//Form Headings
$admin .= "<thead><tr>";
$admin .= "<td>Client ID</td>";
$admin .= "<td>Client Name</td>";
$admin .= "<td>Client Description</td>";
$admin .= "</tr></thead>";
$admin .= "<tbody>";
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
$cont = stripslashes($row[0]);
$admin .= "<tr>";
//Checkbox
$admin .= "<td><input id="check_client" name="check_client" type="radio" value="".$cont."" class="inputframe" />\n";
//Client ID
$admin .= "<input id="client_id".$cont."" name="client_id".$cont."" type="text" size="10" maxlength="3" class="inputframe space" value="".stripslashes($row[0])."" /></td>\n";
//Client Name
$admin .= "<td><input id="client_name".$cont."" name="client_name".$cont."" type="text" size="30" maxlength="30" class="inputframe" value="".stripslashes($row[1])."" /></td>";
//Client Description
$admin .= "<td><input id="client_description".$cont."" name="client_description".$cont."" type="text" size="50" maxlength="50" class="inputframe" value="".stripslashes($row[2])."" /></td>";
$admin .= "</tr>";
$cont++;
}
}
$admin .= "</tbody>";
$admin .= "</table> <br />";
$admin .= "<div class="centro">";
$admin .= "<input title="Delete selected clients from the database" class="submit noindent" id="Delete" name="Delete" type="submit" value="Delete" onclick="javascript:areYouSure();" />";
$admin .= "<input title="Add a client to the database" class="submit space" id="Add" name="Add" type="submit" value="Add" />";
$admin .= "<input title="Edit a selected client" class="submit space" id="Edit" name="Edit" type="submit" value="Edit" /><br /><br />";
$admin .= "</div>";
//Hidden cont (number of records in the table)
$admin .= "<input id="cont" name="cont" type="hidden" value="".$cont."" />";
$admin .= "</fieldset></form>";
mysql_free_result($result); //Free up the resources.
return $admin;
}
return "<p>There has been a system error. We apologise for any inconvenience.<p><br /><br /><p>".mysql_error().": ".mysql_error()."</p>";
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
//Delete clients
function DeleteClients(&$dbconnection)
{
$i = 0;
$check = "check_client";
$delete = "<br />The following clients have been deleted:<br /><ul>";
$bool = 0;
{
if (isset($_POST['check_client']))
{
$clientid = "client_id".$i;
$i = $_POST['check_client'];
$clientname = "client_name".$i;
$clientdescription = "client_description".$i;
$query = "SELECT client_id FROM users WHERE (client_id = '{$_POST['check_client']}')";
$result = @mysql_query($query); //Run the query.
if ($result && (mysql_num_rows($result) > 0)) //If it ran ok, continue
{
return "<p>Sorry that client has users and /or projects belonging to it. It is not possible to delete this user without firstly deleting the users and/ or projects related to it.</p>".ClientsForm(); //Display the form to add a new user
}
else
$query = "SELECT client_id FROM projects WHERE (client_id = '{$_POST['check_client']}')";
$result = @mysql_query($query); //Run the query.
if ($result && (mysql_num_rows($result) > 0)) //If it ran ok, continue
{
return "<p>Sorry that client has users and /or projects belonging to it. It is not possible to delete this user without firstly deleting the users and/ or projects related to it.</p>".ClientsForm(); //Display the form to add a new user
}
else
$query = "DELETE FROM clients WHERE (client_id = '{$_POST['check_client']}')";
if (@mysql_query($query)) //If the query ran ok
{
$delete .= "<li><strong>".stripslashes($_POST[$clientname])."</strong> </li>";
$bool = 1;
}
else //If query did not run
return "<p>There has been a system error. We apologise for any inconvenience.<p><br /><br /><p>".mysql_error().": ".mysql_error()."</p>";
}
$i++;
$check = "check_client";
}
$delete .= "</ul>";
if ($bool == 1)
return $delete.ClientsForm();
return "<p>Please select the client you wish to delete!</p>".ClientsForm();
}
Bech100 | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]