Jump to content

[SOLVED] if statement


cleary1981

Recommended Posts

Why does this not work? What I trying to do is if part_no already exists in part execute result 1, else execute result 2 and 3.

 

the code doesn't seem to do anything to either table

 

<?php
if (isset($_POST['submit']))
{
   require "config.php"; // database connection details
   
   //convert all the posts to variables:
   $mod_name = $_REQUEST['mid'];
   $pno = $_REQUEST['part_no'];
   $des = $_REQUEST['description'];
   $price = $_REQUEST['price'];
   $qty = $_REQUEST['quantity'];
   $disc = $_REQUEST['discount'];
   $sup = $_REQUEST['supplier'];
   
   // if $part_no != part_no add it to part table 
   if(mysql_num_rows(mysql_query("SELECT part_no FROM part WHERE part_no = '$pno'"))){
   $result1=MYSQL_QUERY("INSERT INTO component (c_id, module_name, part_no, quantity) VALUES ('', '$mod_name', '$pno', '$qty')") or die (mysql_error()); 
   }
   else {
   $result2=MYSQL_QUERY("INSERT INTO part (part_no, price, discount, supplier_name, description) VALUES ('$pno', '$des', '$price', '$disc', '$sup')") or die (mysql_error()); 
   //Add new part to component list
   $result3=MYSQL_QUERY("INSERT INTO component (c_id, module_name, part_no, quantity) VALUES ('', '$mod_name', '$pno', '$qty')") or die (mysql_error()); 
   }

}
?>

Link to comment
https://forums.phpfreaks.com/topic/116594-solved-if-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.