Jump to content


Photo

Form submit help


  • Please log in to reply
1 reply to this topic

#1 ryan.od

ryan.od
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 01 October 2006 - 02:08 AM

I have a form that targets itself and is used to insert into a db. It works fine, but I want it to insert and then reload the form for another submission (with a little blurb telling them it inserted the last one successfully). Right now it will only do the IF part upon submission rather than the ELSE part.

I am currently using the following code. Can I put another copy of the form in the 'IF' part? I tried that and it didn't work. Any suggestions would be appreciated!

Thanks,
Ryan

--
<html>
<head>
<title>Add New MySQL User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if(isset($_POST['add']))
{
include_once('db_connect.php');
mysql_select_db ('evaluati_blog');

$query = "INSERT INTO blog_main (title_main, intro_main, content_main) VALUES ('$title', '$intro', '$content')";
$result = @mysql_query ($query);

if($result) {
echo 'Blog inserted! ';
}
else {
echo 'Sorry';
}

include 'db_close.php';

}

else
{
?>

<div id="wrapper">
<form action="blog_submit.php" method="POST">
<fieldset><legend>Article Submission</legend>
<div id="main">
<table cellpadding="5" cellspacing="0" border="1">
<tr valign="bottom">
  <td width="150" valign="bottom" >
  <label for="q8">Title <span class="required">*</span></label>
  </td>
  <td valign="bottom">
  <input type="text" size="40" name="title" id="q8">
  </td>
</tr>

<tr valign="bottom">
  <td width="150" valign="bottom" >
  <label for="q9">Intro</label>
  </td>
  <td valign="bottom">
  <input type="text" size="40" name="intro" id="q9">
  </td>
</tr>

<tr valign="bottom">
  <td width="150" valign="top"  >
  <label for="q6">Blog<span class="required">*</span></label>
  </td>
  <td valign="bottom">
  <textarea wrap="soft" cols="30" rows="8" name="content" id="q6"></textarea>
  </td>
</tr>

<tr valign="bottom">
  <td width="150" valign="top"  >
  <label for="q7">Category<span class="required">*</span></label>
  </td>
  <td valign="bottom">
  <?php
    include_once('db_connect.php');
mysql_select_db ('evaluati_blog');
$query  = "SELECT * FROM blog_category";
$result = mysql_query($query);
  while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<input type=\"radio\"  id=\"\" name=\"{$row['subject']}\" value=\"{$row['subject']}\">";
echo "{$row['subject']}<br />";
}
include_once('db_close.php');
  ?>
  </td>
</tr>

<tr valign="bottom">
  <td width="150" valign="bottom" >
 
  </td>
  <td valign="bottom">
    <input type="submit" name="add" id="add" value="Submit">
  </td>
</tr>
</table>
</div>
</fieldset>
</form>
</div>
<?php
}
?>
</body>
</html>

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 October 2006 - 03:01 AM

Then just lose the else structure. That way the form will submit, post data, and display again ready for the next time.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users