<?php
session_start();
if (isset($_SESSION['username'])){
$loginstatus = "logout";
$username = $_SESSION['username'];
include_once('inc/connect.php');
$siteid = $_GET['siteid'];
$message = "messagebox";
$success = " ";
$error = " ";
$useridquery = "SELECT id FROM users WHERE username='$username'";
$useridresult = mysql_query($useridquery);
$useridrow = mysql_fetch_assoc($useridresult);
$userid = $useridrow['id'];
$result1 = mysql_query("SELECT * FROM websites WHERE `id`='$siteid' && userid='$userid'");
$siterow1 = mysql_fetch_assoc($result1);
$titledb = $siterow1['title'];
$urldb = $siterow1['url'];
$maxviewsdb = $siterow1['dailyviews'];
$statusdb = $siterow1['active'];
$titlenew = $_POST['title'];
$urlnew = $_POST['url'];
$maxviewsnew = $_POST['maxviews'];
$statusnew = $_POST['status'];
if($statusnew=="Active"){
$statusnew = "yes";
}
else{
$statusnew = "no";
}
$editnewsite = $_POST['editnewsite'];
if($success!=""){
$message = "";
}
else{
$message = "messagesuccess";
}
// $siteid will Echo up until here. After this point it stops working.
if($editnewsite){
if($titlenew){
if($urlnew){
if($maxviewsnew){
function valid_url($urlnew)
{
return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $urlnew)) ? FALSE : TRUE;
}
if(valid_url($urlnew)){
//Check if URL is a Duplicate for current user
$results = mysql_query("SELECT * FROM `websites` WHERE `userid`='$userid' AND `url`='$url'");
$rows = mysql_num_rows($results);
if ($rows<=0)
{
$siteidnew = $siteid;
// Problem lies in this query.
$update = "UPDATE `websites` SET `title`='$titlenew', `url`='$urlnew', `dailyviews`='$maxviewsnew', `active`='$statusnew' WHERE `id`='$siteid' && `userid`='$userid'";
mysql_query($update);
$titledb = $titlenew;
$urldb = $urlnew;
$maxviewsdb = $maxviewsnew;
$statusdb = $statusnew;
echo $titledb;
echo $urldb.$maxviewsdb.$statusdb."<br>".$siteid;
// PROBLEM HERE
exit();
}
else{
$error = "You have already submitted that site";
$message = "messageerror";
}
} // here
else {
$error = "Invalid URL";
$message = "messageerror";
}
}
else{
$error = "Type in the Maximum Views you<br />want your site to get daily!";
$message = "messageerror";
}
}
else{
$error = "Type in the Url of your website!";
$message = "messageerror";
}
}
else{
$error = "Type in a Title for your site!";
$message = "messageerror";
}
}
}
else{
$loginstatus = "login";
header("Location: index.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content="Free Piano Sheet Music - Sheet Music Haven" />
<meta name="keywords" content="Piano,Sheet,Music,Haven,Score,Piece,Top,Trade" />
<meta name="author" content="Sheet Music Haven" />
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
<title>Edit Sites - Sheet Music Haven</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
<link rel="stylesheet" type="text/css" href="styles/editsites.css" />
<script type="text/javascript">
function make_blank()
{
if(document.login.username.value =="Username"){
document.login.username.value ="";
document.login.username.style.color ="#000000";
}
}
function make_blank1()
{
if(document.login.password.value =="Password"){
document.login.password.value ="";
document.login.password.type ="password";
document.login.password.style.color ="#000000";
}
}
function undoBlank() {
if(document.login.username.value == ""){
document.login.username.value ="Username";
document.login.username.style.color="#ccc";
}
}
function undoBlankpass() {
if(document.login.password.value == ""){
document.login.password.value ="Username";
document.login.password.style.color="#cccccc";
}
}
function inputLimiter(e,allow) {
var AllowableCharacters = '';
if (allow == 'NumbersOnly'){AllowableCharacters='1234567890';}
var k;
k=document.all?parseInt(e.keyCode): parseInt(e.which);
if (k!=13 && k!=8 && k!=0){
if ((e.ctrlKey==false) && (e.altKey==false)) {
return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
} else {
return true;
}
} else {
return true;
}
}
</script>
</head>
<body bgcolor="#343331">
<!-- Header -->
<div id="header">
<div id="headerleft"></div>
<div id="headermiddle"><a href="index.php"><img src="img/logo.png"></a></div>
<div id="headerright">
<?php echo "<form name='login' action='inc/$loginstatus.php' method='POST'>";?>
<div class="loginboxdiv" id="username">
<input type="text" class="loginbox" name="username" value="Username" onFocus="make_blank();" onBlur="undoBlank();">
</div>
<div class="loginboxdiv" id="password">
<input class="loginbox" type="text" name="password" type="text" value="Password" onFocus="make_blank1();" onBlur="undoBlankpass();">
</div>
<div id="login">
<?php echo "<input type='image' src='img/$loginstatus.png' alt='".ucfirst($loginstatus)."'>";?>
</div>
</form>
<div id="register">
<a href="register.php"><img src="img/register.png"></a>
</div>
<div id="forgotpassword">
<a href="resetpassword.php" class="forgot">Forgot Password?</a>
</div>
</div>
</div>
<!-- Content Top -->
<div id="contenttop">
<div id="links">
<table cols="7">
<tr>
<td align="center" valign="middle" width="100px" height="48px"><a href="index.php"><img src="img/home.png"></a></td>
<td align="center" valign="middle" width="100px" height="48px"><a href="member.php"><img src="img/member.png"></a></td>
<td align="center" valign="middle" width="100px" height="48px"><a href="addsheet.php"><img src="img/addsheet.png"></a></td>
<td align="center" valign="middle" width="100px" height="48px"><a href="advertise.php"><img src="img/advertise1.png"></a></td>
<td align="center" valign="middle" width="100px" height="48px"><a href="faq.php"><img src="img/faq.png"></a></td>
<td align="center" valign="middle" width="100px" height="48px"><a href="terms.php"><img src="img/terms.png"></a></td>
<td align="center" valign="middle" width="100px" height="48px"><a href="contact.php"><img src="img/contact.png"></a></td>
</tr>
</table>
<!-- 92x30 -->
</div>
</div>
<!-- Content Middle -->
<div id="contentmiddle">
<div id="content">
<div id="headeditsites"></div>
<br />
<div id="editsite">
<form action="editsites.php" method="post" name="newsite">
Title: <input type="text" name="title" value="<?php echo $titledb; ?>"><br />
Url: <input type="text" name="url" value="<?php echo $urldb; ?>"><br />
Max Views: <input type="text" maxlength="11" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" name="maxviews" value="<?php echo $maxviewsdb; ?>"><br />
<select name="status"><option value='Active' name='active'>Active</option><option value='Passive' name='passive'>Passive</option></select><br /><br />
<center><input type="submit" name="editnewsite" value="Edit Site"></center>
</form>
</div>
</div>
</div>
<!-- Content Bottom -->
<div id="contentbottom">
</div>
</body>
</html>