Jump to content

[SOLVED] Why won't it insert the MySQL data?


Shiny_Charizard

Recommended Posts

<?PHP
include('top.php');

$ID = $_GET["ID"];
$username= $_SESSION['username'];

//If User Is Not Logged In
if(!isset($username))
{
include('connect.php'); 

echo "<link rel='stylesheet' href='style.css' type='text/css'>";

echo "<center>";

echo "<table rules='rows' width='980px'>";

echo "<TR><TD CLASS='headings'> <a href='index.php'>Forum Index</a> --> <a href='index.php?forumID=$ID'>Viewing Topics</a> --> <a href='newtopic.php?ID=$ID'>Create New Topic</a></td></tr>";

echo "<tr><td class='theadings'>Error</td></tr>";

echo "<tr><td class='headings'><center>You are not logged in. You must be logged in to access the Forums.<BR> Click here to <a href='login.php'>Log in</a>.</center><td></tr>";

echo "</table>";

include('bottom.php');

exit;
}
include('connect.php');
echo "<link rel='stylesheet' href='style.css' type='text/css'>";

echo "<center>";

echo "<table rules='rows' width='980px'>";

echo "<TR><TD CLASS='headings'> <a href='index.php'>Forum Index</a> --> <a href='index.php?forumID=$ID'>Viewing Topics</a> --> <a href='newtopic.php?ID=$ID'>Create New Topic</a></td></tr>";


echo "<tr class='theadings'><td>Create a new topic</td></tr>";

echo "<tr class='headings'><td>";

if(isset($_POST['submit']))

{

   $name = $username;

   $post = $_POST['topic'];

   $subject = $_POST['subject'];


   if(strlen($post)<1)

   {

      echo "<center><font color='red'>Error:</font> You did not type in a post. Click here to go <a href='index.php'>back.</a></center>"; //user did not enter a  post

   }

   else if(strlen($subject)<1)

   {

      echo "<center><font color='red'>Error:</font> You did not enter a Title. Click here to go <a href='index.php'>back.</a></center>"; //user did not enter a subject

   }

   else

   {

$thedate=date("U");
$displaytime=date("F j, Y, g:i a");
	$subject=strip_tags($subject);
		$post=strip_tags($post); 
$addpost =mysql_query("INSERT * INTO forum_posts
(
author, 
title, 
post, 
showtime, 
realtime, 
lastposter, 
category_id
) 
VALUES
(
'$name', 
'$subject', 
'$post', 
'$displaytime', 
'$thedate', 
'$name', 
'$ID'
)")
or die 
("<center><font color='red'>Error:</font> Could not post topic. Click here to go <a href='index.php'>back.</a></center>");
echo "<center>Your topic has been created successfully! Click here to go <a href='index.php'>back.</a></center>"; 

   }
}
else
{
   echo "<center>	
<form name='new_topic' action='' method='POST'>
Topic Title:
   <br />
<input type='text' name='subject' size='32'><br>
Your post:
   <br />
   <textarea name='topic' rows='5' cols='40'></textarea><br>
    <input type='submit' name='submit' value='Post New Topic'>
   </form>   
</center>";
}

echo "</td></tr></table>";

echo "<table width='980'><tr><td class='headings'> HTML is <b>OFF</b><br> BBcode is <b>ON</b></td></tr></table>";

echo "</center>";

include('bottom.php');

?>

 

Why doesn't it insert the data to the MySQL table?

I keep getting the error I made it say when it didn't insert the data.

Link to comment
Share on other sites

Change your query to:

 

$addpost =mysql_query("INSERT * INTO forum_posts
(
author, 
title, 
post, 
showtime, 
realtime, 
lastposter, 
category_id
) 
VALUES
(
'$name', 
'$subject', 
'$post', 
'$displaytime', 
'$thedate', 
'$name', 
'$ID'
)")
or die (mysql_error());

 

Post whatever error you get.

Link to comment
Share on other sites

Okay...do this and post what it gives you

 

$addpost ="INSERT * INTO forum_posts
(
author, 
title, 
post, 
showtime, 
realtime, 
lastposter, 
category_id
) 
VALUES
(
'$name', 
'$subject', 
'$post', 
'$displaytime', 
'$thedate', 
'$name', 
'$ID'
)";

$result = mysql_query($addpost)or die(mysql_error() . "<p>With Query<br>$addpost");

Link to comment
Share on other sites

This is what I get:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* INTO forum_posts ( author, title, post, showtime, realtime, lastpo' at line 1

 

With Query

INSERT * INTO forum_posts ( author, title, post, showtime, realtime, lastposter, category_id ) VALUES ( 'Shiny_Charizard', 'Test', 'Test..', 'February 2, 2008, 9:34 pm', '1202006042', 'Shiny_Charizard', '1' )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.