Gå til innhold

Kalender - databaseproblemer


Anbefalte innlegg

Fant denne "flotte" kalenderen på nettet, virkelig noe for meg og min side. Men får den ikke til å virke skikkelig.

 

Kanskje noen kan se på den? Det er kommunikasjonen med database som ikke virker skikkelig. Den har kontakt osv, men det "skjer" ikke noe.

 

Hvis noen har tips til forbedriner osv så mottas disse med takk.

 

PS jeg har selvsagt fjerne mine database-info.

 

Cal.php

 

<?php
echo "
<html>
<head>
<body bgcolor=#FFFFFF>
<center>
";



// Check for a Month Change submission

if (isset($_POST['submit'])) {
$submit = $_POST['submit'];
$month_now = $_POST["month_now"];
$year_now = $_POST["year_now"];


// Subtract one from the month for previous, add one for next

if ($submit == "Prev") {
$month_now--;
} else {
$month_now++; }

$date = getdate(mktime(0,0,0,$month_now,1,$year_now));

} else {
$date = getdate();
}

$month_num = $date["mon"];
$month_name = $date["month"];
$year = $date["year"];
$date_today = getdate(mktime(0,0,0,$month_num,1,$year));
$first_week_day = $date_today["wday"];
$cont = true;
$today = 27;

while (($today <= 32) && ($cont)) {
$date_today = getdate(mktime(0,0,0,$month_num,$today,$year));

if ($date_today["mon"] != $month_num) {
$lastday = $today - 1;
$cont = false;
}

$today++;
}

// allow for form submission to the script for forward and backwards

echo"
<form action=\"cal.php\" method=\"POST\" name=\"calendar\">

<input type=\"hidden\" name=\"month_now\" value=\"$month_num\">
<input type=\"hidden\" name=\"year_now\" value=\"$year\">
<table width=\"200\">
<tr><td><input type=\"submit\" name=\"submit\" value=\"Prev\"></td>
   <td align=right><input
type=\"submit\" name=\"submit\" value=\"Next\"></td>
</tr>
</table>
</form>


<table width=\"160\" border=\"1\" cellspacing=0 cellpadding=2>
<tr><td colspan=\"7\">$month_name $year</td></tr>
<tr><td>Su</td><td>M</td><td>T</td><td>W</td><td>Th</td><td>F</td><td>Sat</td></
tr>";

// begin placement of days according to their beginning weekday

$day = 1;
$wday = $first_week_day;
$firstweek = true;
while ( $day <= $lastday) {
if ($firstweek) {
echo "<TR>";
for ($i=1; $i<=$first_week_day; $i++) {

echo "<TD>  </td>";
}
$firstweek = false;
}
if ($wday==0) {
echo "<tr>";
}

// make each day linkable to the following result.php page


if ( intval($month_num) < 10) { $new_month_num = "0$month_num"; }
elseif (intval($month_num) >= 10) { $new_month_num = $month_num; }
if ( intval($day) < 10) { $new_day = "0$day"; }
elseif (intval($day) >= 10) { $new_day = $day; }
$link_date = "$year-$new_month_num-$new_day";


echo "<td><a href=results.php?eventid=$link_date> $day </a></td>";

if ($wday==6) {
echo "</tr>\n";
}

$wday++;
$wday = $wday % 7;
$day++;
}
echo"
</table>
</body>
</html>
";
?>

 

results.php

 

<?php

echo "<html><body bgcolor=#FFFFFF>";
echo "<form method=\"POST\" action=\"results.php\">";


$db = mysql_connect("**********", "*********", "*******");
mysql_select_db("**********",$db);


if ($del) {
$array = explode(",",$delete);
$sql = "DELETE FROM calendar WHERE userid='$array[0]' AND received='$array[1]'";
$result = mysql_query($sql, $db) or die ("Invalid query");
}
if ($submit) {
$eventid=$_REQUEST['eventid'];
$hour=$_REQUEST['hour'];
$event_finish=$_REQUEST['event_finish'];
$event_type=$_REQUEST['event_type'];
$userid=$_REQUEST['userid'];
$event=$_REQUEST['event'];

$event_id = "$eventid $hour:00:00";
$durhour = $hour + $event_finish;
$event_finish = "$eventid $durhour:00:00";
$sql = "INSERT INTO calendar
(received,event,userid,event_type,event_finish) VALUES('$event_id','$event','$userid', '$event_type', '$event_finish')";
$result = mysql_query($sql, $db) or die ("Invalid query");

echo "<b>Submission Added</b><br><br>";
}

