├── README.md ├── createtables.sql ├── db.php ├── dbregister.php ├── dbsubmitpost.php ├── images ├── downvote.gif ├── favicon.ico ├── logo.jpg ├── logo.png └── upvote.gif ├── index.php ├── logout.php ├── signup.php ├── styles └── style.css ├── submit.php ├── viewpost.php └── vote.php /README.md: -------------------------------------------------------------------------------- 1 | # redditclone 2 | Made this Reddit Clone Just For Fun. 3 | -------------------------------------------------------------------------------- /createtables.sql: -------------------------------------------------------------------------------- 1 | create table t_users( 2 | username VARCHAR(30), 3 | fullname VARCHAR(30), 4 | password VARCHAR(20), 5 | email VARCHAR(254), 6 | PRIMARY KEY (username)); 7 | 8 | create table t_news( 9 | id integer AUTO_INCREMENT, 10 | username VARCHAR(30) not null, 11 | news VARCHAR(500), 12 | ts timestamp default now(), 13 | score integer default 0, 14 | PRIMARY KEY (id)); 15 | 16 | create table t_pluses( 17 | id integer AUTO_INCREMENT, 18 | username VARCHAR(30), 19 | newsid integer, 20 | score integer default 1, 21 | ts timestamp default now(), 22 | PRIMARY KEY (id)); 23 | -------------------------------------------------------------------------------- /db.php: -------------------------------------------------------------------------------- 1 | error); 8 | 9 | // Check connection 10 | if ($mysqli->connect_error) { 11 | die("Connection failed: " . $mysqli->connect_error); 12 | } 13 | echo "Connected successfully"; 14 | ?> 15 | -------------------------------------------------------------------------------- /dbregister.php: -------------------------------------------------------------------------------- 1 | window.location.assign('index.php'); "; 19 | } else { 20 | echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); 21 | } 22 | mysqli_close($link); 23 | ?> 24 | -------------------------------------------------------------------------------- /dbsubmitpost.php: -------------------------------------------------------------------------------- 1 | window.location.assign('index.php'); "; 20 | } else { 21 | echo $_SESSION['uname']; 22 | echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); 23 | } 24 | mysqli_close($link); 25 | ?> 26 | -------------------------------------------------------------------------------- /images/downvote.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roshanlam/redditclone/9200a827fdc6e2bb37f7f5b0098066316d071a16/images/downvote.gif -------------------------------------------------------------------------------- /images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roshanlam/redditclone/9200a827fdc6e2bb37f7f5b0098066316d071a16/images/favicon.ico -------------------------------------------------------------------------------- /images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roshanlam/redditclone/9200a827fdc6e2bb37f7f5b0098066316d071a16/images/logo.jpg -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roshanlam/redditclone/9200a827fdc6e2bb37f7f5b0098066316d071a16/images/logo.png -------------------------------------------------------------------------------- /images/upvote.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roshanlam/redditclone/9200a827fdc6e2bb37f7f5b0098066316d071a16/images/upvote.gif -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | Reddit Clone 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second'); 22 | foreach ($tokens as $unit => $text) { 23 | if ($time < $unit) continue; 24 | $numberOfUnits = floor($time / $unit); 25 | return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); 26 | } 27 | } 28 | ?> 29 | 30 | '; 43 | } else { 44 | echo '
'; 45 | } 46 | ?> 47 | 48 |
49 |
' . $score . '
' . $title . '

66 | submitted by ' . $username . ' '; 67 | echo timeSince(strtotime($row['ts'])) . ' ago, add a comment

