Code Comments
Programming Forum and web based access to our favorite programming groups.Dear Friends,
My form was working on localhost, without any error and was writing to
database, however, now on server, over the internet, it does write to databa
se,
there is no problem of connection or writng to database.
Still it gives this shabby error.
Any Guidance, please.
----------------------------------------------------------------------------
--
----
Notice: Undefined index: pp in
\\premfs15\sites\premium15\mrpeace\webro
ot\replytopost.php on line 7
---------------------------------------
Code of the script
-------------------------------------------------------------
<?php
//connect to server and select database; we'll need it soon
$conn = mysql_connect("orf-kster.com", "mr", "p") or die(mysql_error());
mysql_select_db("mr",$conn) or die(mysql_error());
//check to see if we're showing the form or adding the post
if ($_POST['pp'] != "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'));
print "
<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[pp] == "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
exit;
}
?>
------------------------------------------------
Post Follow-up to this messageYou get this notice because when the form is displayed, it means the data
has not been sent, hence $_POST is empty!
Add isset() in front of every $_POST and $_GET
Example:
if (isset($_POST['pp'] && $_POST['pp'] != 'addpost')
---
You may also add this line at the very top of the page!
This line will not give the notice - even if isset() is not added!
<?php error_reporting(0); ?>
Hope it helps!
Nadim Attari
<Remember14a@aol.com> a écrit dans le message de
news:15b.3e05133a.2e658ff6@aol.com...
> Dear Friends,
> My form was working on localhost, without any error and was writing to
> database, however, now on server, over the internet, it does write to
database,
> there is no problem of connection or writng to database.
>
> Still it gives this shabby error.
> Any Guidance, please.
>
> --------------------------------------------------------------------------
----
> ----
> Notice: Undefined index: pp in
> \\premfs15\sites\premium15\mrpeace\webro
ot\replytopost.php on line 7
> ---------------------------------------
> Code of the script
> -------------------------------------------------------------
> <?php
> //connect to server and select database; we'll need it soon
> $conn = mysql_connect("orf-kster.com", "mr", "p") or die(mysql_error());
> mysql_select_db("mr",$conn) or die(mysql_error());
>
> //check to see if we're showing the form or adding the post
> if ($_POST['pp'] != "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'));
>
> print "
> <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[pp] == "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
>
> exit;
> }
> ?>
> ------------------------------------------------
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.