Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with multiple queries

Newbie
 
Join Date: Aug 2007
Posts: 4
#1: Aug 2 '07
The second query works fine by itself, so why doesn't it work when the first query is in front of it and the else is triggered?
still spits out the print with no errors.

[PHP]
<? include("dbconnect.php");
$result = mysql_query("SELECT CTRL_NUM "
. "FROM inventory "
."WHERE CTRL_NUM = $_POST[ctrl_num] ");

$res = mysql_fetch_array($result);

if( $_POST[ctrl_num] = $res[0])
{

print ("Record could not be added."); print ("Item already exists.");

}
else
{
mysql_query ("INSERT INTO inventory (CTRL_NUM, PART_NUM, SHELF_BIN, UNIT_ISSUE, PART_TYPE, WHSE, VENDOR, MANUFACTUR, SYSTEM, DOM, SUB_SYS, validation, Repairstat, QAstat)
VALUES ('$_POST[ctrl_num]', '$_POST[part_num]', '$_POST[shelf_bin]', '$_POST[unit_issue]', '$_POST[part_type]', '$_POST[whse]', '$_POST[vendor]', '$_POST[manufactur]', '$_POST[system]', '$_POST[dom]', '$_POST[sub_sys]', '$_POST[validation]', '$_POST[repairstat]', '$_POST[qastat]')");

print ("Your record has been added.");
}
mysql_close();
?>
[/PHP]

jx2 jx2 is offline
Familiar Sight
 
Join Date: Feb 2007
Location: Bristol UK
Posts: 227
#2: Aug 2 '07

re: Help with multiple queries


the code looks fine
posible problem:
u trying to insert improper values into the table
e.g. char(asci) into integer column

try this after last query

echo mysql_error();

it will display the error - if any occur

hope that help
jx2
Newbie
 
Join Date: Aug 2007
Posts: 4
#3: Aug 2 '07

re: Help with multiple queries


actually it was simply as the = statement changeing the data to be entered..i wasn't sure if == was useable in php but it seems to be.
jx2 jx2 is offline
Familiar Sight
 
Join Date: Feb 2007
Location: Bristol UK
Posts: 227
#4: Aug 2 '07

re: Help with multiple queries


lol i didnt notice that eighter :-) well done
Reply