Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
PHP
<?php
include('connect.php');
?>
<?php
session_start();
?>
         
		<?php
		if (isset($_SESSION['dob']) && isset($_SESSION['month']) && isset($_POST['present'])) {
		$dob=$_SESSION['dob'];
		$month=$_SESSION['month'];
		}
			$s=$_POST['present'];
			$p="1";
			foreach( $s as $value=>$var)
			     {
			 $sql= "UPDATE atten SET total=total+1 where roll ='$var'";
			 $mont="UPDATE $month SET $dob='$p' where roll='$var'";
		echo $sql . " " . $mont;  
				 mysql_query($sql) or die(mysql_error());
				 mysql_query($mont) or die(mysql_error());
				 
			}
			}
			
			?>

my complete code is above and my error in this code only.
PHP
$mont="UPDATE $month SET $dob='$p' where roll='$var'";
how to update database table.?
Posted
Comments
Maarten Kools 20-Dec-13 11:14am    
And the error is...?

I would advise you to use prepared statements instead of what you are doing now. This makes your code vulnerable to SQL injection[^].
rao0088 20-Dec-13 11:25am    
thanks for advise ...
ZurdoDev 20-Dec-13 11:34am    
What's the error?
rao0088 20-Dec-13 22:55pm    
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET --='1' where roll='901'' at line 1
Peter Leow 31-Dec-13 7:16am    
Have you solved your problem already? If not, could you show the code for the calling page. Not enough information. Please use the "Improve question" button.

1 solution

Hi friend, obviously there is an error,

See it and if it resolved your problem do mark it as solved :)

Here's the issue,
Your MYSQL query is
PHP
  $mont="UPDATE $month SET $dob='$p' where roll='$var'";
?>

And the error is $month and $dob ... My friend, you have to use the field name in the table in your database. Also, the table name can be month and not $month. It is possible that the table field name is dob so...

If field name is dob and table name is month, the correction is
PHP
  $mont="UPDATE month SET dob='$p' where roll='$var'";
?>


One more point to make though is, you should always place session_start() the very first line of code even before any include.

I am sure it will solve your problem. Do mark it :) Thank you.

With Regards
Tushar Srivastava
 
Share this answer
 
v2
Comments
rao0088 29-Dec-13 11:53am    
my friend here $dob is a column name which is select dynamically my user like date
Er. Tushar Srivastava 29-Dec-13 13:33pm    
Then you have to try using sprintf function to build the query and then execute it using mysql_query. That will possibly solve the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900