Need a PHP Junkie

We may earn a small commission from affiliate links and paid advertisements. Terms

JDMPlaya

Senior Member
Code:
<?
include("../conf.php");
include(DB_INC_FILE);

$table_name = "greg_chamblin";

$business_name_for_display = stripslashes($business_name);


$db = @mysql_select_db($db_name, $connection) or die("Couldn't select DCW Chamblin delete database.");

$sql = "DELETE FROM greg_chamblin WHERE id_num =\"$id_num\"";

$result = @mysql_query($sql,$connection) or die("Couldn't execute DCW Chamblin Delete query.");

?>


<HTML>
<HEAD>

<TITLE>>Business ID <? echo "$id_num"; ?> Deleted</TITLE>
</HEAD>
<bodybgcolor="white" leftmargin=0 topmargin=0 text="black" link="navy" vlink="blue" alink="red">

<br><br>

<center><font face="Arial" size="4" color="navy"><b>Business Deleted</b></font></center><br>
<center><table align="center">
<tr>
<td width="3"><br></td>
<td valign="top">

<font face="Arial" size="+1" color="Black">Business IDNumber - <? echo "$id_num"; ?><br>
BusinessName -<? echo "$business_name_for_display"; ?><br>
<b>DELETED</b></font><br>

</td>
<td width="3"><br></td>
</tr>
</table></center>

<center><a href="./admin_menu.php">Return to Main Admin Menu</a></center>

</BODY>
</HTML>

I'm trying to get a pop up that says "are you sure you want to delete this item" or something like that.. anyone know the line of code to do this?
 

posol

RETIRED
Staff member
do something like:

<script type="text/javascript">

function checkit() {
if (confirm("Are you sure you want to delete this?")) {
return true;

} else {
return false;
}
}
}
</script>

and your link like this:
delete


this will bring you to the prompt before it will move onto the link...
 

JDMPlaya

Senior Member
this is where I added the onclick
Code:
$display_block .= "
<form action=\"./admin_del.php\" onclick=\"checkit();\" method=\"POST\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
<input type=\"submit\" value=\"Delete this Business\" name=\"Delete this Business\"</form>
<form action=\"./admin_edit.php\" method=\"POST\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
<input type=\"submit\" value=\"Edit Data for this Business\" name=\"Edit Data for this Business\">
</form>
<hr align=\"LEFT\" size=\"2\" width=\"100%\" color=\"navy\" noshade>
";
}
?>

than in my HTML header i put
Code:
<script type="text/javascript">

function checkit() {
if (confirm("Are you sure you want to delete this Business?")) {
return true;

} else {
return false;
}
}
}
</script>

It didnt prompt, but i probably did something wrong .. see anything?
 

posol

RETIRED
Staff member
yeah,you aren't clicking the form. lol there is no onclick() attribute for a form.

it needs to be on either a <ahref ... > link or on an <input type="button" onclick=checkit();" />

-------------


Code:
<input type=\"submit\" value=\"Delete this Business\" name=\"Delete this Business\" onclick=\"checkit();\">
 

JDMPlaya

Senior Member
hmm still doesnt work

here is a snippet of my code again for reference

Code:
$display_block .= "
<form action=\"./admin_del.php\" method=\"POST\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
<input type=\"submit\" value=\"Delete this Business\" name=\"Delete this Business\" onclick=\"checkit();\"></form>
<form action=\"./admin_edit.php\" method=\"POST\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
<input type=\"submit\" value=\"Edit Data for this Business\" name=\"Edit Data for this Business\">
</form>
<hr align=\"LEFT\" size=\"2\" width=\"100%\" color=\"navy\" noshade>
";
}
?>

<HTML>
<HEAD>
<script type="text/javascript">

function checkit() {
if (confirm("Are you sure you want to delete this Business?")) {
return true;

} else {
return false;
}
}
}
</script>

<TITLE>Administer by Business Name</TITLE>
</HEAD>
<bodybgcolor="white" leftmargin=0 topmargin=0 text="black" link="navy" vlink="blue" alink="red">

<br><br>

<center><font face="Arial" size="4" color="navy"><b>Administer by Business Name</b></font></center><br>
<center><table align="center">
<tr>
<td width="3"><br></td>
<td valign="top">

<font face="Arial" size="+1" color="Black"><? echo "$display_block"; ?></font>

</td>
<td width="3"><br></td>
</tr>
</table></center>

<center><a href="./index.php">Return to Admin Menu</a></center>

</BODY>
</HTML>
 

posol

RETIRED
Staff member
https://hondaswap.com/temp/test.php

cancel does nothing, ok takes you to the admin_del page (which pbviosuly isn't on my server, so it goes to the generic 404.


if JAVASCRIPT is turned off, this will fail miserably.

know this before implementing.

Code:
<?php

$display_block .= "
<form id=\"frmdefault\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
<input type=\"button\" value=\"Delete this Business\" name=\"Delete this Business\" onclick=\"checkit();\"></form>
<form action=\"./admin_edit.php\" method=\"POST\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
<input type=\"submit\" value=\"Edit Data for this Business\" name=\"Edit Data for this Business\">
</form>
<hr />
";
?>

<html>
<head>
<script type="text/javascript">

function checkit() {
if (confirm("Are you sure you want to delete this Business?")) 
{
document.getElementById("frmdefault").action = "admin_del.php";
document.getElementById("frmdefault").method="post";
document.getElementById("frmdefault").submit();
return;
}
else 
{
return false;
}
}
</script>

<title>Administer by Business Name</title>
</head>
<body>
<h1>Administer by Business Name</h1>

<div><?php echo $display_block; ?></div>
</body>
</html>


as an aside, your html sucks. there is no use for a table. you should learn html mark up structure and css to style stuff.
 

JDMPlaya

Senior Member
hmm..Now the prompt does come up but it does not take you to the delete page, It does nothing by clicking "okay"

once again here is my code

Code:
<?
include("../conf.php");
include(DB_INC_FILE);

$search_string_name = stripslashes($search_string_name);

// ////////////////// block of variable to change for different display SORTING methods //////////////
// Next variable is sorting method for display - Change it for different sorting methods 
$order_by_field = "last_name";

// Next variable is the file name of this file
$current_file_name = "sel_by_business_name.php";
// ////////////////// end of block of variables to change //////////////////////////////////////////////

$table_name = "greg_chamblin";
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select DCW Equitable database.");

$order_by_field_1 = premium;
$order_by_field_2 = business_name;
$sql = "SELECT id_num, business_name, first_name, last_name, address1, address2, city, state, zip, phone, fax, email, web_address, logo, business_type_1, business_type_2, business_type_3
FROM $table_name
WHERE business_name LIKE \"%$search_string_name%\"
ORDER BY $order_by_field_1, $order_by_field_2
";
$result = @mysql_query($sql,$connection) or die("Couldn't execute DCW Equitable Read query.");

while ($row = mysql_fetch_array($result)) {
$id_num = $row['id_num'];
$business_name = $row['business_name'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$address1 = $row['address1'];
$address2 = $row['address2'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$fax = $row['fax'];
$email = $row['email'];
$web_address = $row['web_address'];
$logo = $row['logo'];
$business_type_1 = $row['business_type_1'];
$business_type_2 = $row['business_type_2'];
$business_type_3 = $row['business_type_3'];

$display_block .= "
ID Number = $id_num<br>
<strong>$business_name</strong><br>
$first_name $last_name<br>
$address1<br>";
if ($address2 != "") {$display_block .= "$address2<br>";} 
$display_block .= "
$city, $state $zip<br>
Phone: $phone<br>";
if ($fax != "") {$display_block .= "FAX: $fax<br>";} 
if ($email != "") {$display_block .= "$email<br>";}
if ($web_address != "") {$display_block .= "$web_address<br>";}
if ($logo != "") {$display_block .= "Logo Image: $logo<br>";} 
$display_block .= "
Type of Business:<br>
$business_type_1 <br>";
if ($business_type_2 != "") {$display_block .= "$business_type_2<br>";}
if ($business_type_3 != "") {$display_block .= "$business_type_3<br>";}

$display_block .= "
<form action=\"./admin_del.php\" method=\"POST\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
 <input type=\"button\" value=\"Delete this Business\" name=\"Delete this Business\" onclick=\"checkit();\"> </form>
<form action=\"./admin_edit.php\" method=\"POST\">
<input type=\"hidden\" name=\"id_num\" value=\"$id_num\">
<input type=\"hidden\" name=\"business_name\" value=\"$business_name\">
<input type=\"submit\" value=\"Edit Data for this Business\" name=\"Edit Data for this Business\">
</form>
<hr align=\"LEFT\" size=\"2\" width=\"100%\" color=\"navy\" noshade>
";
}
?>

<html>
<head>
<script type="text/javascript">

function checkit() {
if (confirm("Are you sure you want to delete this Business?")) 
{
document.getElementById("frmdefault").action = "admin_del.php";
document.getElementById("frmdefault").method="post";
document.getElementById("frmdefault").submit();
return;
}
else 
{
return false;
}
}
</script>

<center><font face="Arial" size="4" color="navy"><b>Administer by Business Name</b></font></center><br>
<center><table align="center">
<tr>
<td width="3"><br></td>
<td valign="top">

<font face="Arial" size="+1" color="Black"><? echo "$display_block"; ?></font>

</td>
<td width="3"><br></td>
</tr>
</table></center>

<center><a href="./index.php">Return to Admin Menu</a></center>
<div>
<hr />

</div>
</body>
</html>
 

posol

RETIRED
Staff member
it doesn't work because you didn't copy the code i gave you.

your form tag is fucked.

getElementById won't work if you don't have a form id="X"
 

JDMPlaya

Senior Member
When I copy the code you gave me, When I click okay, it goes nowhere
 

posol

RETIRED
Staff member
go to my test link... it works. thats the code i have quoted above.

100%.

you don't have the id in the form tag.
you need to remove the action and method fromt he form tag.

if my test page doesn't work either, you don't have javascript enabled.
 
Top