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
https://forums.phpfreaks.com/topic/22630-form-submit-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.