Re: [PHP-DB] DATABASE Error on form submission

2004-08-31 Thread randy
//check for required fields from the form
if ((!$_POST[topic_owner]) || (!$_POST[topic_title])|| (!$_POST[post_text])) {
   header(Location: addtopic.html);
   exit;
}

The $_POST is an associative array and the key names need to be
wrapped by commas. The same error is happening on your local machine,
but you notices turned off in your php.ini file. Your code should look
like this...

$_POST['topic_owner']



On Tue, 31 Aug 2004 01:41:32 EDT, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Dear friends,
 
 My form works on localhost and writes to mysql database with php script,
 however
 when I use same form on server over the internet, it writes to mysql
 database, that means no connection problem,
 
 however it gives me error stated below.
 
 Guidance, please.
 
 
 Error
 ---
 Notice: Use of undefined constant topic_owner - assumed 'topic_owner' in
 \\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 3
 
 Notice: Use of undefined constant topic_title - assumed 'topic_title' in
 \\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 3
 
 Notice: Use of undefined constant post_text - assumed 'post_text' in
 \\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 3
 
 Warning: Cannot modify header information - headers already sent by (output
 started at \\premfs15\sites\premium15\mrbushforpeace\webroot\do_addtopic.php:3)
 in \\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 4
 --
 --
 code of php file
 --
 --
 ?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(orf-mysql1.briter.com, mr, p) or
 die(mysql_error());
 mysql_select_db(meace,$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 = PThe strong$topic_title/strong topic has been created./p;
 ?
 html
 head
 titleNew Topic Added/title
 /head
 body
 h1New Topic Added/h1
 ?php print $msg; ?
 /body
 /html
 -
 Form code
 --
 ?php
 
 include 'menufile.php';
 ?
 htmlcenter
 head
 titleAdd a Topic/title
 /head
 body
 h1Add a Topic/h1
 form method=post action=do_addtopic.php
 pstrongYour E-Mail Address:/strongbr
 input type=text name=topic_owner size=40 maxlength=150
 pstrongTopic Title:/strongbr
 input type=text name=topic_title size=30 maxlength=150
 PstrongPost Text:/strongbr
 textarea name=post_text rows=8 cols=30 wrap=virtual/textarea
 Pinput type=submit name=submit value=Add Topic/p/center
 /form
 /body
 /html
 


-- 
randy [EMAIL PROTECTED]

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] DATABASE error on form submission.

2004-08-31 Thread Remember14a
Dear Friends,

I have a reply form which writes to database, however it gives an error 
posted below.
Guidance, please.

--
---
Error when I keep op like 'op'
--
-
Notice: Undefined index: op in 
\\premfs15\sites\pre15\mrbupeace\webroot\replytopost.php on line 7

error when I keep op like op without inverted comma's gives two different 
errors
--

Notice: Use of undefined constant op - assumed 'op' in 
\\premfs15\sites\pre15\mrbupeace\webroot\replpost.php on line 7

Notice: Undefined index: op in 
\\premfs15\sites\premium15\mrbushforpeace\webroot\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['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'));

   print 
   html
   head
   titlePost Your Reply in $topic_title/title
   /head
   body
   h1Post Your Reply in $topic_title/h1
   form method=post action=\$_SERVER[PHP_SELF]\
   pstrongYour E-Mail Address:/strongbr
   input type=\text\ name=\post_owner\ size=40 maxlength=150

   PstrongPost Text:/strongbr
   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\

   Pinput 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

   exit;
}
?


Re: [PHP-DB] DATABASE error on form submission.

2004-08-31 Thread Arné Klopper
Can you access the other POST variables, if not put quotation marks around 
method=post, also try using instead of op something else...
 
 
Kind Regards
Arné Klopper
 

NetCB Solutions (Pty) Ltd.
www.netcb.com
Office: +27 12 997 3007
Fax: 27 12 997 3629
Mobile: +27 84 513 4119

 [EMAIL PROTECTED] 2004/08/31 09:58:39 AM 

Dear Friends,

I have a reply form which writes to database, however it gives an error 
posted below.
Guidance, please.

--
---
Error when I keep op like 'op'
--
-
Notice: Undefined index: op in 
\\premfs15\sites\pre15\mrbupeace\webroot\replytopost.php on line 7

error when I keep op like op without inverted comma's gives two different 
errors
--

Notice: Use of undefined constant op - assumed 'op' in 
\\premfs15\sites\pre15\mrbupeace\webroot\replpost.php on line 7

Notice: Undefined index: op in 
\\premfs15\sites\premium15\mrbushforpeace\webroot\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['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'));

   print 
   html
   head
   titlePost Your Reply in $topic_title/title
   /head
   body
   h1Post Your Reply in $topic_title/h1
   form method=post action=\$_SERVER[PHP_SELF]\
   pstrongYour E-Mail Address:/strongbr
   input type=\text\ name=\post_owner\ size=40 maxlength=150

   PstrongPost Text:/strongbr
   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\

   Pinput 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

   exit;
}
?




[PHP-DB] DATABASE Error on form submission

2004-08-30 Thread Remember14a
Dear friends,

My form works on localhost and writes to mysql database with php script, 
however
when I use same form on server over the internet, it writes to mysql 
database, that means no connection problem,

however it gives me error stated below.

Guidance, please.


Error
---
Notice: Use of undefined constant topic_owner - assumed 'topic_owner' in 
\\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 3

Notice: Use of undefined constant topic_title - assumed 'topic_title' in 
\\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 3

Notice: Use of undefined constant post_text - assumed 'post_text' in 
\\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 3

Warning: Cannot modify header information - headers already sent by (output 
started at \\premfs15\sites\premium15\mrbushforpeace\webroot\do_addtopic.php:3) 
in \\premfs15\sites\premium15\mrbpeace\webroot\do_addtopic.php on line 4
--
--
code of php file
--
--
?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(orf-mysql1.briter.com, mr, p) or 
die(mysql_error());
mysql_select_db(meace,$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 = PThe strong$topic_title/strong topic has been created./p;
?
html
head
titleNew Topic Added/title
/head
body
h1New Topic Added/h1
?php print $msg; ?
/body
/html
-
Form code
--
?php

include 'menufile.php';
?
htmlcenter
head
titleAdd a Topic/title
/head
body
h1Add a Topic/h1
form method=post action=do_addtopic.php
pstrongYour E-Mail Address:/strongbr
input type=text name=topic_owner size=40 maxlength=150
pstrongTopic Title:/strongbr
input type=text name=topic_title size=30 maxlength=150
PstrongPost Text:/strongbr
textarea name=post_text rows=8 cols=30 wrap=virtual/textarea
Pinput type=submit name=submit value=Add Topic/p/center
/form
/body
/html