'; 68 | } 69 | } else { 70 | echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); 71 | } 72 | $id = $row['id']; 73 | ?> 74 | "; }?> 75 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /logout.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /signup.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Reddit Clone 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 41 | query($query); 55 | $n = $sql->num_rows; 56 | // if $n is > 0 it mean account exists 57 | if($n > 0){ 58 | $_SESSION['uname'] = $username; 59 | $_SESSION['logged_in'] = true; 60 | header('Location: index.php'); 61 | } else { 62 | //echo "alert(Incorrect username or password.)"; 63 | echo ''; 68 | } 69 | } 70 | ?> 71 | 72 | 73 | 74 | 75 | '; 86 | } else { 87 | echo '
88 |
'; 89 | } 90 | ?> 91 | 92 | 93 |
94 |

Create a new account

95 |
96 | 97 | 98 | 99 | 100 |
101 | 102 |
103 |
104 |
105 |

or just sign into an existing one.

106 |
107 | 108 |
109 | 110 |
111 |
112 | 113 | 114 | -------------------------------------------------------------------------------- /styles/style.css: -------------------------------------------------------------------------------- 1 | /* A New Design Will Come Out Soon 2 | * CSS Coded By Roshan Lamichhane 3 | */ 4 | 5 | * { 6 | margin: auto; 7 | } 8 | 9 | body { 10 | background-color: rgb(42, 42, 42); 11 | font-family: 'Roboto', sans-serif; 12 | } 13 | 14 | .navbar { 15 | height: 70px; 16 | width: 100%; 17 | border-bottom: 10px solid #16a085; 18 | background-color: #D3D3D3; 19 | display: flex; 20 | } 21 | 22 | #logo { 23 | float: left; 24 | color: #ecf0f1; 25 | margin-top: 10px; 26 | margin-left: 10px; 27 | font-family: 'Roboto', sans-serif; 28 | } 29 | 30 | #logo img { 31 | width: auto; 32 | height: auto; 33 | max-width: 110px; 34 | max-height: 96px; 35 | } 36 | 37 | #right-side-opts button { 38 | float: right; 39 | 40 | right: .5em; 41 | transform: translate(0,-50%); 42 | justify-content: flex-end; 43 | } 44 | 45 | .right-side-opts { 46 | float: right; 47 | position: absolute; 48 | right: .5em; 49 | transform: translate(0,-50%); 50 | justify-content: flex-end; 51 | color: rgb(66, 112, 162); 52 | margin-top: 10px; 53 | margin-left: 10px; 54 | } 55 | 56 | .login-forms { 57 | 58 | } 59 | 60 | .button { 61 | -moz-box-shadow:inset 0px 1px 0px 0px #ffffff; 62 | -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff; 63 | box-shadow:inset 0px 1px 0px 0px #ffffff; 64 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #f9f9f9), color-stop(1, #e9e9e9)); 65 | background:-moz-linear-gradient(top, #f9f9f9 5%, #e9e9e9 100%); 66 | background:-webkit-linear-gradient(top, #f9f9f9 5%, #e9e9e9 100%); 67 | background:-o-linear-gradient(top, #f9f9f9 5%, #e9e9e9 100%); 68 | background:-ms-linear-gradient(top, #f9f9f9 5%, #e9e9e9 100%); 69 | background:linear-gradient(to bottom, #f9f9f9 5%, #e9e9e9 100%); 70 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f9f9f9', endColorstr='#e9e9e9',GradientType=0); 71 | background-color:#f9f9f9; 72 | -moz-border-radius:10px; 73 | -webkit-border-radius:10px; 74 | border-radius:10px; 75 | display:inline-block; 76 | cursor:pointer; 77 | color:#000000; 78 | font-family:Arial; 79 | font-size:15px; 80 | font-weight:bold; 81 | padding:5px 10px; 82 | text-decoration:none; 83 | text-shadow:-1px 1px 0px #ffffff; 84 | } 85 | .button:hover { 86 | background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #e9e9e9), color-stop(1, #f9f9f9)); 87 | background:-moz-linear-gradient(top, #e9e9e9 5%, #f9f9f9 100%); 88 | background:-webkit-linear-gradient(top, #e9e9e9 5%, #f9f9f9 100%); 89 | background:-o-linear-gradient(top, #e9e9e9 5%, #f9f9f9 100%); 90 | background:-ms-linear-gradient(top, #e9e9e9 5%, #f9f9f9 100%); 91 | background:linear-gradient(to bottom, #e9e9e9 5%, #f9f9f9 100%); 92 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#e9e9e9', endColorstr='#f9f9f9',GradientType=0); 93 | background-color:#e9e9e9; 94 | } 95 | .button:active { 96 | position:relative; 97 | top:1px; 98 | } 99 | 100 | #signing-container { 101 | display: block; 102 | position: relative; 103 | margin: auto; 104 | height: auto; 105 | width: auto; 106 | padding: 5px; 107 | } 108 | 109 | #split-panel { 110 | display:block; 111 | float: left; 112 | padding: 30px; 113 | position: relative; 114 | height: auto; 115 | width: auto; 116 | margin-left: 30px; 117 | padding-left: 50px; 118 | padding-right: 50px; 119 | padding-top: 50px; 120 | } 121 | 122 | #split-panel > form { 123 | padding: 5px; 124 | display: block; 125 | } 126 | 127 | #split-panel > input { 128 | padding: 5px 5px 5px 15px; 129 | display: block; 130 | } 131 | 132 | .signing-section { 133 | width: 75%; 134 | height: 500px; 135 | margin: auto; 136 | padding: 30px; 137 | } 138 | 139 | .split-pane { 140 | display: block; 141 | margin: auto; 142 | width: auto; 143 | margin-left: 20px; 144 | padding: 10px 10px 10px 10px; 145 | max-width: 100%; 146 | height: 500px; 147 | float: left; 148 | } 149 | 150 | 151 | .split-pane button { 152 | float: center; 153 | } 154 | 155 | .register-form input, textarea { 156 | width: 85%; 157 | display: inline-block; 158 | padding: 12px; 159 | border: 1px solid #ccc; 160 | padding: 12px; 161 | min-width: 200px; 162 | margin-bottom: 20px; 163 | -webkit-border-radius: 7px; 164 | -moz-border-radius: 7px; 165 | border-radius: 7px; 166 | resize: vertical; 167 | } 168 | 169 | .register-form textarea { 170 | min-height: 70px; 171 | } 172 | 173 | .split-pane h1 { 174 | color: rgb(66, 112, 162); 175 | margin-bottom: 20px; 176 | } 177 | 178 | @media screen and (max-width: 500px) { 179 | .flex-direction{ 180 | flex-direction:column; 181 | } 182 | 183 | .btn-blue { 184 | letter-spacing: 1px; 185 | } 186 | 187 | #navbar ul li a { 188 | text-decoration: none; 189 | float: left; 190 | position: absolute; 191 | text-align: center; 192 | color: #000; 193 | margin-right: 5px; 194 | margin-top: 1px; 195 | font-size: 15px; 196 | font-family: 'Roboto', sans-serif; 197 | font-style: strong; 198 | } 199 | 200 | #right-side-opts button { 201 | position: relative; 202 | margin-top: 7%; 203 | } 204 | 205 | .logged-in table { 206 | position: relative; 207 | margin-top: 20px; 208 | } 209 | 210 | .post-comment { 211 | width: 80% !important; 212 | } 213 | } 214 | 215 | .btnblue { 216 | display: inline-block; 217 | text-transform: uppercase; 218 | letter-spacing: 0.18em; 219 | margin-top: 5px; 220 | padding-top: 3px; 221 | padding-bottom: 3px; 222 | font-size: 10px; 223 | border-radius: 5px; 224 | -moz-border-radius: 5px; 225 | -webkit-border-radius: 5px; 226 | border: 1px solid rgba(0,0,0,0.3); 227 | border-bottom-width: 3px; 228 | background-color: #699DB6; 229 | border-color: rgba(0,0,0,0.3); 230 | text-shadow: 0 1px 0 rgba(0,0,0,0.5); 231 | color: #FFF; 232 | } 233 | 234 | .btnblue:hover { 235 | background-color: #4F87A2; 236 | border-color: rgba(0,0,0,0.5); 237 | } 238 | .btnblue:active { 239 | background-color: #3C677B; 240 | border-color: rgba(0,0,0,0.9); 241 | } 242 | 243 | #sign-up-in-btn { 244 | margin-bottom: 10px; 245 | } 246 | 247 | .content-container { 248 | display: block; 249 | } 250 | 251 | .score-container { 252 | width: 15px; 253 | max-height: 70%; 254 | float: left; 255 | clear: left; 256 | color: rgb(100, 100, 100); 257 | font-style: strong; 258 | text-align: center; 259 | max-width: 15px; 260 | display: inline-block; 261 | margin-top: 0; 262 | line-height: 0; 263 | } 264 | 265 | #votearrow { 266 | display: block; 267 | margin:0; 268 | padding:0; 269 | height: 10%; 270 | display: inline-block; 271 | margin: 10px; 272 | margin-left: 0px; 273 | } 274 | 275 | .row { 276 | margin-top: 1em; 277 | margin-left: 1em; 278 | font-size: inherit; 279 | line-height: 2; 280 | color: #000; 281 | position:relative; 282 | } 283 | 284 | .post-container { 285 | margin-top: 15px; 286 | margin-left: 25px; 287 | } 288 | 289 | .post-container > p { 290 | background-color: rgb(55, 55, 55); 291 | color: rgb(222, 222, 222); 292 | font-size: medium; 293 | font-weight: normal; 294 | margin-bottom: 1px; 295 | padding-left: 5px; 296 | } 297 | 298 | .post-container a { 299 | text-decoration: none; 300 | color: rgb(130, 130, 130); 301 | } 302 | 303 | .post-container a:visited { 304 | color: rgb(130, 130, 130); 305 | } 306 | 307 | .logged-in { 308 | float: right; 309 | position: absolute; 310 | right: .5em; 311 | transform: translate(0,-50%); 312 | justify-content: flex-end; 313 | color: rgb(66, 112, 162); 314 | margin-top: 10px; 315 | margin-left: 10px; 316 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 317 | } 318 | 319 | .logged-in table { 320 | margin-top: 40px; 321 | } 322 | 323 | .logged-in th { 324 | margin-top: 10px; 325 | margin-left: 10px; 326 | } 327 | 328 | 329 | .dooting { 330 | background: #09F; 331 | width: 5%; 332 | height: 50px; 333 | text-align: center; 334 | line-height: 50px; 335 | font-size: 32px; 336 | border: 3px solid blue; 337 | border-radius: 5px; 338 | } 339 | 340 | #minus { 341 | margin: 25px 2.5% 0 37.5%; 342 | } 343 | 344 | .comment-row { 345 | margin-top: 1em; 346 | font-size: inherit; 347 | line-height: 2; 348 | color: #000; 349 | position:relative; 350 | background-color: rgb(28, 28, 28); 351 | } 352 | 353 | .comments-container { 354 | display: block; 355 | margin-top: 5px; 356 | padding-left: 16px; 357 | } 358 | 359 | .comments-container > p { 360 | background-color: rgb(28, 28, 28); 361 | color: rgb(222,222,222); 362 | font-size: medium; 363 | font-weight: normal; 364 | margin-bottom: 1px; 365 | margin-left: 15px; 366 | padding-top: 0px; 367 | } 368 | 369 | .comments-container a { 370 | color: rgb(130, 130, 130); 371 | } 372 | 373 | .comments-container a:visited { 374 | color: #551a8b; 375 | } 376 | 377 | #comment-title-container > p { 378 | padding-top: 5px; 379 | margin-left: 15px; 380 | background-color: rgb(28, 28, 28); 381 | } 382 | 383 | #comment-title-container > p:visited { 384 | background-color: rgb(28, 28, 28); 385 | } 386 | 387 | #comment-title-container { 388 | color: rgb(100, 149, 103); 389 | font-weight: bold; 390 | text-decoration: none; 391 | } 392 | 393 | #comment-points > a { 394 | font-weight: 600; 395 | color: rgb(179, 179, 179); 396 | font-size: 75%; 397 | } 398 | 399 | #comment-content-container { 400 | padding-bottom: 5px; 401 | } 402 | 403 | #comment-content-container > p { 404 | padding-right: 15px; 405 | } 406 | 407 | .comment-score-container { 408 | width: 15px; 409 | max-height: 70%; 410 | float: left; 411 | clear: left; 412 | color: rgb(100, 100, 100); 413 | font-style: strong; 414 | text-align: center; 415 | max-width: 25px; 416 | display: inline-block; 417 | margin-top: 0; 418 | line-height: 0; 419 | margin-left: 5px; 420 | } 421 | 422 | .empty-comments { 423 | margin-top: 1em; 424 | margin-left: 1em; 425 | font-size: inherit; 426 | line-height: 2; 427 | color: #000; 428 | position:relative; 429 | margin-left: 42px; 430 | } 431 | 432 | .empty-comments p { 433 | color: rgb(255, 0, 0); 434 | font-weight: 500; 435 | background-color: inherit; 436 | } 437 | 438 | .post-comment { 439 | margin-top: 1.2em; 440 | margin-left: 1em; 441 | font-size: inherit; 442 | line-height: 2; 443 | color: #000; 444 | position: relative; 445 | margin-left: 42px; 446 | margin-bottom: 20px; 447 | height: 145px; 448 | width: 20%; 449 | } 450 | 451 | #comment-form { 452 | width: 100%; 453 | float: left; 454 | } 455 | 456 | #comment-content { 457 | width: 90%; 458 | padding: 12px; 459 | border: 1px solid #ccc; 460 | -webkit-border-radius: 7px; 461 | -moz-border-radius: 7px; 462 | border-radius: 7px; 463 | min-width: 265px; 464 | max-width: 200%; 465 | min-height: 50px; 466 | max-height: 60px; 467 | } 468 | 469 | #comment-form > button { 470 | margin-top: 10px; 471 | } 472 | 473 | #submission-info { 474 | font-size: 75%; 475 | } 476 | 477 | #failure > p { 478 | color: rgb(255, 0, 0); 479 | font-weight: 500; 480 | background-color: inherit; 481 | } 482 | -------------------------------------------------------------------------------- /submit.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Reddit Clone 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | '; 27 | } else { 28 | header("location: signup.php"); 29 | echo '
30 | 31 |
'; 32 | } 33 | ?> 34 | 35 | 36 |
37 |

Create a new post

38 |
39 | 40 | 41 | 42 | 43 |
44 |
45 | document.getElementById("failure").innerHTML = "

Title or post content not entered.

";'; 62 | } else { 63 | // attempt insert query execution 64 | $sql = "INSERT INTO t164053_news (username, news, type, subreddit, title) VALUES ('$username', '$content', '$posttype', '$subreddit', '$title')"; 65 | if(mysqli_query($link, $sql)) { 66 | // echo "Records added successfully."; 67 | $msg = 'Post submitted successfully!'; 68 | echo ""; 69 | } else { 70 | echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); 71 | } 72 | } 73 | } 74 | ?> 75 |
76 | 77 | 78 | -------------------------------------------------------------------------------- /viewpost.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | RedditClone 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second'); 24 | foreach ($tokens as $unit => $text) { 25 | if ($time < $unit) continue; 26 | $numberOfUnits = floor($time / $unit); 27 | return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); 28 | } 29 | } 30 | ?> 31 | 32 | 33 | '; 38 | } else { 39 | echo '
'; 40 | } 41 | ?> 42 | 43 |
44 |
' . htmlspecialchars($row['score'], ENT_QUOTES, 'UTF-8'); 58 | echo '

' . htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'); 60 | echo '

submitted by ' . htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8') . ' '; 61 | echo timeSince(strtotime($row['ts'])) . ' ago

