Brian W Posted September 4, 2008 Share Posted September 4, 2008 I'm relatively new to PHP. What I need to do is to have a form that can create entries in a database (lets just say 5 fields; Name, Last Name, DOB, Fav Color, Fav Holiday)(not actually what they are ) I will also have a form with the same fields so that you can update entries (their fav color and/or fav holiday). So far I know how to do this... Now is where I need HELP I also want is so that when an entry is added, the form/site/something sends me an email telling me the info. When an update is made to an entry, again I want an email but only telling me the info updated which could be the color and/or the holiday. If they only updated their holiday, I want the email to say "John Doe updated: Fav Holiday CLICK HERE TO VIEW ENTRY". Any suggestions, code, info, links greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/122723-email-me-changes-to-database/ Share on other sites More sharing options...
FVxSF Posted September 4, 2008 Share Posted September 4, 2008 This should be very simple. All you need to do is use the mail function built into php after the user updates. Like after the values are changed in the database. Take a look here: http://www.php.net/mail Quote Link to comment https://forums.phpfreaks.com/topic/122723-email-me-changes-to-database/#findComment-633804 Share on other sites More sharing options...
Brian W Posted September 4, 2008 Author Share Posted September 4, 2008 I'm using Dreamweaver, it automates most of the PHP for me... lol So I have some things in my code that I don't understand. <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> Normally, I know what to do with the POST function so that it goes to email, but the action right now is PHP being the front end to SQL to insert into my database. -Note- I'm trying to figure this out on one of my sandbox databases so that I don't mess up anything serious. This one is a simple username, pass, account level (Admin, User, View Only) <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } // *** Redirect if username exists $MM_flag="MM_insert"; if (isset($_POST[$MM_flag])) { $MM_dupKeyRedirect="?result=sorry"; $loginUsername = $_POST['Username']; $LoginRS__query = sprintf("SELECT Username FROM Users WHERE Username=%s", GetSQLValueString($loginUsername, "text")); mysql_select_db($database_MV_Users, $MV_Users); $LoginRS=mysql_query($LoginRS__query, $MV_Users) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); //if there is a row in the database, the username was found - can not add the requested username if($loginFoundUser){ $MM_qsChar = "?"; //append the username to the redirect page if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&"; $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername; header ("Location: $MM_dupKeyRedirect"); exit; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO Users (Username, Password, Rank) VALUES (%s, %s, %s)", GetSQLValueString($_POST['Username'], "text"), GetSQLValueString($_POST['Password'], "text"), GetSQLValueString($_POST['RadioGroup1'], "int")); mysql_select_db($database_MV_Users, $MV_Users); $Result1 = mysql_query($insertSQL, $MV_Users) or die(mysql_error()); $insertGoTo = "echo.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> echo.php is a not functioning right now but will be a page to echo the Username just entered into the db. The form though isn't actually posting so I can't seem to use echo $_POST['Username'] on the echo.php page to see it. IDK what is going on. Quote Link to comment https://forums.phpfreaks.com/topic/122723-email-me-changes-to-database/#findComment-633817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.