View Full Version : 3 PHP Questions
loserWILL
27-12-2007, 02:50 AM
Well, I've started on my portfolio script. So far, so good. I've run in to three errors so far:
1. Name doesn't appear when adding news
2. Unexpected "t" after the date
3. After the PHP there is a bottom DIV, which doesn't display
Here's my code:
<?php
// Database
include "config.php";
//Variables
$title = ($_POST["title"]);
$news = ($_POST["news"]);
$date = date('F dS h:i: ');
// Some mySQL to fetch your name
$sql = "SELECT * FROM details";
$check = mysql_query("SELECT name FROM details") or die("Onoes! Something is wrong! Please contact loserWILL for assistance (this is an error).");
while ($display = mysql_fetch_array($check)) {
$user = $display['user'];
// If form has been submitted, display this
if ($_GET["action"] == "submit")
{
if ($title == "")
{
echo "Onoes! Please enter a title.";
exit;
}
if ($news == "")
{
echo "Onoes! Please enter some news.";
exit;
}
$addnews = mysql_query("INSERT INTO `news` (`title`, `name`, `date`, `post`) VALUES ('$title','$name','$date', '$post')");
//Details are fine
echo "Your news has been added.";
exit;
}
// Display form
echo ("<form action=\"?action=submit\" method=\"post\">
<strong>Name:</strong> $user<br />
<strong>Title:</strong> <input type=\"text\" name=\"title\"><br />
<strong>News:</strong> <input type=\"text\" name=\"news\"><br />
<input type=\"submit\" name=\"submit\" value=\"Add News\">
</form>");
exit;
}
Moved by Agesilaus (Forum Moderator) from Design and Development: Please post in the correct forum next time. :)
The first problem I can see is that you're missing the ?>
Well, I've started on my portfolio script. So far, so good. I've run in to three errors so far:
1. Name doesn't appear when adding news You have declared '$name', only $user. Try that.
2. Unexpected "t" after the date Date looks fine?
3. After the PHP there is a bottom DIV, which doesn't display Dont use exit;
Try this:
<?php
// Database
include "config.php";
//Variables
$title = ($_POST["title"]);
$news = ($_POST["news"]);
$date = date('F dS h:i: ');
// Some mySQL to fetch your name
$sql = "SELECT * FROM details";
$check = mysql_query("SELECT name FROM details") or die("Onoes! Something is wrong! Please contact loserWILL for assistance (this is an error).");
while ($display = mysql_fetch_array($check)) {
$user = $display['user'];
// If form has been submitted, display this
if ($_GET["action"] == "submit")
{
if ($title == "")
{
echo "Onoes! Please enter a title.";
exit;
}
if ($news == "")
{
echo "Onoes! Please enter some news.";
exit;
}
$addnews = mysql_query("INSERT INTO `news` (`title`, `name`, `date`, `post`) VALUES ('$title','$user','$date', '$post')");
//Details are fine
echo "Your news has been added.";
exit;
}
// Display form
echo ("<form action=\"?action=submit\" method=\"post\">
<strong>Name:</strong> $user<br />
<strong>Title:</strong> <input type=\"text\" name=\"title\"><br />
<strong>News:</strong> <input type=\"text\" name=\"news\"><br />
<input type=\"submit\" name=\"submit\" value=\"Add News\">
</form>");
}
loserWILL
27-12-2007, 03:33 PM
The name still doesn't show.
loserWILL
29-12-2007, 06:01 PM
Bump - Does anybody know?
Edited by mat64 (Forum Super Moderator): Please do not double post, unless you are adding additional information.
lolwut
29-12-2007, 06:22 PM
In the database, is the users name stored as "name" or "user"? I think that would be the cause of the problem.
<?php
// Database
include "config.php";
//Variables
$title = ($_POST["title"]);
$news = ($_POST["news"]);
$date = date('F dS h:i: ');
// Some MySQL to fetch your name
$sql = "SELECT * FROM `details` ;"; //It doesn't look like this line is doing anything?
$check = mysql_query("SELECT `name` FROM `details` ;") or die("Onoes! Something is wrong! Please contact loserWILL for assistance (this is an error).");
while ($display = mysql_fetch_array($check)) {
$user = $display[user];
// If form has been submitted, display this
if ($_GET["action"] == "submit")
{
if ($title == NULL)
{
echo "Onoes! Please enter a title.";
exit;
}
if ($news == NULL)
{
echo "Onoes! Please enter some news.";
exit;
}
$addnews = mysql_query("INSERT INTO `news` (`title`, `name`, `date`, `post`) VALUES ('$title','$user','$date', '$post')");
//Details are fine
echo "Your news has been added.";
exit;
}
// Display form
echo ("<form action=\"?action=submit\" method=\"post\">
<strong>Name:</strong> $user<br />
<strong>Title:</strong> <input type=\"text\" name=\"title\"><br />
<strong>News:</strong> <input type=\"text\" name=\"news\"><br />
<input type=\"submit\" name=\"submit\" value=\"Add News\">
</form>");
}
?>
loserWILL
29-12-2007, 08:19 PM
It still doesn't display the name.
<?php
// Database
include "config.php";
//Variables
$title = ($_POST["title"]);
$news = ($_POST["news"]);
$date = date('F dS h:i: ');
// Some mySQL to fetch your name
$sql = "SELECT * FROM details";
$check = mysql_query("SELECT name FROM details") or die("Onoes! Something is wrong! Please contact loserWILL for assistance (this is an error).");
while ($display = mysql_fetch_array($check)) {
$user = $display['name'];
// If form has been submitted, display this
if ($_GET["action"] == "submit")
{
if ($title == "")
{
echo "Onoes! Please enter a title.";
exit;
}
if ($news == "")
{
echo "Onoes! Please enter some news.";
exit;
}
$addnews = mysql_query("INSERT INTO `news` (`title`, `name`, `date`, `post`) VALUES ('$title','$user','$date', '$post')");
//Details are fine
echo "Your news has been added.";
exit;
}
// Display form
echo ("<form action=\"?action=submit\" method=\"post\">
<strong>Name:</strong> $user<br />
<strong>Title:</strong> <input type=\"text\" name=\"title\"><br />
<strong>News:</strong> <input type=\"text\" name=\"news\"><br />
<input type=\"submit\" name=\"submit\" value=\"Add News\">
</form>");
}
loserWILL
30-12-2007, 12:26 AM
No worries, I got it. Thanks for all the help.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.