' . htmlspecialchars($row['news'], ENT_QUOTES, 'UTF-8') . '

'; 62 | } 63 | } else { 64 | echo "ERROR: Could not able to execute $query. " . mysqli_error($link); 65 | } 66 | ?> 67 | 68 |
71 |
'; 72 | } 73 | if($_SERVER['REQUEST_METHOD']=='POST' && isset($_POST['post-comment'])){ 74 | $link = mysqli_connect("localhost", "st2014", "progress", "st2014"); 75 | // Check connection 76 | if($link === false){ 77 | die("ERROR: Could not connect. " . mysqli_connect_error()); 78 | } 79 | // Escape user inputs for security 80 | $username = $_SESSION['uname']; 81 | $postid = $_REQUEST['postid']; 82 | $content = mysqli_real_escape_string($link, $_REQUEST['content']); 83 | // attempt insert query execution 84 | if ($content === '') { 85 | echo ""; 86 | } else { 87 | $sql = "INSERT INTO t164053_comments (username, newsid, content) VALUES ('$username', '$postid', '$content')"; 88 | if(mysqli_query($link, $sql)) { 89 | // echo "Records added successfully."; 90 | $msg = 'Comment submitted successfully!'; 91 | header('Refresh: 0'); 92 | } else { 93 | echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); 94 | } 95 | } 96 | } 97 | ?> 98 | num_rows == 0) { 109 | echo "

