Jump to content

[SOLVED] PHP - SQL Help Please


eRott

Recommended Posts

The problem I am facing is that I have a script which a user uses to add news to a DB. The problem is however, that when you add the news, you have to enter 4 things, the TITLE, the actual CONTENT, and the part I want to change, the user who SUBMITTED it.

 

What I am looking to do, is automatically grab the username of the person currently logged in and add that to the database that way you cannot enter a different name. (to keep track of the users, i use sessions).

 

Here is the code I am using.

 

<?
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>

<?php include("lib/header.php"); ?>

<h3>Guild News Editor - New Article</h3>

<?
if(isset($_POST['add']))
{
include 'lib/config.php';
include 'lib/db_open.php';

$title = $_POST['title'];
$content = $_POST['content'];
$submitted = $_POST['submitted'];

$query = "INSERT INTO $tbl_content (title, content, date, submitted) VALUES ('$title', '$content', CURRENT_DATE, '$submitted')";
mysql_query($query) or die('Error, insert query failed');

include 'lib/db_close.php';
echo "<meta http-equiv='refresh' content='1;url=index2.php'>New article successfully added!";
}
else
{
echo "
<form method='post'>
<b>Title:</b><br><input name='title' type='text' id='title'><br><br>
<b>Content:</b><br>
<textarea name='content' id='content' type='text' rows='15' cols='50' style='width: 100%; margin-left: 0px; padding: 0px; background-color: #fff'></textarea><br><br>
<b>Submitted By:</b><br><input name='submitted' type='text' id='submitted'><br><br>
<input name='add' type='submit' id='add' value='Submit New Article'>
</form>
";
}
?>

<?php include("lib/footer.php"); ?>

 

Any idea of how to do this?

Link to comment
https://forums.phpfreaks.com/topic/39658-solved-php-sql-help-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.