hi i would like to update the lecturer lec_id of an module if that module does not have an lecturer a signed, but same time must not update the modules lecuturer when there is already one present... the columns in table module are mod_id, mod_name, lec_id..
mod_id and mod_names have been preset, thus just lec_id needs to be inserted or updated through form which then sent results to this code...please help noob

function mysql_evaluate($query, $default_value="undefined") {
    $result = mysql_query($query);
    if (mysql_num_rows($result)==0)
        return "<br/>hello ".$default_value;
    else
        return "<br/> mysql ".mysql_result($result,0);		
}
if (isset($_POST['submitted'])&&(is_array($module)))
{
foreach($module as $key => $value)
	   {
//check if the module selected is PHP
$query = "SELECT mod_name FROM module WHERE mod_name='$value'";
$result = mysql_query($query);

$row = mysql_fetch_array ($result , MYSQL_ASSOC);

    
	if($row['mod_name']==$value)
    {  
	
	
	$customer_type = mysql_evaluate("SELECT lec_id FROM module WHERE mod_name='$value'", "some_one_");
	echo  "<br/>customer ".$customer_type;
	$result=mysql_query($customer_type);
	if (!empty($result)) 
	{ 
	
	echo '<br/><br/>Ok,'. $name.',you are now registered';
       $querys = "UPDATE module SET lec_id='$name' WHERE mod_name='$value'";
       $results = mysql_query($querys);
       
    }
	else
	{
	 echo "<br/>Could not register you";
	  
	}
       }

	   }

print "</br></br></br></br>";

}

why don't you select those records from the table where the lec_id is empty? And then make update code for them only.

are you sure $customer_type is a valid SQL query?

it has a returned valus from these two options:
"<br/>hello " . $default_value
or
"<br/> mysql " . mysql_result( $result, 0 )


If that is a requirement, not to allow more then 1 one lec_id in the table's lec_id field, then apply a unique key for that table to filter duplication. When you insert the lec_id , or update the table you will get duplicate entry error code, and you then say, its not allowed.

the problem im having is that a lecturer can be assigned to more than one module but a lecturer cannot be assigned to a module whom already has been assigned to a lecturer.

my code is dumb, ive tried weird things. im not succesful in just adding a lecturer where there is no lecturer assigned to a module.. a lecturer can select a module another has been assigned to but he or she cannot owerrite that lectuer, the system should not allow it..

i just want code to update lec_id at a module where the is no lecturer...mod_id is the primary key

you can update the modules table with a query like this (change the field and table names and insert the LEC ID and moduleID with php variables):

UPDATE `modules` SET `Lec_ID` = '1' WHERE `modules`.`modulD` =1 AND Lec_ID =0 LIMIT 1 ;

means: update the modules table to a lecture with ID=1 where the moduleID is 1 and the Éecture is empty.

then on php:

<?php
if(mysql_affected_rows()==1) 
{
print "updated successfully...";
}
else
print "Couldnot update, this module has been in used.";
?>

thanx ill try it....

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.