Skip to content

Instantly share code, notes, and snippets.

@sashaca2
Created September 16, 2012 02:19
Show Gist options
  • Save sashaca2/3730773 to your computer and use it in GitHub Desktop.
Save sashaca2/3730773 to your computer and use it in GitHub Desktop.
relational database
-- phpMyAdmin SQL Dump
-- version 3.5.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 16, 2012 at 04:16 AM
-- Server version: 5.5.25
-- PHP Version: 5.4.4
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `characters`
--
-- --------------------------------------------------------
--
-- Table structure for table `actors`
--
CREATE TABLE `actors` (
`actor_no` int(11) NOT NULL AUTO_INCREMENT,
`actor` varchar(30) DEFAULT NULL,
PRIMARY KEY (`actor_no`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;
--
-- Dumping data for table `actors`
--
INSERT INTO `actors` (`actor_no`, `actor`) VALUES
(1, 'Dwight Einsenhower'),
(2, 'Richard Nixon'),
(3, 'Josef Stalin'),
(4, ''),
(5, 'John Q. Public'),
(6, 'Little Red Riding Hood'),
(7, 'Little Miss Muffet'),
(8, 'Little Bo Peep'),
(9, 'Jack and Jill'),
(10, 'wila hoffman'),
(11, 'john hoffman'),
(12, 'sasha hoffman'),
(13, 'wila puppy'),
(14, 'battlefield of love'),
(15, 'hello world'),
(16, ''),
(17, 'working?'),
(18, 'attempt thousand'),
(19, 'loverly'),
(20, 'brain=hurt'),
(21, 'coding hell'),
(22, 'this sucks');
-- --------------------------------------------------------
--
-- Table structure for table `cartoons`
--
CREATE TABLE `cartoons` (
`toon_no` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(200) DEFAULT NULL,
PRIMARY KEY (`toon_no`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
--
-- Dumping data for table `cartoons`
--
INSERT INTO `cartoons` (`toon_no`, `title`) VALUES
(1, 'once and for all I will get this'),
(2, 'I will get this tonight!'),
(3, 'One more time for good measure'),
(4, 'trying this again'),
(5, 'should see a 5 and a 9 if this works'),
(6, 'once upon a time there was an adorable puppy named wila'),
(7, 'see if i can get this to work one more time before moving on'),
(8, 'third time is the charm'),
(9, 'wila is the cutest puppy ever!'),
(10, 'welcome to my insanity!!!!'),
(11, 'will it work with both????'),
(12, 'one of these things will break I know it'),
(13, 'once more to make sure not crazy'),
(14, 'did I do that right???'),
(15, 'will this work?'),
(16, 'once again a test'),
(17, 'trying again'),
(18, 'lucky in love and unlucky in code'),
(19, 'if I only add a new character'),
(20, 'trying to just add a new character again'),
(21, 'third tries the charm...right?'),
(22, 'and now if I only add an existing character will I add a new "blank" space?'),
(23, 'and now if I only add an existing character will I add a new "blank" space?');
-- --------------------------------------------------------
--
-- Table structure for table `cartoon_actors`
--
CREATE TABLE `cartoon_actors` (
`fk_toon_no` int(11) NOT NULL,
`fk_actor_no` int(11) NOT NULL,
KEY `fk_toon_no` (`fk_toon_no`),
KEY `fk_actor_no` (`fk_actor_no`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `cartoon_actors`
--
INSERT INTO `cartoon_actors` (`fk_toon_no`, `fk_actor_no`) VALUES
(6, 10),
(7, 11),
(8, 12),
(9, 13),
(10, 12),
(11, 14),
(11, 10),
(12, 15),
(12, 12),
(13, 16),
(13, 3),
(18, 19),
(18, 12),
(19, 20),
(20, 21),
(21, 22),
(23, 20);
--
-- Constraints for dumped tables
--
--
-- Constraints for table `cartoon_actors`
--
ALTER TABLE `cartoon_actors`
ADD CONSTRAINT `cartoon_actors_ibfk_1` FOREIGN KEY (`fk_toon_no`) REFERENCES `cartoons` (`toon_no`),
ADD CONSTRAINT `cartoon_actors_ibfk_2` FOREIGN KEY (`fk_actor_no`) REFERENCES `actors` (`actor_no`);
<html>
<head>
<title>Update Cartoon Table of Database</title>
</head>
<body>
<form method="post" action="update4.php">
<?php
mysql_connect ("localhost", "root", "root") or die('Error: . . .');
//echo "Connected to server <br />";
mysql_select_db ("characters");
//echo "Connected to database <br />";
echo "<br />";
?>
<br />Enter Caption for Cartoon:<br />
<textarea name='caption' cols=50 rows=4></textarea>
<br />Add New Character:
<input type="text" name="new_actor" size="30"/><br />
and/or Choose a Character
<select name="actor" multiple="yes" size="7">
<option value="empty"> --- </option>
<?php
$actorq = "SELECT actor_no, actor FROM actors 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>";
}
?>
<br /><br /><input type='submit' value='SUBMIT'/>
</form>
</body>
</html>
<html>
<head>
<title>Updated Database</title>
</head>
<body>
<?php
mysql_connect ("localhost", "root", "root") or die('Error: . . .');
//echo "Connected to server <br />";
mysql_select_db ("characters");
//echo "Connected to database <br />";
echo "<br />";
?>
<?php
$toon_to_add=$_POST['caption'];
$new_toon = "INSERT INTO cartoons (toon_no, title) VALUES ('NULL', '".$toon_to_add."')";
mysql_query($new_toon) or die('Error adding new cartoon');
$new_toon_id = mysql_insert_id();
echo "<br />cartoon (" .$new_toon_id .") successfully added to database<br />";
$char_to_add=$_POST['new_actor'];
if ($char_to_add >= 1)
{
$new_char = "INSERT INTO actors (actor_no, actor) VALUES ('NULL', '".$char_to_add."')";
mysql_query($new_char) or die('Error adding new character');
$new_char_id = mysql_insert_id();
echo "<br />character (" .$new_char_id .") successfully added to database<br />";
} else
{
echo "No New Character Added<br />";
}
if ($char_to_add >= 1)
{
if ($new_toon_id >= 1)
{
$new_cartoon_actor = "INSERT INTO cartoon_actors (fk_toon_no, fk_actor_no) VALUES
('".$new_toon_id."', '".$new_char_id."')";
mysql_query($new_cartoon_actor) or die('Error updating cartoon actor table with new actor');
echo "<br />new cartoon and new character successfully added to joiner table<br />";
}
} else
{
echo "No new characters to add to joiner table";
}
$cartoon_actor=$_POST['actor'];
if ($cartoon_actor >= 1)
{
$old_cartoon_actor = "INSERT INTO cartoon_actors (fk_toon_no, fk_actor_no) VALUES
('".$new_toon_id."', '".$cartoon_actor."')";
mysql_query($old_cartoon_actor) or die('Error updating cartoon actor table with existing actor');
echo "<br />new cartoon and old character successfully added to joiner table<br />";
} else
{
echo "No Existing Character Added to Joiner table<br />";
}
/*
$q = "SELECT * FROM cartoon_actors";
$r = mysql_query($q) or die(mysql_error());
while($row = mysql_fetch_array($r)){
echo $row['fk_toon_no']. " - ". $row['fk_actor_no'];
echo "<br />";
*/
?>
<br /><a href="http://localhost:8888/dropdown2.php">Return to entry form</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment