Created
September 17, 2012 03:12
-
-
Save sashaca2/3735366 to your computer and use it in GitHub Desktop.
Development Database in Progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Update Cartoon Database</title> | |
</head> | |
<body> | |
<h2>Add New Cartoon to Database</h2> | |
<form method="post" action="updatedev.php"> | |
<?php include 'connect-db.php'?> | |
<?php | |
echo "<br />"; | |
$artistq = "SELECT artist_no, f_name, l_name, paper FROM cartoonists"; | |
$artistr = mysql_query($artistq) or die(mysql_error()); | |
echo "Select Cartoonist: *<br />"; | |
$artistdd = "<select name='artist' size='4'>"; | |
while($row = mysql_fetch_assoc($artistr)) | |
{$artistdd .="\r\n<option value='{$row['artist_no']}'>{$row['f_name']} {$row['l_name']}: {$row['paper']}</option>"; | |
} | |
$artistdd .= "\r\n</select>"; | |
echo $artistdd; | |
echo "<br />"; | |
?> | |
<br />Enter Cartoon Publication Date: <em>(mm/dd/yyyy)</em> * | |
<input type="text" name="pub_date" size="10" /><br /> | |
<br />Enter Caption for Cartoon: *<br /> | |
<textarea name='caption' cols=50 rows=4></textarea> | |
<br /></br />Add New Character(s): <em>use comma ', ' for multiple entries</em><br /> | |
<input type="text" name="new_actors" size="50"/><br /> | |
<br />and/or Choose Character(s): <em>command or control for multiple entries</em></br /> | |
<select name="actors[]" multiple="yes" size="10"> | |
<option value="empty"> --- </option> | |
<?php | |
$actorq = "SELECT actor_no, actor FROM characters ORDER BY actor asc"; | |
$actorr = mysql_query($actorq) or die(mysql_error()); | |
while($row = mysql_fetch_assoc($actorr)) { | |
echo "<option value='{$row['actor_no']}'>{$row['actor']}</option>"; | |
} | |
?> | |
</select></br /> | |
<br /><input type='submit' value='SUBMIT'/><br /> | |
<br /> | |
* required | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Updated Cartoon Database</title> | |
</head> | |
<body> | |
<?php include 'connect-db.php'?> | |
<?php | |
// check connection | |
if (mysqli_connect_error()) | |
{ | |
exit('Connect failed: '. mysqli_connect_error()); | |
} | |
?> | |
<?php | |
//This section of code is generating a new cartoon entry and creating/getting it's primary key | |
$artist_id =mysql_real_escape_string($_POST['artist']); | |
$caption =mysql_real_escape_string($_POST['caption']); | |
$date = explode('/', $_POST['pub_date']); | |
$mysqlPDate = $date[2].'-'.$date[0].'-'.$date[1]; | |
$new_toon = "INSERT INTO cartoons (toon_no, fk_artist_no, p_date, title) | |
VALUES ('NULL', '".$artist_id."', '".$mysqlPDate."', '".$caption."')"; | |
if ($caption == "") { | |
die('Error you must add a caption<br /><a href="http://www.digitalpraxis.sashahoffman.org/formdev.php">Return to entry form</a>'); | |
} | |
if ($mysqlPDate == "") { | |
die('Error you must add a date<br /><a href="http://www.digitalpraxis.sashahoffman.org/formdev.php">Return to entry form</a>'); | |
} | |
if ($artist_id == 0) { | |
die('Error you must select a cartoonist<br /><a href="http://www.digitalpraxis.sashahoffman.org/formdev.php">Return to entry form</a>'); | |
} elseif ($artist_id >= 1) { | |
mysql_query($new_toon) or die('Error adding new cartoon '); | |
$new_toon_id = mysql_insert_id(); | |
echo "<br />Cartoon (" .$new_toon_id .") with the caption - \"" .$caption ."\" - successfully added to CARTOONS table<br />"; | |
} else | |
{ | |
die('Error you must add a new cartoon<br /><a href="http://www.digitalpraxis.sashahoffman.org/formdev.php">Return to entry form</a>'); | |
} | |
?> | |
<?php | |
//code that adds new character to actor table and new character and new cartoon to joiner table | |
$char_to_add=mysql_real_escape_string($_POST['new_actors']); | |
$new_char_arr = explode(', ', $char_to_add); | |
foreach ($new_char_arr as $new_char_add) | |
{ | |
if (!empty($new_char_add)) | |
{ | |
$new_char = "INSERT INTO characters (actor_no, actor) VALUES ('NULL', '".$new_char_add."')"; | |
mysql_query($new_char) or die('Error adding new character'); | |
$new_char_id = mysql_insert_id(); | |
echo "<br />New character - " .$new_char_add ." (" .$new_char_id .") successfully added to CHARACTERS table<br />"; | |
$new_cartoon_actor = "INSERT INTO cartoon_characters (fk_toon_no, fk_actor_no) VALUES | |
('".$new_toon_id."', '".$new_char_id."')"; | |
mysql_query($new_cartoon_actor) or die('Error updating cartoon_characters table with new actor'); | |
echo "<br />New cartoon (" .$new_toon_id .") and new character (" .$new_char_id .") successfully added to CARTOON_CHARACTERS table<br />"; | |
} else | |
{ | |
echo "<br />No New Character Added to Database or Joining Table<br />"; | |
} | |
} | |
?> | |
<?php | |
// This code creates array of existing characters puts those values into joiner table with new cartoon | |
$cartoon_actors=($_POST['actors']); | |
foreach($cartoon_actors as $cartoon_actor) { | |
if ($cartoon_actor >= 1) | |
{ | |
$old_cartoon_actor = "INSERT INTO cartoon_characters (fk_toon_no, fk_actor_no) VALUES | |
('".$new_toon_id."', '".$cartoon_actor."')"; | |
mysql_query($old_cartoon_actor) or die('Error updating cartoon_characters table with existing actor'); | |
echo "<br />New cartoon (" .$new_toon_id .") and existing character (" .$cartoon_actor .") successfully added to CARTOON_CHARACTERS table<br />"; | |
} else | |
{ | |
echo "<br />No Existing Character Added to Joining Table<br />"; | |
} | |
} | |
?> | |
<br /><a href="http://www.digitalpraxis.sashahoffman.org/formdev.php">Return to entry form</a> | |
<br /><a href="http://www.digitalpraxis.sashahoffman.org">Return to Portfolio Development Homepage</a> | |
<br /><a href="https://gist.github.com/3735366">See the Code</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment