02. december 2006 - 14:03
Der er
5 kommentarer
Kan det lade sig gøre at submit knappen har to funktioner ?
Hej har sat et php kalenderscript op på min side det funker fint. Når man har skrevet en ny event i kalenderen skal man trykke på submit, så smider den eventen op i databasen ...fuldstændig som den skal :-) .... Men nu kommer mit spørgsmål ... Kan det lade sig gøre at submit knappen har to funktioner ? jeg vil nemlig gerne at den samtidig sender mig en mail om at nogen har skrevet i kalenderen. Sriptet ser således ud : <? include "config.php"; $db = mysql_connect($host,$login,$password); mysql_select_db($base,$db); //session_start(); if (!verifyuser() ) { header( "Location: ./login.php" ); } else { ?> <head> <title>myEvent <? echo $version ?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body bgcolor="#FFFFFF" topmargin="5" leftmargin="5" marginheight="5" marginwidth="5" ><center> <? if (isset($_POST["event_desc"])) { $event_desc = $_POST['event_desc']; } if (isset($_POST["submit"]) && (!isset($_POST["event_desc"]) or empty($event_desc) )) { ?> <script language="Javascript" type="text/javascript"> <!-- window.open('empty.html', '_myevent', 'HEIGHT=100,resizable=yes,WIDTH=400'); //--> </script> <? } if ( isset($_POST["submit"]) && !empty($event_desc)) { $eventyear = $_POST['eventyear']; $eventmonth = $_POST['eventmonth']; $eventdate = $_POST['eventdate']; $day_in_a_mth = date('t', mktime(0, 0, 0, $eventmonth, 1, $eventyear)) ; if ($day_in_a_mth >= $eventdate ) { $fulldate = $eventyear."-".$eventmonth."-".$eventdate; $event_desc = $_POST['event_desc']; $sql = "INSERT INTO event SET date='$fulldate', event_desc='$event_desc'"; $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error()); message( "ADD EVENT", "DATA ENTERED"); } else { message( "ERROR", "DATE ENTERED NOT VALID"); } } else { ?> <div width=90% class="genfont"><center>MyEvent Admin Center - Add Events</center></div> <form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" name="post"> <table width="90%" class="tdborder" cellSpacing=1 cellPadding=6 border=0> <tr> <td class="header" bgcolor="#6699ff"><center>EVENTS ENTRY</center></td></tr> <tr> <td> <table width="100%" class=tableborder cellSpacing=1 cellPadding=0 border=0> <tr> <td><div class="genfont"><b>Date</b></div> <div><select name="eventyear"> <option value="2004">2004 <option value="2005">2005 <option value="2006">2006 <option value="2007">2007 <option value="2008">2008 <option value="2009">2009 <option value="2010">2010 </select> <select name="eventmonth"> <option value="01">Jan <option value="02">Feb <option value="03">Mar <option value="04">Apr <option value="05">May <option value="06">Jun <option value="07">Jul <option value="08">Aug <option value="09">Sep <option value="10">Oct <option value="11">Nov <option value="12">Dec </select> <select name="eventdate"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 <option value="11">11 <option value="12">12 <option value="13">13 <option value="14">14 <option value="15">15 <option value="16">16 <option value="17">17 <option value="18">18 <option value="19">19 <option value="20">20 <option value="21">21 <option value="22">22 <option value="23">23 <option value="24">24 <option value="25">25 <option value="26">26 <option value="27">27 <option value="28">28 <option value="29">29 <option value="30">30 <option value="31">31 </select> </div> </td> </tr> </table> </td> <tr> <td><div class="genfont">Enter event :</div> <textarea name="event_desc" rows="4" cols="15" wrap="virtual" style="width:550px; font-size:12px" tabindex="3"></textarea> </td> </tr> <tr> <td><div align="center"> <input type="submit" value="Submit" name="submit" /></form></div> </td> </tr> </table> <? } } ?>
Annonceindlæg fra Kingston Technology
02. december 2006 - 14:10
#1
Ja altså lige efter du har udført query'en der indsætter event'en i databasen så laver du lige et par linieskift og indsætter en mail() funktion ? Eller forstår jeg ikke helt problemet? Du kan evt. bestemme alt hvad der skal ske når man har trykket på submit knappen sådan her: if (isset($_POST[knap])) { // alt herinde skal ske når der trykkes på submit knappen ved navn "knap" }
02. december 2006 - 14:21
#2
Jeg vil ha den til at sende mig en mail når der er en der har tilføjet noget i kalenderen ... kort sagt :-)
02. december 2006 - 14:29
#3
<? include "config.php"; $db = mysql_connect($host,$login,$password); mysql_select_db($base,$db); //session_start(); if (!verifyuser() ) { header( "Location: ./login.php" ); } else { ?> <head> <title>myEvent <? echo $version ?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body bgcolor="#FFFFFF" topmargin="5" leftmargin="5" marginheight="5" marginwidth="5" ><center> <? if (isset($_POST["event_desc"])) { $event_desc = $_POST['event_desc']; } if (isset($_POST["submit"]) && (!isset($_POST["event_desc"]) or empty($event_desc) )) { ?> <script language="Javascript" type="text/javascript"> <!-- window.open('empty.html', '_myevent', 'HEIGHT=100,resizable=yes,WIDTH=400'); //--> </script> <? } if ( isset($_POST["submit"]) && !empty($event_desc)) { $eventyear = $_POST['eventyear']; $eventmonth = $_POST['eventmonth']; $eventdate = $_POST['eventdate']; $day_in_a_mth = date('t', mktime(0, 0, 0, $eventmonth, 1, $eventyear)) ; if ($day_in_a_mth >= $eventdate ) { $fulldate = $eventyear."-".$eventmonth."-".$eventdate; $event_desc = $_POST['event_desc']; $sql = "INSERT INTO event SET date='$fulldate', event_desc='$event_desc'"; $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error()); $modtager = "DIN@MAIL.dk"; mail("$modtager", "Kalender event", "Der er blevet indsat noget i kalenderen", "FROM: noreply@site.dk"); echo "En mail er sendt."; message( "ADD EVENT", "DATA ENTERED"); }else { message( "ERROR", "DATE ENTERED NOT VALID"); } }else{ ?> <div width=90% class="genfont"><center>MyEvent Admin Center - Add Events</center></div> <form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" name="post"> <table width="90%" class="tdborder" cellSpacing=1 cellPadding=6 border=0> <tr> <td class="header" bgcolor="#6699ff"><center>EVENTS ENTRY</center></td></tr> <tr> <td> <table width="100%" class=tableborder cellSpacing=1 cellPadding=0 border=0> <tr> <td><div class="genfont"><b>Date</b></div> <div><select name="eventyear"> <option value="2004">2004 <option value="2005">2005 <option value="2006">2006 <option value="2007">2007 <option value="2008">2008 <option value="2009">2009 <option value="2010">2010 </select> <select name="eventmonth"> <option value="01">Jan <option value="02">Feb <option value="03">Mar <option value="04">Apr <option value="05">May <option value="06">Jun <option value="07">Jul <option value="08">Aug <option value="09">Sep <option value="10">Oct <option value="11">Nov <option value="12">Dec </select> <select name="eventdate"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 <option value="11">11 <option value="12">12 <option value="13">13 <option value="14">14 <option value="15">15 <option value="16">16 <option value="17">17 <option value="18">18 <option value="19">19 <option value="20">20 <option value="21">21 <option value="22">22 <option value="23">23 <option value="24">24 <option value="25">25 <option value="26">26 <option value="27">27 <option value="28">28 <option value="29">29 <option value="30">30 <option value="31">31 </select> </div> </td> </tr> </table> </td> <tr> <td><div class="genfont">Enter event :</div> <textarea name="event_desc" rows="4" cols="15" wrap="virtual" style="width:550px; font-size:12px" tabindex="3"></textarea> </td> </tr> <tr> <td><div align="center"> <input type="submit" value="Submit" name="submit" /></form></div> </td> </tr> </table> <? } } ?>
02. december 2006 - 16:22
#4
Tak det virker bare :-) super tak for hjælpen du skal lige have nogle point
02. december 2006 - 17:29
#5
Bare behold dem selv. Jeg samler nemlig ikke på dem :-)
Vi tilbyder markedets bedste kurser inden for webudvikling