mysql_connect("localhost","gecky","jeck532") or die ("Database server unavailable"); mysql_select_db("artgeckzillacom") or die ("Database unavailable"); if($_POST["submit"] == "Change Both Words") { $omit = $_POST["omit_adjective_id"]; $sql = "SELECT max(adjective_id) AS max_id, count(adjective_id) AS adj_count FROM adjective"; $qry = mysql_query($sql) or die(mysql_error()); $rs = mysql_fetch_assoc($qry); $max_adj = $rs["max_id"]; $adj_count = $rs["adj_count"]; $found = false; while(!$found) { $rand_adj = rand(1,$max_adj); if($rand_adj != $omit) { $found = true; } } $sql = "SELECT * FROM adjective WHERE adjective_id = $rand_adj"; $qry = mysql_query($sql) or die(mysql_error()); $rs1 = mysql_fetch_assoc($qry); $adjective = $rs["adjective_text"]; $omit = $_POST["omit_noun_id"]; $sql = "SELECT max(noun_id) AS max_id, count(noun_id) AS noun_count FROM noun"; $qry = mysql_query($sql) or die(mysql_error()); $rs = mysql_fetch_assoc($qry); $max_noun = $rs["max_id"]; $noun_count = $rs["noun_count"]; $found = false; while(!$found) { $rand_noun = rand(1,$max_noun); if($rand_noun != $omit) { $found = true; } } $sql = "SELECT * FROM noun WHERE noun_id = $rand_noun"; $qry = mysql_query($sql) or die(mysql_error()); $rs2 = mysql_fetch_assoc($qry); } else { $sql = "SELECT max(adjective_id) AS max_id, count(adjective_id) AS adj_count FROM adjective"; $qry = mysql_query($sql) or die(mysql_error()); $rs = mysql_fetch_assoc($qry); $max_adj = $rs["max_id"]; $adj_count = $rs["adj_count"]; $found = false; $rand_adj = rand(1,$max_adj); $sql = "SELECT * FROM adjective WHERE adjective_id = $rand_adj"; $qry = mysql_query($sql) or die(mysql_error()); $rs1 = mysql_fetch_assoc($qry); $sql = "SELECT max(noun_id) AS max_id, count(noun_id) AS noun_count FROM noun"; $qry = mysql_query($sql) or die(mysql_error()); $rs = mysql_fetch_assoc($qry); $max_noun = $rs["max_id"]; $noun_count = $rs["noun_count"]; $rand_noun = rand(1,$max_adj); $sql = "SELECT * FROM noun WHERE noun_id = $rand_noun"; $qry = mysql_query($sql) or die(mysql_error()); $rs2 = mysql_fetch_assoc($qry); } if($_POST["submit"] == "Insert") { $noun_text = strtolower($_POST["noun_text"]); $adjective_text = strtolower($_POST["adjective_text"]); if(!empty($noun_text)) { $sql = "SELECT * FROM noun WHERE noun_text = '$noun_text'"; $qry = mysql_query($sql) or die(mysql_error()); $rows = mysql_num_rows($qry); if($rows == 0) { $sql = "INSERT INTO noun (noun_text) VALUES('$noun_text')"; $qry = mysql_query($sql) or die(mysql_error()); } else { echo "noun already existed
"; } } if(!empty($adjective_text)) { $sql = "SELECT * FROM adjective WHERE adjective_text = '$adjective_text'"; $qry = mysql_query($sql) or die(mysql_error()); $rows = mysql_num_rows($qry); if($rows == 0) { $sql = "INSERT INTO adjective (adjective_text) VALUES('$adjective_text')"; $qry = mysql_query($sql) or die(mysql_error()); } else { echo "adjective already existed
"; } } } $noun = $rs2["noun_text"]; $noun_id = $rs2["noun_id"]; $adjective = $rs1["adjective_text"]; $adjective_id = $rs1["adjective_id"]; ?>
There are currently adjectives and nouns for a possible 0 combinations.
new adjective:
new noun: