Skip to content

Instantly share code, notes, and snippets.

@sunlee-newyork
Created November 16, 2013 21:34
Show Gist options
  • Save sunlee-newyork/7505649 to your computer and use it in GitHub Desktop.
Save sunlee-newyork/7505649 to your computer and use it in GitHub Desktop.
Website NONAME / NEWCARDS
<?php
error_reporting(E_ERROR);
session_start();
if (! isset($_SESSION["user"])) {
header("Location: /IDEA/login/index.php");
}
if ($_GET["cmd"] == "logout") {
session_unset();
session_destroy();
session_write_close();
session_regenerate_id(true);
header('Location: /IDEA/login/index.php');
exit;
}
?>
<html>
<head>
<style>
button {
margin-left:auto;
margin-right:auto;
}
#header {
text-align:center;
margin-top:80px;
font-family:HelveticaNeue-Light;
font-size:27px;
}
#form {
width:351px;
margin-top:30px;
margin-left:auto;
margin-right:auto;
font-family:HelveticaNeue-Light;
}
#title, #tag {
width:350px;
height:24px;
font-family:HelveticaNeue-Light;
font-size:14px;
}
#description {
width:350px;
height:200px;
font-family:HelveticaNeue-Light;
font-size:14px;
}
#submit_button {
margin-top:20px;
font-size:20px;
}
#logout {
margin-left:236px;
font-family:HelveticaNeue-Light;
font-size:14px;
}
</style>
<title>NEWCARDS</title>
</head>
<body>
<?php require $_SERVER['DOCUMENT_ROOT']."/IDEA/header/index.php"; ?>
<div id="header">NEW CATEGORY CREATED!</div>
<div id="form">
<form action="index.php" name="form" method="post">
<p>You've created a category called TELEVISION.
<br>Tell us a bit more about your project.
</p>
<p>What's the catchphrase?</p>
<input id="title" name="title" placeholder="Title needs to be 3 words!" required/>
<br>
<p>Add more tags.</p>
<input id="tag" name="tag" placeholder="Separate with commas." required/>
<br>
<p>Here is where you sell it. You have 200 characters. <a href="">Why?</a></p>
<textarea id="description" name="description" placeholder="Make it simple." required></textarea>
<br>
<input id="submit_button" type="submit" />
<a href="index.php?cmd=logout" id="logout">Logout</a>
</form>
</div>
</body>
<?php
// === USER LOGIN CHECK === \\
error_reporting(E_ERROR);
session_start();
if (! isset($_SESSION["user"])) {
header("Location: /IDEA/login/index.php");
}
/*
if ($_GET["cmd"] == "logout") {
session_unset();
session_destroy();
session_write_close();
session_regenerate_id(true);
header('Location: /IDEA/login/index.php');
exit;
}
*/
// === PROCESS USER INPUT === \\
if ($_POST) {
// Name all user input variables
$title = $_POST["title" ];
$description = $_POST["description" ];
$tag = $_POST["tag" ];
// Bounce empty input fields
$required = array('title','description','tag');
$error = false;
foreach($required as $value) {
if (empty($_POST[$value])) {
$error = true;
}
}
if ($error) {
echo "<script>alert('ERROR: All fields are required.');</script>";
die;
}
// Title must be at most 3 words (2 spaces) and at most 40 characters ***FRONTEND: Count down characters as user types***
// $whitespace = preg_replace("/\S/", "", $title);
// $no_whitespace = strlen($whitespace);
$no_chars_title = strlen($title);
// if ($no_whitespace > 2) {
// echo "<script>alert('Title must be at max 3 words.');</script>";
// die;
// }
if ($no_chars_title > 40) {
echo "<script>alert('No stuffing! It\'s not Thanksgiving yet.');</script>";
die;
}
// Description must be at most 200 characters
$no_chars_descript = strlen($description);
if ($no_chars_descript > 200) {
echo "<script>alert('The limit is 200 characters. Think of it like Twitter with 60 more chances.');</script>";
die;
}
// Tags must be separated by commas and at most 5 tags
// Bounce if current submission is too similar to past submissions
// Insert user input data
$query = mysql_query (
"INSERT INTO `idea_cards` (
`owner` ,
`title` ,
`description`,
`tag` ,
`id` ,
`timestamp`
)
VALUES (
'Sun' ,
'$title' ,
'$description',
'$tag' ,
NULL ,
NULL
);"
);
if (!$query) {
$message = 'Invalid Query: ' .mysql_error(). "<br/><br/>";
die($message);
}
// Display successful input
if ($query) {
mysql_free_result($query);
// Send instant email
$subject = "You've created a new Ideacard!";
$headers .= "From: Idea.com <sunlee1988@gmail.com>]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "<p>We're happy to see you making new ideas come to life!</p>";
$message .= "<p>Here is your latest input:</p>";
$message .= "<table>";
$message .= "<tr><td><b>Title:</b></td><td>" .strip_tags($title ). "</td></tr>";
$message .= "<tr><td><b>Description:</b></td><td>" .strip_tags($description). "</td></tr>";
$message .= "<tr><td><b>Tags:</b></td><td>" .strip_tags($tag ). "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($email, $subject, $message);
$query = mysql_query("SELECT * FROM `idea_cards` WHERE `title` = '$title';");
}
while ($row = mysql_fetch_assoc($query)) {
echo "You successfully performed an insert affecting the following data.<br/><br/>";
echo "Owner: " .$row["owner" ]. "</br>";
echo "Title: " .$row["title" ]. "</br>";
echo "Description: " .$row["description"]. "</br>";
echo "Tags: " .$row["tag" ]. "</br>";
echo "ID: " .$row["id" ]. "</br>";
}
// Wrap it up team
mysql_free_result($query);
return;
echo "</p></html>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment