<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SYNTHESIS REACTIONS</title>
</head>
<body>
<p>
Chemistry synthesis reaction equations </p>
<p> </p>
<form name="form1" method="post" action="index.php">
<p>
<label for="A"></label>
<input type="text" name="A" id="A"> +
<input type="text" name="B" id="B">
<label for="B"></label>
</p>
<p>NB: Case Sensitive - Use Real Names!</p>
<p>
<input type="submit" name="solve" id="solve" value="Submit">
</p>
<p>
<label for="results"></label>
</text>
</p>
</form>
<p> </p>
</body>
</html>
<?php
require_once ("dbconnect.php");
/* 2. Synthesis Reactions
a. Metal + Nonmetal = a salt
i. Ag + Cl2 = AgCl
b. Metal oxides + H2O = a base
i. CuO + H2O = Cu(OH)2
c. Nonmetal oxide + H2O = an acid
i. SO2 + H2O = H2SO3 */
// validate the form
if (isset($_POST['A'] ))
{
$A = $_POST['A'];
}
else
{ ?>
<br> <? echo "data is missing "; ?> <br />
<? }
if (isset($_POST['B'] ))
{
$B = $_POST['B'];
}
else
{
echo "data is missing";
}
// Do a search in the database
$db_selected =($con);
$queryA = "SELECT symbol, charge FROM elements WHERE symbol= '" .$A. "' ";
$queryB = "SELECT symbol, charge FROM elements WHERE symbol= '" .$B. "' ";
$resultA = mysql_query($queryA);
$resultB = mysql_query($queryB);
$rowA = mysql_fetch_array($resultA);
$rowB = mysql_fetch_array($resultB);
if ($rowA['charge'] < 0)
{ ?>
<html><tr><td> <? echo" '".$rowA['element'] . $rowB['charge'] . $rowB['element'] .
$rowA['charge'] ."' "; ?>
</td></tr>
<? }
elseif ($rowA['charge'] > 0) { ?>
<tr><td> <? echo " '" .$rowB['element'] . $rowA['charge'] . $rowA['element'] .
$rowB['charge']. "' " ?>
</td></tr></html>
<? }
else { echo "Error! Please check the parameters again";}
mysql_close($con);
?>
Edwin_2 0 Newbie Poster
Edwin_2 0 Newbie Poster
diafol
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
Edwin_2 0 Newbie Poster
Edwin_2 0 Newbie Poster
GrazerC0de 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.