Jump to content

Form submit help


ryan.od

Recommended Posts

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.