Regardless of where I want to be, where I am coming from, and where I am actually going, I'm not trying to create a db-driven site. I just wanted to put up a comment box. Nothing more, nothing less.
Tonight was spent mostly twiddling my thumbs with various other stuff with other people, and twiddling my thumbs in front of a computer reading this and reading that.
What did I really learn today?
insert("xxxxx.php") makes my life a lot easier. How I would implement this into my current project is a question riddled with choice vocabulary I won't repeat here. Regardless, insert() is perfect for me since I have a ton of articles that are intertwined, so 20 articles on the left of the page? Write once, insert(). Lovely.
I am sort of happy I got the comment box to work, but I am not happy with the implementation. I have two comment boxes right now, here is one, just imagine the other says "commentTwo":
Code:
<?php
require('connect.php');
if(isset($_POST['subjectOne'])){
$subjectOne = $_POST['subjectOne'];
}
if (isset($_POST['name'])){
$name = $_POST['name'];
}
if (isset($_POST['commentary'])){
$comment = $_POST['commentary'];
}
if (isset($_POST['submit'])){
$submit = $_POST['submit'];
}
if($submit){
if($name&&$comment){
$insert=mysql_query("INSERT INTO comments (subject, name, comment) VALUES ('" . mysql_real_escape_string($subjectTwo) . "','" . mysql_real_escape_string($name) . "','" . mysql_real_escape_string($comment) . "')");
header('Location: direct.php');
}else{
echo "Please fill out all fields";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<form action="comment.php"
method="POST">
<fieldset>
<legend>Comments:</legend>
<p>While I am a strong proponent of freedom of speech and expression, I am granted with the right to delete spam, troll posts, and rudeness. I will exercise that right when needed.</p>
<input type="hidden" name="subjectOne" value="sOne">
<p><label>Name:<br><input type="text" name="name"></label></p>
<p><label>Comments:<br><textarea name="commentary"></textarea></label></p>
<input type="submit" name="submit" id="submit" value="Hit me" />
</fieldset>
</form>
<?php
$getquery=mysql_query('SELECT id ,name ,comment
FROM comments
WHERE subject="sOne"
ORDER BY id DESC');
while($rows=mysql_fetch_assoc($getquery)){
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
echo $name . '<br>' . $comment . '<br>' . '<br>';
}
?>
</body>
</html>
I did attempt this:
Code:
<form action="commentOrg.php"
method="POST">
<fieldset>
<legend>Comments:</legend>
<p>While I am a strong proponent of freedom of speech and expression, I am granted with the right to delete spam, troll posts, and rudeness. I will exercise that right when needed.</p>
<input type="hidden" name="subjectOne" value="sOne">
<p><label>Name:<br><input type="text" name="name"></label></p>
<p><label>Comments:<br><textarea name="commentary"></textarea></label></p>
<input type="submit" name="submit" id="submit" value="Hit me" />
</fieldset>
</form>
so that the form information redirects to commentOrg.php, which is basically the stuff at the top of the page copy/paste with a few modifications.
Although I got it too work, the page only redirected to commentOrg.php.
As for direct.php, I tried a bunch of stuff, like using an if (should use a switch/case statement if I really wanted to this, I guess). The idea would be to catch the hidden form variable, and send the information back to the appropriate page.
Code:
<?php
header('Location: comment.php');
header('Location: commentTwo.php');
?>
but I guess if I really wanted it all to work with my current knowledge, I would have 1500 files that say nothing more than header('Location: xxxxx.php'), which I don't want to do.
Basically, I think I am on the right track with using a switch/case statement.
The more I am learning about PHP -- which so happens to be everything I don't need to know about this particular project -- I am finding that it makes life a heck of a lot easier, and creating a site without it or a similar back end seems patently absurd to me now.
Did you know that you can use:
<script type ="text/javascript" src=xxxxx.php>
Interesting implications there.
Also learning that PHP is a violent language. explode(), implode(), die().