hae guys am working on a discusion forum and i have some few errors how can i get lid of them this are the erors
Notice: Use of undefined constant topic_owner - assumed 'topic_owner' in C:\wamp\www\disc\do_addtopic.php on line 12

Notice: Use of undefined constant topic_title - assumed 'topic_title' in C:\wamp\www\disc\do_addtopic.php on line 12

Notice: Use of undefined constant post_text - assumed 'post_text' in C:\wamp\www\disc\do_addtopic.php on line 14

Notice: Undefined variable: topic_title in C:\wamp\www\disc\do_addtopic.php on line 47

the following are the codes

<?php

//check for required fields from the form

if ((!$_POST[topic_owner]) || (!$_POST[topic_title])

|| (!$_POST[post_text])) {
header("Location: addtopic.html");

exit;

}

//connect to server and select database

$conn = mysql_connect("localhost","root","")
or die(mysql_error());
mysql_select_db("forum",$conn) or die(mysql_error());


//create and issue the first query
$add_topic = "insert into forum_topics values ('', '$_POST[topic_title]',
now(), '$_POST[topic_owner]')";
mysql_query($add_topic,$conn) or die(mysql_error());


//get the id of the last query
$topic_id = mysql_insert_id();

//create and issue the second query

$add_post = "insert into forum_posts values ('', '$topic_id',

'$_POST[post_text]', now(), '$_POST[topic_owner]')";

mysql_query($add_post,$conn) or die(mysql_error());


//create nice message for user
$msg = "<P>The <strong>$topic_title</strong> topic has been created.</p>";

?>

<html>
<head>
<title>New Topic Added</title>
</head>

<body>

<h1>New Topic Added</h1>

<?php echo $msg; ?>

</body>

</html>

Your reverens to $_POST should be quoted like this

$_POST['topic_owner']

Same answer as in this thread

thanx for the answer you gave it enabled me solve some errors
some one help how i can solve this error
Notice: Undefined index: op in C:\wamp\www\disc\replytopost.php on line 22

this is the codes

 <?php

 //connect to server and select database; we'll need it soon

 $conn = mysql_connect("localhost", "root", "")

     or die(mysql_error());

 mysql_select_db("forum",$conn)  or die(mysql_error());

 //check to see if we're showing the form or adding the post


  if ($_POST['op'] != "addpost") {

     // showing the form; check for required item in query string

    if (!$_GET['post_id']) {

        header("Location: topiclist.php");

        exit;

    }

      //still have to verify topic and post

    $verify = "select ft.topic_id, ft.topic_title from

    forum_posts as fp left join forum_topics as ft on

    fp.topic_id = ft.topic_id where fp.post_id = $_GET[post_id]";



    $verify_res = mysql_query($verify, $conn) or die(mysql_error());

     if (mysql_num_rows($verify_res) < 1) {

        //this post or topic does not exist

        header("Location: topiclist.php");

        exit;

    } else {

        //get the topic id and title

        $topic_id = mysql_result($verify_res,0,'topic_id');
       $topic_title = stripslashes(mysql_result($verify_res,

         0,'topic_title'));



        echo "

        <html>
        <head>

        <title>Post Your Reply in $topic_title</title>

        </head>

        <body>

        <h1>Post Your Reply in $topic_title</h1>

        <form method=post action=\"$_SERVER[PHP_SELF]\">



       <p><strong>Your E-Mail Address:</strong><br>

        <input type=\"text\" name=\"post_owner\" size=40 maxlength=150>


        <P><strong>Post Text:</strong><br>

        <textarea name=\"post_text\" rows=8 cols=40 wrap=virtual></textarea>



        <input type=\"hidden\" name=\"op\" value=\"addpost\">

       <input type=\"hidden\" name=\"topic_id\" value=\"$topic_id\">


        <P><input type=\"submit\" name=\"submit\" value=\"Add Post\"></p>



        </form>

       </body>

        </html>";

   }

 } else if ($_POST['op'] == "addpost") {
    //check for required items from form

    if ((!$_POST[topic_id]) || (!$_POST[post_text]) ||

     (!$_POST[post_owner])) {

        header("Location: topiclist.php");

        exit;

    }


    //add the post

    $add_post = "insert into forum_posts values ('', '$_POST[topic_id]',

     '$_POST[post_text]', now(), '$_POST[post_owner]')";

   mysql_query($add_post,$conn) or die(mysql_error());


    //redirect user to topic
    header("Location: showtopic.php?topic_id=$topic_id");

    exit;

 }

 ?>

Same solution applies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.