Forum Moderators: coopster

Message Too Old, No Replies

Problem in inserting a record

         

manvirsr

9:52 am on Jan 9, 2004 (gmt 0)



Hi people.

I am having some trouble with this piece of code that i am writing to insert a record in a database. No the record does get inserted but the immediate next line of code is not executed (Refer to "This is where i am talking about" in the code given below)

<?php
session_start();
include("./functions/config.php");
include("./functions/functions.php");

if($_SESSION["emp_id"] == "")
{
header("location: [$httpserver$httpsubdir...]
}

$department = $_POST["department"];

$query = "select department_id from departments where department = '$department'";
$result = mysql_query($query)
or die("Query Failed");

$rows = 0;
while($line = mysql_fetch_array($result))
$rows = $rows + 1;
$failed = false;
$error = false;

if($department!= "")
{
if($rows == 0 )
{
$query = "select max(department_id) from departments";
$result = mysql_query($query)
or die("Query Failed");

$line = mysql_fetch_array($result);
$department_id = $line[0] + 1;

$query1 = "insert into departments (department_id,department) values ($department_id,'$department')";

$result1 = mysql_query($query1)
or die("Query Failed");

//This is where i am talking about
if($result1 == TRUE)
{
$_SESSION["result"] = "Department $department added successfully";
$_SESSION["camefrom"] = "adddepartment.php";
header("location: [$httpserver$httpsubdir...]
}
else
{
$error = true;
}

}
else
{
// This is where i am talking about
$failed = true;
}
}
?>

now after the inserting the record in $result1=mysql_query($query1) the execution jumps to $failed = true;
Please help

justageek

2:08 pm on Jan 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a if($result) before your while and change your if($result1 == TRUE) to if($result1).