$sql = "SELECT * from calendar where received LIKE '$eventid%' ORDER BY
received";
$result = mysql_query($sql, $db) or die ("Invalid query");

if (!mysql_num_rows($result)) {
echo "I'm sorry, but there are no events for that date.";
} else {
echo "For $eventid the following events have been located:";}
?>

<br><hr noshade>
<table cellpadding=0 cellspacing=0 width=200>
<tr><td>
<table border=1>
<tr><td>Start Time</td><td>Event</td>
<td>Event Type</td><td>Event Finish</td>
<td>UserID</td><td>Delete?</td>
</tr>

<?php

while ($row = mysql_fetch_array($result)){

echo "<tr><td>$row[received]</td><td>";
echo "$row[event]</td><td>";
echo "$row[event_type]</td><td>";
echo "$row[event_finish]</td><td>";
echo "$row[userid]</td><td>";
echo "<input
type=\"radio\" value=\"$row[userid],$row[received]\" name=\"delete\"></td></tr>";

}

?>
</table>
</td>
</tr>
</table>
<input type="hidden" name="eventid" value="<?php echo $eventid;?>">
<input type="submit" name="del" value="Delete Event">
</form>
<form method="POST" action="results.php"><br><br>
Add an Event for <?php echo "$eventid";?>
<input type="hidden" name="eventid" value="<?php echo $eventid;?>"><br>
Hour:
<select name="hour">
<option value="1">1.00
<option value="2">2.00
<option value="3">3.00
<option value="4">4.00
<option value="5">5.00
<option value="6">6.00
<option value="7">7.00
<option value="8">8.00
<option value="9">9.00
<option value="10">10.00
<option value="11">11.00
<option value="12">12.00
<option value="13">13.00
<option value="14">14.00
<option value="15">15.00
<option value="16">16.00
<option value="17">17.00
<option value="18">18.00
<option value="19">19.00
<option value="20">20.00
<option value="21">21.00
<option value="22">22.00
<option value="23">23.00
</select>
<br>
Event Information:<br>
<textarea name="event" cols="20" rows="5"></textarea>
<br>
UserID:<br>
<input type="text" name="userid"><br>
Event Type:<br>
<input type="text" name="event_type"><br>
Event Duration (in hours):<br>
<input type="text" name="event_finish"><br>
<input type="submit" name="submit" value="Add Event">
</form>
<a href="cal.php">Back to the Calendar</a>
</body></html>

 

Beklager rotete koding

Lenke til kommentar
Videoannonse
Annonse

Det er jo akkurat det, det skjer ikke noe som helst. Feks kan jeg legge inn en ny "event" og trykke add. Så blinker skjermbildet og feltene tømmes, men ingenting skjer.

 

Eller når jeg sletter, trykk del - ingenting skjer.

 

Ellers så er jo kalenderen pen å se på da :dribble:

Lenke til kommentar
Gjest Slettet-rXRozPkg

Dette må være gammel kode, siden den krever at register globals er på.

I cal.php er det gjort "rett", mens i results.php er det galt.

 

Bytt ut:

if ($del) {
  blabla...
}
if ($submit) {
  blabla...
}

 

Med:

if ($_POST['del']) {
  $array = explode(",",$_POST['delete']);
  blabla...
}
if ($_POST['submit']) {
  blabla...
}

 

Nå burde du få litt bedre reaksjon (eller kanskje en feilmelding fra databasen :) ).

Endret av Slettet-rXRozPkg
Lenke til kommentar

Glimrende, nå virker database delen helt fint.

 

Nå oppdaget jeg at datoene ikke virker skikkelig, når jeg velger en dato å lagre på så blir det lagret på feks 0002-00-00 dvs år 2. En stund siden det da :!:

 

Jeg får finlese litt i kodene, om noen har ett tips er jeg takknemlig for det.

Lenke til kommentar

Nå har jeg finlest og rettet opp i noen variabler, men nye problemer dukker opp.

 

Når jeg lagrer på en dato blir det nå lagret på riktig dato, men når "eventen" skal hentes frem igjen så finner ikke programmet noe som helst.

 

$sql = "SELECT * from calendar WHERE received LIKE '$eventid' ORDER BY received"; 
$result = mysql_query($sql, $db) or die ("Invalid query"); 

 

Jeg bruker denne koden, den skal da virke? Jeg legger med hele results.php, med alle rettelser. :hmm:

 

<?php 

echo "<html><body bgcolor=#FFFFFF>"; 
echo "<form method=\"POST\" action=\"results.php\">"; 

//Kobler til database
************************

$eventid=$_GET['eventid'];


//Slette poster
if ($_POST['del']) { 
$array = explode(",",$_POST['delete']); 
$sql = "DELETE FROM calendar WHERE userid='$array[0]' AND received='$array[1]'"; 
$result = mysql_query($sql, $db) or die ("Invalid query"); 
} 

//Legge til poster
if ($_POST['submit']) { 
$eventid=$_POST['eventid'];    //Dato    	
$hour=$_POST['hour'];    	//Klokkeslett i hele timer
$event_finish=$_POST['event_finish'];  	//Hvor mange timer hendelsen varer
$event_type=$_POST['event_type'];  	//Hvilken type hendlelse  	Skal i databasen
$userid=$_POST['userid'];    //Bruker ID    	Skal i databasen
$event=$_POST['event'];    	//Teksten til hendelese    Skal i databasen
$event_id = "$eventid $hour:00:00";    //Dato + klokkeslett - 00:00  	Skal i databasen
$durhour = $hour + $event_finish;    //Slutttid
$event_finish = "$eventid $durhour:00:00";  	//Dato +sluttid    	Skal i databasen

$sql = "INSERT INTO calendar (received,event,userid,event_type,event_finish) VALUES('$event_id','$event','$userid', '$event_type', '$event_finish')"; 
$result = mysql_query($sql, $db) or die ("Invalid query"); 

echo "<b>Submission Added</b><br><br>"; 
} 



//Liste opp innhold i kalenderen

$sql = "SELECT * from calendar WHERE received LIKE '$eventid' ORDER BY received"; 
$result = mysql_query($sql, $db) or die ("Invalid query"); 

//Hvis det ikke er noe for denne datoen
if (!mysql_num_rows($result)) { 
echo "I'm sorry, but there are no events for that date. $eventid"; 
} else { 
echo "For $eventid the following events have been located:";} 
?> 

<br><hr noshade> 
<table cellpadding=0 cellspacing=0 width=200> 
<tr><td> 
<table border=1> 
<tr><td>Start Time</td><td>Event</td> 
<td>Event Type</td><td>Event Finish</td> 
<td>UserID</td><td>Delete?</td> 
</tr> 

<?php 

while ($row = mysql_fetch_array($result)){ 

echo "<tr><td>$row[received]</td><td>"; 
echo "$row[event]</td><td>"; 
echo "$row[event_type]</td><td>"; 
echo "$row[event_finish]</td><td>"; 
echo "$row[userid]</td><td>"; 
echo "<input 
type=\"radio\" value=\"$row[userid],$row[received]\" name=\"delete\"></td></tr>"; 

} 

?> 
</table> 
</td> 
</tr> 
</table> 
<input type="hidden" name="eventid" value="<?php echo $eventid;?>"> 
<input type="submit" name="del" value="Delete Event"> 
</form>

<form method="POST" action="results.php"><br><br>

<input type="hidden" name="eventid" value="<?php echo $eventid;?>"> 

Add an Event for <?php echo "$eventid";?> 
<br> 
Hour: 
<select name="hour"> 
<option value="1">1.00
<option value="2">2.00 
<option value="3">3.00 
<option value="4">4.00 
<option value="5">5.00 
<option value="6">6.00 
<option value="7">7.00 
<option value="8">8.00 
<option value="9">9.00 
<option value="10">10.00 
<option value="11">11.00 
<option value="12">12.00 
<option value="13">13.00 
<option value="14">14.00 
<option value="15">15.00 
<option value="16">16.00 
<option value="17">17.00 
<option value="18">18.00 
<option value="19">19.00 
<option value="20">20.00 
<option value="21">21.00 
<option value="22">22.00 
<option value="23">23.00 
</select> 
<br> 

Event Information:<br> 
<textarea name="event" cols="20" rows="5"></textarea> 
<br> 

UserID:<br> 
<input type="text" name="userid"><br> 

Event Type:<br> 
<input type="text" name="event_type"><br> 

Event Duration (in hours):<br> 
<input type="text" name="event_finish"><br> 

<input type="submit" name="submit" value="Add Event"> 

</form> 
<a href="cal.php">Back to the Calendar</a> 
</body></html> 

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...