Page 1 of 1

strange update problem ..or edit problem

Posted: Mon Jul 03, 2006 11:46 am
by rami
strange edit problem

i am trying to update result of student
well
i have
result(user_id,subject1,gradeone,remarks,semester)
ok feild names are adjusted for simplicity

for every student for every semester different rows are entered like
212021,english,A,"GOOD",1
212021,Maths,B,"OK",2

now i was trying to edit data(already entered) using user_id and semester
but problem is that when i do
$query = "update result set subone='$s1',gone='$g1',remarks='$rm' where (semester like '$sem' and user_id='$cb1')";

it does not work
it does not show any error message and says data has been updated but no changes takes place
if i do only where(user_id='$cb1') ie do taking only one columns it works
cannot i use two colums to filters data to be updated
please help
how can i do that

Code: Select all

<?php 
 session_start();
$page_title = 'Edit notice';
$cb1 = (isset($_GET['cb1'])) ?(int)($_GET['cb1']) : ""; 
$sem = (isset($_GET['sem'])) ?(int)($_GET['sem']) : ""; 
echo $sem;
if (isset($_POST['submit'])) { 
	require_once ('../databaseconnect.php');	

		$s1 = ($_POST['sub1']);
	
		$g1 = ($_POST['g1']);
	

	
		$rm = ($_POST['remarks']);
	
	echo $sem;
	if ($s1 && $g1 && $rm )
 { 
$query = "update result set subone='$s1',gone='$g1',remarks='$rm' where (semester like '$cb1' and user_id='$sem')";
			
$result = mysql_query($query) 
    or die('MySQL error: ' . mysql_error() . "<br/><br />$query");
			if ($result) { // If it ran OK.
			
				
				echo '<h3><center>The data has been updated!</center></h3>';
echo " <a href=\"index.php\"><center>Home</center></a>";
echo " <a href=\"pathmain.php\"><center>Admin Home</center></a>";
								exit();				
				
			} else { 
				
				echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>'; 
			}		
			
		
		mysql_close(); // Close the database connection.

	} else { // If one of the data tests failed.
		echo '<p><font color="red" size="+1">Please try again.</font></p>';		
	}

} // End of the main Submit conditional.
?>
<center><h1>Edit Notice</h1></center>
<table border="1" width="100%" bordercolor="#0000FF" bordercolorlight="#0000FF" bordercolordark="#0000FF">
  <tr>
    <td width="100%">
           <form action="<?php echo $_SERVER['PHP_SELF'] . '?cb1=' . $cb1; ?>" method="POST"> 
        <p align="center">&nbsp;&nbsp;&nbsp;&nbsp; <b>Edit&nbsp; Notice</b></p>
        <table border="0" width="100%" bgcolor="#EFEFEF">
          <tr>
            <td width="100%" colspan="3" bgcolor="#00659C">
              <p align="center"><b>&nbsp;<font color="#FFFFFF">Update the profile where required leaving other fileds intact,which should not be updated.</font></b></td>
          </tr>
<tr>
            <td width="41%"><b>Subject 1</b></td>
            <td width="59%"><input type="text" name="sub1" size="30" maxlength="30" value="<? 	require_once ('../databaseconnect.php');	
$query = "SELECT subone,user_id,semester FROM result WHERE (semester like \"$cb1\" and user_id='$sem')";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
$pron=$row['subone'];
echo $pron ?>" /></td>
          </tr>
<tr>
            <td width="41%"><b>Grade 1</b></td>
            <td width="59%"><input type="text" name="g1" size="20" maxlength="20" value="<? 	require_once ('../databaseconnect.php');	
$query = "SELECT gone,user_id,semester FROM result WHERE (semester like \"$sem\" and user_id='$cb1')";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
$pron1=$row['gone'];
echo $pron1 ?>" /></td>
          </tr>



<td width="41%"><b>Description</b></td>
            <td width="59%"><textarea name="remarks" cols="40" rows="5"><? require_once ('../databaseconnect.php');	
$query = "SELECT remarks,user_id,semester FROM result WHERE (semester like \"$sem\" and user_id='$cb1')";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
$pron10=$row['remarks'];
echo $pron10 ?></textarea></td>
          </tr>          
        </table>
        <p>&nbsp;</p>
        <p><div align="center"><input type="submit" name="submit" value="update" /></div></p>
      </form>
      <p>&nbsp;</td>
  </tr>
</table>
<?php // Include the HTML footer.
?>

Posted: Mon Jul 03, 2006 12:05 pm
by Burrito
try echoing your query to make sure it's really what you think it is. Syntactically it looks fine (although you might try removing your parenthesis around your where clause (they're not needed).

Posted: Mon Jul 03, 2006 12:20 pm
by rami
Burrito wrote:try echoing your query to make sure it's really what you think it is. Syntactically it looks fine (although you might try removing your parenthesis around your where clause (they're not needed).
i have done that as well
i dont think its problem with quotes
if i do one at time
either with user_id or use semester (one at a time )
it works fine
when i try to combine both in one then things does not works
any way
thanks for reply
but ? not solved yet

Posted: Mon Jul 03, 2006 12:35 pm
by Burrito
try doing a select off of the database with both of those conditions to make sure there's a row that meets both of them.