<?
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("training_system");
$now=date("Y")+543;
$sql="select * from seting where year='$now' ";
$rs=mysql_query($sql) or die(mysql_error());
$num=mysql_num_rows($rs);
if($num!=0){
$strSQL="insert into seting(year) value ('$now')";
$query_insert=mysql_query($strSQL) or die(mysql_error());
exit();
}
echo $strSQL;
//$strSQL2="update seting set year = '$now'";
//$query_update=mysql_query($strSQL2) or die(mysql_error());
//$urs=mysql_query($strSQL) or die(mysql_error());
?>
insert into seting(year) value ('2553')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 'value ('2553')' at line 1
insert into seting(year) value ('2553')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 'value ('2553')' at line 1
echo $sql; ส่วนนี้มีค่านะค่ะ select * from seting where year='2553' แต่พอ echo $num; ค่ากลับเป็น 0 ค่ะ
Code (PHP)
<?
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("training_system");
$now=date("Y")+543;
$sql="select * from seting where year='$now' ";
$rs=mysql_query($sql) or die(mysql_error());
echo $sql;