0

Hi,
I am creating an admin page that allows me to view requests for sheet music that is not currently on my website.
(View image to get an idea of what we're talking about).

On this page are 6 columns.
ID (autoincremented) This is the # the request is
Userid - the user's id
artist - the name of the artist the user requested
title - the name of the title the user requested
added - after I have manually added the sheet music to my site, i click added which will set the "added" column in my sql table to "yes". Also, once added is clicked, an email will be sent to the user that originally requested the sheet.
delete - This deletes the row in the sql database, and removes it from view on my page.
At the bottom of the page, there is also a button called "Added All", which goes through and sets the "added" status to "yes" for all rows on the page.

So, the problem I'm having right now, is emailing the user after I have selected Added. After I figure this out, I need to implement it into the "Added All" button, which will email all the corresponding users. Here is what I have come up with. Any input appreciated.
I'm not getting any errors at this point. I tested my variables and all are echoing out correctly.

The area that I have specified to email the user is in this if statement:

if ($confirm=="true" && isset($_GET['id']))

Here's my code. Thanks

<?php
session_start();

include_once('../inc/connect.php');
include_once('../inc/admin.php'); 
if (isset($_SESSION['username'])){
$loginstatus = "logout";

if(!isset($_SESSION['sort_counter']))
{$_SESSION['sort_counter'] = 1;}

if(($_SESSION['sort_counter']%2) == 0){ //test even value
  $sortcount = "DESC";
}else{ //odd value
  $sortcount = "";
}

$result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY id"); 

$requestedquery = mysql_query("SELECT added FROM requests WHERE added='no'");
$requestedcount = mysql_num_rows($requestedquery);

$addedquery = mysql_query("SELECT added FROM requests WHERE added='yes'");
$addedcount = mysql_num_rows($addedquery);

$getuserinfo = mysql_query("SELECT * FROM users");
$row2 = mysql_fetch_assoc($getuserinfo); 

$sort = $_GET['sort'];
$delete = $_GET['delete'];
$confirm = $_GET['confirm'];

/////////////////////////////////

if ($sort=='id'){ 

	// $result = mysql_query("SELECT * FROM users ORDER BY id");  
$result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY id $sortcount"); 
$_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run
 
}
if ($sort=='userid'){ 

	// $result = mysql_query("SELECT * FROM users ORDER BY username"); 
$result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY userid $sortcount"); 
$_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run
}
if ($sort=='artist'){ 

	// $result = mysql_query("SELECT * FROM users ORDER BY email"); 
$result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY artist $sortcount"); 
$_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run
}
if ($sort=='title'){ 

	// $result = mysql_query("SELECT * FROM users ORDER BY email"); 
$result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY title $sortcount"); 
$_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run
}
if ($sort=='file'){ 

	// $result = mysql_query("SELECT * FROM users ORDER BY email"); 
$result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY file $sortcount"); 
$_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run
}

/// FIX THIS AREA
if ($confirm=="true" && isset($_GET['id']))
{
    mysql_query('UPDATE `requests` SET `added`="yes" WHERE id = ' . (int)$_GET['id']);
	$useremailquery = mysql_query("SELECT email FROM users WHERE id=".$row2['id']."");
	$emailrow = mysql_fetch_assoc($useremailquery);
	
	$useremail = $emailrow['email'];
	
	$to = $useremail;
	$subject = "Sheet requested ready for download!";
	$Email = "admin@mysite.com";
	
	mail("$to", "$subject", "
	Hello, <br />The sheet that you requested on Sheet Music site is now ready for download.<br />
	Thank you<br /><strong>Sheet Music site</strong>", "$Email");
	
	echo "<SCRIPT language='JavaScript'><!--
  window.location='requestedsheets.php';//-->
</SCRIPT>";
}  
if ($delete=="true" && isset($_GET['id']))
{
	mysql_query('DELETE FROM `requests` WHERE id = ' . (int)$_GET['id']);	
	echo "<SCRIPT language='JavaScript'><!--
  window.location='requestedsheets.php';//-->
</SCRIPT>";
}  
if ($delete=="false" && isset($_GET['id']))
{
	echo "<SCRIPT language='JavaScript'><!--
  window.location='requestedsheets.php';//-->
</SCRIPT>";
}  
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../styles/style.css" />
<link rel="stylesheet" type="text/css" href="../styles/requestedsheets.css" />
<script type="text/javascript">
function make_blank()
{
if(document.login.username.value =="Username"){
	document.login.username.value ="";
	document.login.username.style.color ="#000000";
}
}
function make_blank1()
{
if(document.login.password.value =="Password"){
document.login.password.value ="";
document.login.password.type ="password";
document.login.password.style.color ="#000000";
}
}
function undoBlank() {
  if(document.login.username.value == ""){
    document.login.username.value ="Username";
	document.login.username.style.color="#ccc";
  }
}
function undoBlankpass() {
  if(document.login.password.value == ""){
    document.login.password.value ="Username";
	document.login.password.style.color="#cccccc";
  }
}
</script>
</head>
<body bgcolor="#343331">

<!-- Header -->
<div id="header">
	<div id="headerleft"></div>
	<div id="headermiddle"><a href="../index.php"><img src="../img/logo.png"></a></div>
	<div id="headerright">
	

			<?php echo "<form name='login' action='../inc/$loginstatus.php' method='POST'>";?>
			<div class="loginboxdiv" id="username">
			<input type="text" class="loginbox" name="username" value="Username" onFocus="make_blank();" onBlur="undoBlank();">
			</div>
			<div class="loginboxdiv" id="password">
			<input class="loginbox" type="text" name="password" type="text" value="Password" onFocus="make_blank1();" onBlur="undoBlankpass();">
			</div>
			<div id="login">
			<?php echo "<input type='image' src='../img/$loginstatus.png' alt='".ucfirst($loginstatus)."'>";?>
			</div>
			</form>
			<div id="register">
			<a href="../register.php"><img src="../img/register.png"></a>
			</div>
			<div id="forgotpassword">
			<a href="../resetpassword.php" class="forgot">Forgot Password?</a>
			</div>
	</div>
	
</div>

<!-- Content Top -->
<div id="contenttop">
	<div id="links">
	
	<table cols="7">
	<tr>
		<td align="center" valign="middle" width="100px" height="48px"><a href="../index.php"><img src="../img/home.png"></a></td>
		<td align="center" valign="middle" width="100px" height="48px"><a href="../member.php"><img src="../img/member.png"></a></td>
		<td align="center" valign="middle" width="100px" height="48px"><a href="../addsheet.php"><img src="../img/addsheet.png"></a></td>
		<td align="center" valign="middle" width="100px" height="48px"><a href="../advertise.php"><img src="../img/advertise1.png"></a></td>
		<td align="center" valign="middle" width="100px" height="48px"><a href="../faq.php"><img src="../img/faq.png"></a></td>
		<td align="center" valign="middle" width="100px" height="48px"><a href="../terms.php"><img src="../img/terms.png"></a></td>
		<td align="center" valign="middle" width="100px" height="48px"><a href="../contact.php"><img src="../img/contact.png"></a></td>
	</tr>
	</table>
<!-- 92x30 -->
	</div>
</div>

<!-- Content Middle -->
<div id="contentmiddle">
<div id="content">

<?php
include('inc/navadmin.php');
echo "<br /><div style='font-size: 28px; text-align: center;'>Requested Sheets</div>
<div id='headcont'>
<div id='requested'>Requested Sheets: ".$requestedcount."</div>
<div id='added'>Added Sheets: ".$addedcount."</div>
</div><br />
<table border='1' align='center'>
<tr>
<th bgcolor='#cccccc'><a href='requestedsheets.php?sort=id'>ID</a></th>
<th bgcolor='#cccccc'><a href='requestedsheets.php?sort=userid'>UserID</a></th>
<th bgcolor='#cccccc'><a href='requestedsheets.php?sort=artist'>Artist</a></th>
<th bgcolor='#cccccc'><a href='requestedsheets.php?sort=title'>Title</a></th>
<th bgcolor='#cccccc'><a href='requestedsheets.php'>Added</a></th>
<th bgcolor='#cccccc'><a href='requestedsheets.php'>Delete</a></th>
</tr>";
echo "<script type='text/javascript'>
function show_delete()
{
var r=confirm('Delete?');
if (r==true)
{
// Delete
return true;
}
else
{
// Don't Delete
return false;
}
}
";

echo "
function show_undelete()
{
var r=confirm('Undelete?');
if (r==true)
{
// Undelete
return true;
}
else
{
// Don't Undelete
return false;
}
}
</script>";

$usersids = "";
$i = 0;

while($row = mysql_fetch_array($result))
  {
  
  //
  $active = $row['active'];
  $color = "#ffffff";
  $deleted = "Delete";
  if ($active=='no'){
  $color = "#f43636";
  $deleted = "Undelete";
  $active = "false";
  $alert = "show_undelete";
  }
  else{
  $active = "true";
  $alert = "show_delete";
  }
  //
  
  echo "<tr>";
  echo "<td align='center' width='40' bgcolor='$color'>" .$row['id']. "</td>";
  echo "<td align='center' width='40'>" .$row['userid']. "</td>";
  echo "<td align='center' width='230'>".ucwords($row['artist'])."</td>";
  echo "<td align='center' width='230'>".ucwords($row['title'])."</td>";
  echo "<td align='center' width='10'><a href='requestedsheets.php?confirm=true&id=" .$row['id'] . "'>Added</a></td>";
  echo "<td align='center' width='10'><a href='requestedsheets.php?delete=$active&id=" .$row['id']. "' onclick='return $alert()'>$deleted</a></td>";
  echo "</tr>";
  $usersids[$i] = $row['id'];
  $i++;
  }

  echo "
  <tr>
	<td align='center' width='10' colspan='6'><a href='requestedsheets.php?confirm=all'>Added All</a></td>
  </tr>";
  
  if ($confirm=="all")
{
	$i = 0;
	mysql_data_seek($result,0);
	while($row = mysql_fetch_array($result))
  {
    mysql_query('UPDATE `requests` SET `added`="yes" WHERE id = ' . $usersids[$i]);
	$i++;
  }
	echo "<SCRIPT language='JavaScript'><!--
  window.location='requestedsheets.php';//-->
</SCRIPT>";
}  
  
echo "</table>";
}
else{
$loginstatus = "login";
}
?>

</div>

</div>

<!-- Content Bottom -->
<div id="contentbottom">

</div>

</body>
</html>
Attachments requested.png 31.61 KB
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by madCoder
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.