For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > August 2004 > Re: [PHP-DB] DATABASE Error on form submission









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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

2004-08-31, 3:55 am

//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, remember14a@aol.com
<remember14a@aol.com> 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\webr
oot\do_addtopic.php on line 3
>
> Notice: Use of undefined constant topic_title - assumed 'topic_title' in
> \\premfs15\sites\premium15\mrbpeace\webr
oot\do_addtopic.php on line 3
>
> Notice: Use of undefined constant post_text - assumed 'post_text' in
> \\premfs15\sites\premium15\mrbpeace\webr
oot\do_addtopic.php on line 3
>
> Warning: Cannot modify header information - headers already sent by (output
> started at \\premfs15\sites\premium15\mrbushforpeac
e\webroot\do_addtopic.php:3)
> in \\premfs15\sites\premium15\mrbpeace\webr
oot\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 = "<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 print $msg; ?>
> </body>
> </html>
> -----------------------------------------------------------------
> Form code
> ----------------------------------------------
> <?php
>
> include 'menufile.php';
> ?>
> <html><center>
> <head>
> <title>Add a Topic</title>
> </head>
> <body>
> <h1>Add a Topic</h1>
> <form method=post action="do_addtopic.php">
> <p><strong>Your E-Mail Address:</strong><br>
> <input type="text" name="topic_owner" size=40 maxlength=150>
> <p><strong>Topic Title:</strong><br>
> <input type="text" name="topic_title" size=30 maxlength=150>
> <P><strong>Post Text:</strong><br>
> <textarea name="post_text" rows=8 cols=30 wrap=virtual></textarea>
> <P><input type="submit" name="submit" value="Add Topic"></p></center>
> </form>
> </body>
> </html>
>



--
randy sesser@gmail.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com