I've looked around my code multiple times but can't find any problematic areas. It doesn't help that there are no error messages either. I don't know, many I'm overlooking something. Anyway, the problem is...well that the script isn't working right. Not too sure what the exact problem is. I mean, nothing is inserted into the database table. No empty columns are inserted, just nothingness. When I insert comments manually, there are displayed correctly, so its just something with the inserting. What baffles me is this is almost exactly the same code used on another page where the commenting is working properly.
PHP Code:
if ($_POST['submitted'] == 1) {
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$_POST['name'] = stripslashes($_POST['name']);
$_POST['comment'] = stripslashes($_POST['comment']);
$_POST['reply'] = stripslashes($_POST['reply']);
}
$username = mysql_real_escape_string($_POST['name']);
$comment = mysql_real_escape_string($_POST['comment']);
$category = 'news';
$subcategory = $article['id'];
$reply = mysql_real_escape_string($_POST['reply']);
if (empty($username)) {
echo "<p>Name is a required field</p>";
exit();
}
if (empty($comment)) {
echo "<p>Comment is a required field</p>";
exit();
}
Do you just get a white blank page when you run it?
Are you sure that error reporting is enabled ... so you don't just get a white page when it fails?
Add the lines in red ... after the query to make sure it's getting to that part.
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
echo "finished";
exit;
No, the design is completely intact. No error messages, no blank white pages, nothing. Just checked to make sure error reporting was enabled and it is. As for the debugging code, it isn't echoing that so...Come to think of it I did do something similar to check earlier and my variables weren't echoed either. Checked my variables' values and even the $_POST values weren't echoed. I should also mention I'm using $_GET values as well so each article in the database gets its own page, in case that might have anything to do with it.
__________________ Coding is a challenge, get used to it Always remember to debug Try the guess & check method Break it down into simple steps
If the 'date' field is a time-stamp field that it doesn't require assigning NOW().
You haven't just omitted the final closing bracket } ?
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Instead of using NOW() to insert a date into the database, try creating a PHP timestamp, format it as you need it then try inserting the variable.
In my PHP book, it shows in one example to insert using now() but when I tried it, it didn't work. Soon as I created a php timestamp, it worked.
Just a thought.
Also, what is different in this script to your last script?
Regards,
LC.
Not much is different. The $subcategory variable was added in this script, and this one is all php. The original was almost entirely static data and so I didn't need the entire page in php tags. Like I said, its almost exactly the same. As for your timestamp trick, nothing...
Quote:
Originally Posted by AndrewGSW
Just eliminating obvious things:
If the 'date' field is a time-stamp field that it doesn't require assigning NOW().
You haven't just omitted the final closing bracket } ?
Nope, all brackets are properly closed... and no the 'date' field is a datetime, kinda need it to be in order to work properly with an 'agoTime()' function.
__________________ Coding is a challenge, get used to it Always remember to debug Try the guess & check method Break it down into simple steps
Posted-data are initially strings, or arrays of strings:
PHP Code:
if ($_POST['submitted'] && $_POST['submitted'] == '1') {
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Where is this $article array coming from and does it contain correct values? use print_r() to display it. Use View Source on the page to read it more easily.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Where is this $article array coming from and does it contain correct values? use print_r() to display it. Use View Source on the page to read it more easily.
PHP Code:
<?php
//News articles start
$news = mysql_query("SELECT * FROM `news` ORDER BY `date` DESC LIMIT 10");
while($article = mysql_fetch_array($news)) {
$articlePosted = $article['date'];
$datePosted = date("F jS, Y", strtotime($articlePosted));
if (empty($_GET['id'])) {
database. And yes its values are correct. Later on in the code, $article is echoed just fine.
__________________ Coding is a challenge, get used to it Always remember to debug Try the guess & check method Break it down into simple steps
You are using $article to fetch rows from the database. When there are no more rows, $article will be false.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
No, there is no guarantee that there exists a syntactical error with the SQL statement. This alone could be a problem here though: '$subcategory' as it stands out given that its populated from an 'id' could possibly be an integer. MySQL can be configured to strict datatyping.
Given the check on the mysql_query function doesn't produce an error report with the mysql_error indicates to me its not syntactical. My take on the description is that it works when manually entered (presumably using a query directly on the client or with something like PHPMyAdmin).
Based on what I see here and what the described output is, my first suggestion is to open your error reporting up:
or check your error logs. Any issue indicating a connection failure with the database? Mysql_error when there is no possible error should produce an empty string.
If not, post more code. This isn't by itself (we can see a syntactical fault with a missing end brace if it were by itself), so we cannot tell looking at this that its even possible to reach this branch statement.