there doesn't seem to be anything here yet

"; 110 | } 111 | else { 112 | echo '
'; 113 | while($row = mysqli_fetch_array($result)){ 114 | $id = htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'); 115 | $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8'); 116 | $score = htmlspecialchars($row['score'], ENT_QUOTES, 'UTF-8'); 117 | $content = htmlspecialchars($row['content'], ENT_QUOTES, 'UTF-8'); 118 | echo '

' . $username. ' ' . $score; 123 | if ($row['score'] == 1) { 124 | echo ' point '; 125 | } else { 126 | echo ' points '; 127 | } 128 | echo timeSince(strtotime($row['ts'])) . ' ago

' . $content . '

'; 129 | } 130 | } 131 | } else { 132 | echo "ERROR: Could not able to execute $query. " . mysqli_error($link); 133 | } 134 | ?> 135 |
136 | 137 | 138 | -------------------------------------------------------------------------------- /vote.php: -------------------------------------------------------------------------------- 1 | = -1 && $points <= 1)) { 8 | $points = 0; 9 | } 10 | if ($link === false) { 11 | die("ERROR: Could not connect. " . mysqli_connect_error()); 12 | } 13 | $vote = "INSERT INTO t164053_pluses (username, newsid, score) 14 | VALUES ('$username', '$id', $points)"; 15 | $check = "SELECT * FROM t164053_pluses 16 | WHERE newsid='$id' AND username='$username'"; 17 | // finds row where given user has voted for given news article 18 | $result = mysqli_query($link, $check); 19 | $row = mysqli_fetch_array($result); 20 | // checks if user has already voted 21 | if($result->num_rows === 0) { 22 | // not yet voted, will vote for first time 23 | echo "New vote"; 24 | mysqli_query($link, $vote); 25 | if ($points == 1) { 26 | $updatenews = "UPDATE t164053_news SET score=$points, upvotes=upvotes+1 WHERE id='$id'"; 27 | } elseif ($points == -1) { 28 | $updatenews = "UPDATE t164053_news SET score=$points, downvotes=downvotes-1 WHERE id='$id'"; 29 | } 30 | mysqli_query($link, $updatenews); 31 | //user has already voted 32 | } elseif ($result->num_rows > 0) { 33 | $currentvote = $row['score']; 34 | // if user hasn't already voted in this manner, new score will be added 35 | if ($currentvote != $points) { 36 | $update = "UPDATE t164053_pluses SET score=score + $points WHERE newsid='$id' AND username='$username'"; 37 | if ($points == 1 && $currentvote == -1) { 38 | $updatenews = "UPDATE t164053_news SET score=score + $points, downvotes=downvotes-1 WHERE id='$id'"; 39 | } elseif ($points == -1 && $currentvote == 1) { 40 | $updatenews = "UPDATE t164053_news SET score=score + $points, upvotes=upvotes-1 WHERE id='$id'"; 41 | } elseif ($points == -1 && $currentvote == 0) { 42 | $updatenews = "UPDATE t164053_news SET score=score + $points, downvotes=downvotes+1 WHERE id='$id'"; 43 | } elseif ($points == 1 && $currentvote == 0) { 44 | $updatenews = "UPDATE t164053_news SET score=score + $points, upvotes=upvotes+1 WHERE id='$id'"; 45 | } 46 | mysqli_query($link, $update); 47 | mysqli_query($link, $updatenews); 48 | echo "Vote changed"; 49 | } else { 50 | echo "Already voted this way"; 51 | } 52 | } else { 53 | echo "ERROR: Could not able to execute $up. " . mysqli_error($link); 54 | } 55 | --------------------------------------------------------------------------------