thisisrealnifty Posted January 20, 2010 Share Posted January 20, 2010 i was wondering if someone could write me an if statement that would be easy to add to the following php. it should check the table, tasks. on that table is a row column called task_id. the page that this will go on has the current task_id. so the script should match it to the row that has the same task_id. also on the row is a column called user_id. it should collect the user_id and then look at the table users and using the user_id grab the email. the email is used so that the script knows which user to send it to. mail($to_them, $to_subject, "$to_message", $headers); the above is where it sends it $to_them is the user that is associated with the task_id. hopefully someone can help thanks. <?php include('auth.php'); include('functions.php'); if($_POST['submit']){ $com_id = $_POST['com_id']; $mode = $_POST['mode']; $project_id = $_POST['project_id']; $task_id = $_POST['task_id']; $comment = $_POST['comment']; $post_getmessage = $_REQUEST['comment']; $to_me = "[email protected]"; # your email address $headers = "From: [email protected]"; # your site $to_subject ="New Client Portal Comment!"; # retrieves subject $to_message = $post_getmessage; # retrieves messages $valid = 1; if($mode == 'add'){ if(strlen($comment) > 0){ $cdate = time(); if($con_access_level == 'admin'){ mysql_query("insert into comments(task_id, comment, cdate, user_id, uread, aread) values ('$task_id', '$comment', '$cdate', '$con_user_id', 'N', 'Y')"); mail($to_them, $to_subject, "$to_message", $headers); }else{ mysql_query("insert into comments(task_id, comment, cdate, user_id, uread, aread) values ('$task_id', '$comment', '$cdate', '$con_user_id', 'Y', 'N')"); mail($to_me, $to_subject, "$to_message", $headers); } }else{ $err = "<div class=err>* Comment cannot be empty!</div>"; $valid = 0; } }elseif($mode == 'edit'){ //security check start if($con_access_level <> 'admin') { echo "<p><a href='main.php'>Access Denied</a></p>"; exit(); } //security check end if(strlen($comment) > 0){ mysql_query("update comments set comment = '$comment' where com_id = $com_id"); }else{ $err = "<div class=err>* Comment cannot be empty!</div>"; $valid = 0; } }else{ mysql_query("delete from comments where com_id = $com_id"); } if($valid == 1){ header("Location: task.php?project_id=$project_id&task_id=$task_id&mode=edit&nc=y"); exit(); } }elseif($_POST['exit']){ $project_id = $_POST['project_id']; $task_id = $_POST['task_id']; header("Location: task.php?project_id=$project_id&task_id=$task_id&mode=edit"); exit(); }else{ $com_id = $_GET['com_id']; $project_id = $_GET['project_id']; $task_id = $_GET['task_id']; $mode = $_GET['mode']; } if($mode != 'add'){ $com = mysql_fetch_array(mysql_query("select * from comments where com_id = $com_id")); } ?> Link to comment https://forums.phpfreaks.com/topic/189120-an-if-statement-that-uses-a-database/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.