max_power
04-24-2009, 11:58 AM
Hi, this php site is for an admin to add, delete and update events now for this one, it can only delete but can not perform the update_data1() and save_data1() functions for some wierd reason. Here is the php code:
<?php
include("includes/host_conf.php");
include("includes/mysql.lib.php");
$obj=new connect;
$mode=$_GET["mode"];
echo "<table width='550' border='0' cellpadding='4' cellspacing='1' bgcolor='#eeeeee' align='center'>";
echo "<tr>";
echo "<td colspan=3> <a href=\"javascript:requestInfo1('showTable.php?mode=new&id=$id','showTable','')\">Add New Events</a>||<a href=\"javascript:requestInfo1('showTable.php?mode=list','showTable','')\">Refresh</a></td>";
echo "</tr>";
echo "<tr>";
echo "<th> ID ";
echo "<th> Author";
echo "<th> Last Updated";
echo "<th> Category";
echo "<th> Event";
echo "<th> Summary";
echo "</tr>";
// For Delete
if($mode=="delete") {
$var_id=$_GET["id"];
$sqlDelete="Delete from events where id='$var_id'";
$obj->query($sqlDelete);
echo "<td><a href=\"javascript:delete_data();\">Delete</a>";
echo "<tr>";
echo "<td colspan=3>Data Deleted";
echo "</tr>";
}
// End of Delete
// For Add New Data -- Display Text box and the Cancel and Save Option
if($mode=="new") {
echo "<tr>";
echo "<td> <input id='id' size=5> ";
echo "<td> <input id='author' size=10> ";
echo "<td> <input id='last_updated' size=10> ";
echo '<td> <select name="category">
<option value="category1">category1</option>
<option value="category2">category2</option>
<option value="category3">category3</option>
<option value="category4">category4</option>
</select> ';
echo '<td> <textarea name="event" rows="12" cols="25"></textarea><td><textarea name="summary" rows="5" cols="25"></textarea> ';
echo "<td<a href=\"javascript:requestInfo1('showTable.php?mode=list&id=$id','showTable','')\">Cancel</a></td>";
echo "<td><a href=\"javascript:save_data1();\">Save</a>";
echo "</tr>";
}
// End of Add New Data
// After Click on Add >> Save option the data is save into the database
if($mode=="save_new") {
$id=$_GET["id"];
$author=$_GET["author"];
$last_updated=$_GET["last_updated"];
$category=$_GET["category"];
$event=$_GET["event"];
$summary=$_GET["summary"];
$sqlSave="Insert into events values('$id','$author','$last_updated','$category','$events','$summary')";
$obj->query($sqlSave);
echo "<tr>";
echo "<td colspan=3>Data Saved";
echo "</tr>";
}
// End of save_new
// For Update save Option
if($mode=="update_data") {
$id=$_GET["id"];
$author=$_GET["author"];
$last_updated=$_GET["last_updated"];
$category=$_GET["category"];
$event=$_GET["event"];
$summary=$_GET["summary"];
$sqlUpdate="Update events set id='$id', author = '$author', last_updated = '$last_updated', category = '$category', event = '$event', summary = '$summary' where id='$prev_id'";
$obj->query($sqlUpdate);
echo "<tr>";
echo "<td colspan=3>Data Updated";
echo "</tr>";
}
// End of Update
// Display all the data from the table
$sql="SELECT id,author,last_updated,category,event,summary FROM events order by id desc";
$obj->query($sql);
while($row=$obj->query_fetch(0)) {
$id=$row['id'];
$author=$row['author'];
$last_updated=$row['last_updated'];
$category=$row['category'];
$event=$row['event'];
$summary=$row['summary'];
echo "<tr bgcolor='#ffffff'>";
// if Mode is Update then get the ID and display the text field with value Other wise print the data into the table
if($mode=="update") {
$id_=$_GET["id"];
}
if($id_==$id) {
echo "<input type='hidden' value='$id_' name='prev_id' id='prev_id'>";
echo "<td> <input type='number' value='$id' id='id' size='5'> </td> ";
echo "<td> <input type='text' value='$author' id='author' size='10'> </td> ";
echo "<td> <input type='text' value='$last_updated' id='last_updated' size='10'> </td> ";
?><td> <select name="category">
<option><? echo $category; ?></option><? echo '
<option value="category1">category1</option>
<option value="category2">category2</option>
<option value="category3">category3</option>
<option value="category4">category4</option>
</select> ';
?><td> <textarea name="event" rows="12" cols="25"><? echo $event; ?></textarea><td><textarea name="summary" rows="5" cols="25"><? echo $summary; ?></textarea> <?
echo "<td> <a href=\"javascript:requestInfo1('showTable.php?mode=list&id=$id','showTable','')\">Cancel</a> </td> ";
echo "<td><a href=\"javascript:update_data1();\">Save</a>";
} else {
echo "<td>$id</td>";
echo "<td>$author</td>";
echo "<td>$last_updated</td>";
echo "<td>$category</td>";
echo "<td>$event</td>";
echo "<td>$summary</td>";
echo "<td> <a href=\"javascript:requestInfo1('showTable.php?mode=update&id=$id','showTable','')\">Update</a> </td> ";
echo "<td> <a href=\"javascript:requestInfo1('showTable.php?mode=delete&id=$id','showTable','');\" onclick='return confirmLink(this);'>Delete</a></td>";
}
echo "</tr>";
}
echo "</table>";
?>
I'll post the javascript code next in a separate post as the characters go over the limit.
<?php
include("includes/host_conf.php");
include("includes/mysql.lib.php");
$obj=new connect;
$mode=$_GET["mode"];
echo "<table width='550' border='0' cellpadding='4' cellspacing='1' bgcolor='#eeeeee' align='center'>";
echo "<tr>";
echo "<td colspan=3> <a href=\"javascript:requestInfo1('showTable.php?mode=new&id=$id','showTable','')\">Add New Events</a>||<a href=\"javascript:requestInfo1('showTable.php?mode=list','showTable','')\">Refresh</a></td>";
echo "</tr>";
echo "<tr>";
echo "<th> ID ";
echo "<th> Author";
echo "<th> Last Updated";
echo "<th> Category";
echo "<th> Event";
echo "<th> Summary";
echo "</tr>";
// For Delete
if($mode=="delete") {
$var_id=$_GET["id"];
$sqlDelete="Delete from events where id='$var_id'";
$obj->query($sqlDelete);
echo "<td><a href=\"javascript:delete_data();\">Delete</a>";
echo "<tr>";
echo "<td colspan=3>Data Deleted";
echo "</tr>";
}
// End of Delete
// For Add New Data -- Display Text box and the Cancel and Save Option
if($mode=="new") {
echo "<tr>";
echo "<td> <input id='id' size=5> ";
echo "<td> <input id='author' size=10> ";
echo "<td> <input id='last_updated' size=10> ";
echo '<td> <select name="category">
<option value="category1">category1</option>
<option value="category2">category2</option>
<option value="category3">category3</option>
<option value="category4">category4</option>
</select> ';
echo '<td> <textarea name="event" rows="12" cols="25"></textarea><td><textarea name="summary" rows="5" cols="25"></textarea> ';
echo "<td<a href=\"javascript:requestInfo1('showTable.php?mode=list&id=$id','showTable','')\">Cancel</a></td>";
echo "<td><a href=\"javascript:save_data1();\">Save</a>";
echo "</tr>";
}
// End of Add New Data
// After Click on Add >> Save option the data is save into the database
if($mode=="save_new") {
$id=$_GET["id"];
$author=$_GET["author"];
$last_updated=$_GET["last_updated"];
$category=$_GET["category"];
$event=$_GET["event"];
$summary=$_GET["summary"];
$sqlSave="Insert into events values('$id','$author','$last_updated','$category','$events','$summary')";
$obj->query($sqlSave);
echo "<tr>";
echo "<td colspan=3>Data Saved";
echo "</tr>";
}
// End of save_new
// For Update save Option
if($mode=="update_data") {
$id=$_GET["id"];
$author=$_GET["author"];
$last_updated=$_GET["last_updated"];
$category=$_GET["category"];
$event=$_GET["event"];
$summary=$_GET["summary"];
$sqlUpdate="Update events set id='$id', author = '$author', last_updated = '$last_updated', category = '$category', event = '$event', summary = '$summary' where id='$prev_id'";
$obj->query($sqlUpdate);
echo "<tr>";
echo "<td colspan=3>Data Updated";
echo "</tr>";
}
// End of Update
// Display all the data from the table
$sql="SELECT id,author,last_updated,category,event,summary FROM events order by id desc";
$obj->query($sql);
while($row=$obj->query_fetch(0)) {
$id=$row['id'];
$author=$row['author'];
$last_updated=$row['last_updated'];
$category=$row['category'];
$event=$row['event'];
$summary=$row['summary'];
echo "<tr bgcolor='#ffffff'>";
// if Mode is Update then get the ID and display the text field with value Other wise print the data into the table
if($mode=="update") {
$id_=$_GET["id"];
}
if($id_==$id) {
echo "<input type='hidden' value='$id_' name='prev_id' id='prev_id'>";
echo "<td> <input type='number' value='$id' id='id' size='5'> </td> ";
echo "<td> <input type='text' value='$author' id='author' size='10'> </td> ";
echo "<td> <input type='text' value='$last_updated' id='last_updated' size='10'> </td> ";
?><td> <select name="category">
<option><? echo $category; ?></option><? echo '
<option value="category1">category1</option>
<option value="category2">category2</option>
<option value="category3">category3</option>
<option value="category4">category4</option>
</select> ';
?><td> <textarea name="event" rows="12" cols="25"><? echo $event; ?></textarea><td><textarea name="summary" rows="5" cols="25"><? echo $summary; ?></textarea> <?
echo "<td> <a href=\"javascript:requestInfo1('showTable.php?mode=list&id=$id','showTable','')\">Cancel</a> </td> ";
echo "<td><a href=\"javascript:update_data1();\">Save</a>";
} else {
echo "<td>$id</td>";
echo "<td>$author</td>";
echo "<td>$last_updated</td>";
echo "<td>$category</td>";
echo "<td>$event</td>";
echo "<td>$summary</td>";
echo "<td> <a href=\"javascript:requestInfo1('showTable.php?mode=update&id=$id','showTable','')\">Update</a> </td> ";
echo "<td> <a href=\"javascript:requestInfo1('showTable.php?mode=delete&id=$id','showTable','');\" onclick='return confirmLink(this);'>Delete</a></td>";
}
echo "</tr>";
}
echo "</table>";
?>
I'll post the javascript code next in a separate post as the characters go over the limit.