<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>&nbsp;</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>&nbsp;</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);
?>    

I have tried reporting the errors but didn't get much from it.Something to do with mysql_fetch_array(). Is it my code?

Member Avatar for diafol

Your SQL - there's a mistake in it/them somewhere.

BTW CuO is insoluble, so it doesn't form Cu(OH)2 under normal circumstances.

That error is triggered when your query fails (or the connection). Try:

$resultA = mysql_query($queryA) or die(mysql_error());
$resultB = mysql_query($queryB) or die(mysql_error());

And reply with any message you see.

Ok, that seems to give me better errors now. Thanks. I guess i forgot to specify the database. I will fix this in a few mins and see if it works.

Thanks, that does her!

something to do with sql query

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.