Jump to content

X Forms from Loop, One Submit, INSERT the data one after another to same TABLE


Sherryar

Recommended Posts

I am making my own CMS, it will be revolved around custom made anime cartoons in flash.  I have quite a number of flash anime series atm, and I'm trying to implement adding them in one go.  In future I also want to extend this to games trailers and reviews, and so this would be very helpful to me if you guys could assist.

 

This is the multiadd.php file

 

	<?php	 //-- include header file and session checks, other stuff --//

echo '<div class="item">';

echo '<h1>Add Flash Anime Series</h1>

<p>Here you can determine how many flash episodes you would like to add.</p>';

if (isset($_SESSION['//-- some session check --//'])) {

require_once ('//-- the db file --//');
require_once (MYSQL);


echo '<br /><form action="multiadd.php" method="post">
<fieldset>';

echo	'<p><b>I would like to add </b><input type="INT" name="episodenum" size="2" maxlength="2" /> <b>episodes of </b>';

$q3 = "SELECT title FROM titles";

$r3 = @mysqli_query ($dbc, $q3);

echo '<select name="title">';

while ($row3 = mysqli_fetch_array($r3)) {

echo	'<option>' . $row3['title'] . '</option>';

}

echo	'</select>.';

echo	'</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit" /></div>

<input type="hidden" name="submitted" value="TRUE" />

</form>';

echo '<p><a href="view.php"><small>Back to episode list</small></a></p>';

}

else

{ echo '<p>You are not authorised.  This incident will be reported.</p>'; }

echo '</div>'; ?>



	<?php include('//-- the footer --//'); ?>

 

This is the multiadd2.php file:

 

	
<?php	 //-- include header file and session checks, other stuff --//

echo '<div class="item">';

	 echo '<h1>Multi Add</h1>

<p>Double check everything you type in, especially if you\'re adding a lot of episodes.</p>';

if (isset($_POST['submitted'])) {

require_once ('//-- the db file --//');
require_once (MYSQL);

//--- Episode Number ---//

if ( (!empty($_POST['episodenum'])) && (is_numeric ($_POST['episodenum'])) ) {

$en = mysqli_real_escape_string ($dbc, $_POST['episodenum']);

} else {

echo '<p>Please enter the <b>number</b> of episodes you want to add!</p> <p><a href="multiadd.php">Back</a></p>';

echo '</div>';

include ('//-- the footer file --//');

exit();

}

//--- Wrap this shit up ---//

}

//--- and if everything is ok ---//


//--- Then... ---//

if (isset($_SESSION['//-- some session check --//'])) {

$count = $_POST['episodenum']; //-- this is the number of episodes which the user typed in multiadd.php and will define how many forms are displayed in the loop --//

for ($i = 1; $i <= $count; $i++ ) { echo '<br /><form action="multiadd3.php" method="post">
<fieldset>';

echo '<p><b>Title:</b><br /><select name="title">';

echo	'<option>' . $_POST['title'] . '</option>';

echo	'</select></p>';

echo	'<p><b>Episode Number:</b><br /> <input type="INT" name="episodenum" size="3" maxlength="3" /></p>
<p><b>Episode Title:</b><br /> <input type="text" name="episodetitle" size="40" maxlength="200" /></p>

<p><b>Description:</b><small><br /> <textarea input type="textarea" name="episodedesc" style="width: 400px; height:100px;" maxlength="30000"></textarea></p>

<p><b>Flash/Embed/Content:</b><br /> <textarea input type="textarea" name="episodevid" style="width: 400px; height:200px;" maxlength="30000"></textarea></p>

</fieldset>';

}

echo '

<div align="center"><input type="submit" name="submit" value="Submit" /></div>

<input type="hidden" name="submitted" value="TRUE" />

</form>';

echo '<p><a href="multiadd.php"><small>Back to multi add</small></a></p>';

}

else

{ echo '<p>You are not authorised.  This incident will be reported.</p>'; }

echo '</div>'; ?>

<?php include('//-- the footer file --//'); ?>

 

Now the problem is, they all have the action to multiadd3.php, but I'm not sure how to get them to submit one after the other into the episodes table.  Here is a typical page that could handle adding one episode:

 

(addep.php)

 

<?php	 //-- include header file and session checks, other stuff --//

echo '<div class="item">';

