Show us the errors that you’re getting.
Since its not working on the server, i’d have a look at the php version and what’s been enabled vs what you have enabled on your local server. Could be that there’s a mission function or something like that.
Show us the errors that you’re getting.
Since its not working on the server, i’d have a look at the php version and what’s been enabled vs what you have enabled on your local server. Could be that there’s a mission function or something like that.
Home |
|
Bizopps
|
Name: |
Email: |
Website: |
Comments: |
A word of advice before it gets too late, don’t use tables in your HTML. It is a pain in the rear-end to try and maintain and even more figure out what’s going on. It does nothing but clutter your HTML. I changed the form so it wasn’t using a table and you still have the same appearance; this will make changing it a lot easier down the road.
The problem with your script is that you were checking for “isset($_POST[‘submit’])” and there was not an input that had that name attribute. I added it to the submit input and it worked. That should do it and I would highly suggest getting rid of the other tables you use right away (especially for the menu). Speaking of menu, you should nest a
. | is suppose to only be used as a child of
// $outputstring = $pre . ‘ ’ . $name . ‘. ’ . date(‘F j Y \a\t h:i a’, $time) . ’// ’ . $message . ‘’;// @fwrite($fp, $outputstring, strlen($outputstring)); // fclose($fp);
<?php include "comments.html" ?>
[/php] |
Those /br,s were supposed to be /tr
Ok. Was asking for suggestion in the part of code where it’s typed “is this really what you want to do?”
Thats fine. My comment was directed more at the other guy. I had noticed the samething, but apparently it was dismissed.
To make it clear, I know little, but am not an expert. Is there something that should be done different concerning meta tag? Looks like that is what it was in reference to.
It depends on what you are trying to do with the information that is submitted. If you are uploading it to a database and want to redirect afterwards, then you should do your query and then use header('location: ‘whateverURL.php’). To use header() you cannot output anything to your page before that. That means not HTML or <?php echo ''; ?> and no using printf.
What is your main goal with this script?
Adding a simple php comment system with no sql for user input.
Okay, how do you plan on storing the information?
No such plan to store info, for now.
Before you go any further you need to figure that out, you can’t create a commenting system without storing the comments. I personally use MySQL as it plays very well with PHP. (technically I use MySQLi as it is the improved version of MySQLi and the regular MySQL will be removed in the near future)
If that was your suggestion, I plan to use that later on, but not right now. This being my first system, I’m trying to finish that.
My suggestion is using MySQLi, but I am strongly recommending you figure out how you’re storing the information before you go further.
The process of a commenting system is generally like this ( or any other information you may want to store)…
Half of a commenting system is the database.
Yes. I understand that, but I prefer to start with something simple for the moment. And see how this works for me.
I don’t understand your reasoning. Your form is posting the information. What else is there to do other than store it into a database and then retrieve the information to display it? What I’m telling you to do with the db is simple.
I just wrote this up in about 15 min. It will handle your comments (insert and display them). This is your next step.
another-year.php
[php]
Home |
|
Bizopps
|
<h2>Another Year</h2>
<h4>February 22, 2012</h4>
<hr/>
<h2> Share Your Thoughts</h2>
<?php
if (isset($_POST['submit'])) { // Added not to display "please fill out all reqired fields".
$host = '';
$user = 'PUT USERNAME HERE';
$pass = 'PUT PASSWORD HERE';
$db = 'simple_comment_system';
$link = new mysqli($host, $user, $pass, $db);
$name = htmlentities($_POST['name']);
$email = htmlentities($_POST['email']);
$website = htmlentities($_POST['website']);
$message = htmlentities($_POST['message']);
$sql = $link->query("INSERT INTO comment(userName, userEmail, userWebsite, userComment)
VALUES ('".$link->real_escape_string($name)."', '".$link->real_escape_string($email)."', '".$link->real_escape_string($website)."', '".$link->real_escape_string($message)."')
");
if($sql){
echo "Successful Insertion!";
}
else {
echo mysqli_error($link);
}
// this redirects before you get a chance to see the output
// Is this what you really wanted to do?
//echo "<meta http-equiv='Refresh' content='0; URL=another-year.php'>"; // changed from Header( )
}
?>
<div id="formWrapper">
<form action="another-year.php" method="post">
<label>Name:</label>
<input type="text" name="name">
<br />
<label>Email:</label>
<input type="text" name="email">
<br />
<label>Website:</label>
<input type="text" name="website">
<br />
<label>Comments:</label>
<br />
<textarea name="message" cols="40" rows="4" ></textarea>
<br />
<input name="submit" type="submit" value="submit">
</form>
</div>
<h2>Comments:</h2>
<?php
$sql = $link->query("SELECT * FROM comment ORDER BY commentID DESC");
while($row = $sql->fetch_array()){
echo "
<hr />
<div style='margin:10px;'>
".$row['userName']."<small> - ".$row['timestamp']."</small>
<br />
Email: ".$row['userEmail']."
<br />
Website: ".$row['userWebsite']."
<br />
Comment: <pre>".$row['userComment']."</pre>
</div>
";
}
?>
[/php]
sql code to create database and table
-- phpMyAdmin SQL Dump
-- version 4.0.4.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 07, 2013 at 12:56 PM
-- Server version: 5.6.12
-- PHP Version: 5.5.3
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `simple_comment_system`
--
CREATE DATABASE IF NOT EXISTS `simple_comment_system` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `simple_comment_system`;
-- --------------------------------------------------------
--
-- Table structure for table `comment`
--
CREATE TABLE IF NOT EXISTS `comment` (
`commentID` int(11) NOT NULL AUTO_INCREMENT,
`userName` text NOT NULL,
`userEmail` text NOT NULL,
`userWebsite` text NOT NULL,
`userComment` text NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`commentID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I don’t disagree with your suggestion, but appreciate it, and in the future, can return to this thread. Again, appreciate it. I would just like to see how this works for me, right now. It’s a personal goal.