manageBookmarks.php
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<link href="css/default.css" rel="stylesheet" type="text/css"></head><body>
<?php
include("header.php");
session_start();
echo $_SESSION['sname']." sname_val: ".$_SESSION['sname_val']." ".$_SESSION['stype']." stype_val: ".$_SESSION['stype_val']." ".$_SESSION['saddy']." saddy_val: ".$_SESSION['saddy_val']." scomm: ".$_SESSION['scomm_val'];
?>
<p/>
<p><b>Manage Bookmarks</b>
<?php
if(isset($_SESSION['empty'])){
echo "<b><font color=\"red\"> - Incomplete fields. Please complete them.</font></b>";
unset($_SESSION['empty']);
}
?>
</p>
<form name="addBookmarksFrm" method="post" action="addBookmarks.php">
<p/>Add Bookmarks:
<p/>Site Name: <input type="text" name="sitename">
<?php
if(isset($_SESSION['sname_val'])){
$val = $_SESSION['sname_val'];
echo $val;
unset($_SESSION['sname_val']);
}
?>
</input>
<?php
if(isset($_SESSION['sname'])){
if($_SESSION['sname']){
echo "<b><font color=\"red\"> * </font></b>";
}
unset($_SESSION['sname']);
}
?>
<p/>Site Type: <input type="text" name="sitetype">
<?php
if(isset($_SESSION['stype_val'])){
$val = $_SESSION['stype_val'];
echo $val;
unset($_SESSION['stype_val']);
}
?>
</input>
<?php
if(isset($_SESSION['stype'])){
if($_SESSION['stype']){
echo "<b><font color=\"red\"> * </font></b>";
}
unset($_SESSION['stype']);
}
?>
<p/>Site Address: <input type="text" name="siteaddress">
<?php
if(isset($_SESSION['saddy_val'])){
$val = $_SESSION['saddy_val'];
echo $val;
unset($_SESSION['saddy_val']);
}
?>
</input>
<?php
if(isset($_SESSION['saddy'])){
if($_SESSION['saddy']){
echo "<b><font color=\"red\"> * </font></b>";
}
unset($_SESSION['saddy']);
}
?>
<p/>Comments: </br>
<textarea rows="7" cols=37" name="sitecomment">
<?php
if(isset($_SESSION['scomm_val'])){
$val = $_SESSION['scomm_val'];
echo $val;
unset($_SESSION['scomm_val']);
}
?>
</textarea>
<p/>
<?php session_destroy();?>
<input type="reset" value="Clear" /> <input type="submit" value="Submit" />
</form>
<?php include("footer.php"); ?>
</body></html>
Code: Select all
<?php
//include("debug.php");
session_start();
$sname = $_POST["sitename"];
$stype = $_POST["sitetype"];
$saddy = $_POST["siteaddress"];
$scomm = $_POST["sitecomment"];
if(!checkFields($sname,$stype,$saddy,$scomm)){
//echo "Fields checked";
$conn = mysql_connect("localhost:3306","root","faefolks");
//echo "Conn = ".$conn;
if(!$conn){
die("Could not connect: ".mysql_error());
} else {
mysql_select_db("bookmarks",$conn);
$rs = mysql_query("select TypeId from bookmarktypes where TypeName = '$stype'");
$row = mysql_fetch_array($rs);
if($row > 0 ){
//Data found, continue to add...
//echo "<html>Data found </html>";
echo 'row - '.$row['TypeId'];
addBookmarks($conn,$row['TypeId'],$sname,$saddy,$scomm);
} else {
//No data... insert a valid one
$rs = mysql_query("insert into bookmarktypes (TypeName) values ('$stype')");
if (!$rs){
die('Error, add book mark types: '.mysql_error());
} else {
$rs = mysql_query("select TypeId from bookmarktypes where TypeName = '$stype'");
$row = mysql_fetch_array($rs);
if($row > 0 ){
addBookmarks($conn,$row['TypeId'],$sname,$saddy,$scomm);
}
}
}
}
} else {
header("Location: manageBookmarks.php");
}
mysql_close($conn);
//Refresh page once
function addBookmarks($conn,$stype_id,$sname,$saddy,$scomment){
$sql = "insert into bookmarks.bookmarks (`SiteName`, `SiteType`, `SiteAddress`, `Comments`) values ('$sname','$stype_id','$saddy','$scomment')";
$rs = mysql_query($sql,$conn);
if (!$rs){
die('Error, addBookmarks(): '.mysql_error());
} else {
//echo "window.alert('Successfully added site: $sname')";
header("Location: bookmarks.php");
}
}
function checkFields($sname,$stype,$saddy,$scomm){
$isEmpty = false;
if(empty($sname)||$sname==""){
$_SESSION['sname_val']=$sname;
$_SESSION['sname']=true;
$isEmpty = true;
}
if(empty($stype)||$stype==""){
$_SESSION['stype_val']=$stype;
$_SESSION['stype']=true;
$isEmpty = true;
}
if(empty($saddy)||$saddy==""){
$_SESSION['saddy_val']=$saddy;
$_SESSION['saddy']=true;
$isEmpty = true;
}
if($isEmpty === true){
$_SESSION['empty']=true;
$_SESSION['scomm_val']=$scomm;
}
return $isEmpty;
}
?>