echo '<h1>Add Flash Anime Series</h1>';

	if (isset($_POST['submitted'])) {

require_once ('//-- the db file --//');
require_once (MYSQL);

$trimmed = array_map('trim', $_POST);

//--- Episode Title ---//

$et = FALSE;

if (preg_match ('/^[A-Z \'.-]{2,200}$/i', $trimmed['episodetitle'])) {

$et = mysqli_real_escape_string ($dbc, $trimmed['episodetitle']);

} else {



echo '<p>Please enter a valid title!</p>';

}

//--- Episode Description ---//

if (!empty($_POST['episodedesc'])) {

$ed = mysqli_real_escape_string ($dbc, $_POST['episodedesc']);

} else {



echo '<p>Please enter a valid description!</p>';

}

//--- Episode Vid ---//

if (!empty($_POST['episodevid'])) {

$ev = mysqli_real_escape_string ($dbc, $_POST['episodevid']);

} else {



echo '<p>Please enter a flash video/embed or content!</p>';

}

//--- Episode Number ---//

if ( (!empty($_POST['episodenum'])) && (is_numeric ($_POST['episodenum'])) ) {

$en = mysqli_real_escape_string ($dbc, $_POST['episodenum']);

} else {



echo '<p>Please enter a valid episode number!</p>';

}

//--- Title ---//

if (!empty($_POST['title'])) {

$tt = mysqli_real_escape_string ($dbc, $_POST['title']);

} else {



echo '<p>Please select a title!</p>';

}

//--- Username ---//

$un = $_SESSION['//-- the session username --//'];

//--- Wrap this shit up ---//

}

//--- If it's gone all right ---//

if ($et && $ed && $en && $ev && $tt) {

//--- Then... ---//

$q = "SELECT episode_id FROM episode WHERE episode_title='$et'";

$r = @mysqli_query($dbc, $q);

$un = $_SESSION['//-- the session username --//'];

$q2 = "SELECT title_id FROM titles WHERE title_title='$tt'";

$r2 = @mysqli_query($dbc, $q2);

$row2 = mysqli_fetch_array($r2);

$ti = $row2['title_id'];

if (mysqli_num_rows($r) == 0) {

$q = "INSERT INTO episode (title_id, title_title, episode_title, ep_description, episode_num, episode_vid, username) VALUES ('$ai', '$at', '$et', '$ed', '$en', '$ev', '$un')";

$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />My SQL Error: " . mysqli_error($dbc));

if (mysqli_affected_rows($dbc) == 1)
{

echo "<p>The episode was added successfully.</p>

<p><a href=\"addep.php\"><small>Add another</small></a> - <a href=\"view.php\"><small>View Episode List</small></a></p>";



		echo '</div>';

include ('//-- the footer file --//');

exit();

} else {

echo '<p>The episode could not be added due to a system error.  We apologise for any inconvenience.</p>';

}


} else {

echo '<p>The episode already exists!</p>';

}

}

?>

<?php

if (isset($_SESSION['//-- some session check --//'])) {

require_once ('//-- the db file --//');
require_once (MYSQL);

echo '<br /><form action="addep.php" method="post">
<fieldset>';

$q3 = "SELECT title FROM titles";

$r3 = @mysqli_query ($dbc, $q3);

echo '<p><b>Title:</b><br /><select name="title">';

while ($row3 = mysqli_fetch_array($r3)) {

echo	'<option>' . $row3['title'] . '</option>';

}

echo	'</select></p>';

echo	'<p><b>Episode Number:</b><br /> <input type="INT" name="episodenum" size="3" maxlength="3" /></p>
<p><b>Episode Title:</b><br /> <input type="text" name="episodetitle" size="40" maxlength="200" /></p>

<p><b>Description:</b><small><br /> <textarea input type="textarea" name="episodedesc" style="width: 400px; height:100px;" maxlength="30000"></textarea></p>

<p><b>Flash/Embed/Content:</b><br /> <textarea input type="textarea" name="episodevid" style="width: 400px; height:200px;" maxlength="30000"></textarea></p>

</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit" /></div>

<input type="hidden" name="submitted" value="TRUE" />

</form>';

echo '<p><a href="view.php"><small>Back to episode list</small></a></p>';

}

else

{ echo '<p>You are not authorised.  This incident will be reported.</p>'; }

echo '</div>'; ?>



	<?php include('//-- the footer file --//'); ?>

 

 

I'd imagine that if I set up a multiadd3.php in a similar way, it would only insert the first form? Someone suggested arrays, I know the basics but still learning.  PHP & MySQL is quite fun, I am learning by creating a CMS -

 

I have a theory on how to do this, by dumping everything into an array...

 

Many thanks!

 

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.