รันโค้ดบน host จริงไม่ได้ค่ะช่วยเเก้ไขโค้ดหน่oยค่ะ ขoบคุณค่ะ
Code (PHP)
<?php
$conn;
function Conn2DB()
{
global $conn;
global $ServerName;
global $UserName;
global $UserPassword;
global $DataBaseName;
$conn = mysql_connect( $ServerName, $UserName, $UserPassword );
if ( ! $conn )
die( "äÁèÊÒÁÒöµÔ´µè͡Ѻ MySQL ä´é" );
mysql_query( "SET NAMES utf8", $conn );
mysql_select_db( $DataBaseName, $conn )
or die ( "äÁèÊÒÁÒöàÅ×Í¡ãªé§Ò¹°Ò¹¢éÍÁÙÅ $DataBaseName ä´é" );
}
function CloseDB()
{
global $conn;
mysql_close( $conn );
}
function GetPollTitle( $sID )
{
global $conn;
$strSQL = "SELECT sTitle FROM tbl_subject WHERE sID=$sID";
$result = mysql_query( $strSQL, $conn )
or die ( "SELECT GetPollTitle มีข้อผิดพลาด" . mysql_error() );
$rs = mysql_fetch_array( $result );
return $rs[sTitle];
}
function UpdatePollVote( $iID )
{
global $conn;
$strSQL = "UPDATE tbl_item SET iVote=iVote+1 WHERE iID=$iID";
mysql_query( $strSQL, $conn )
or die ( "UPDATE มีข้อผิดพลาดเกิดขึ้น" ) . mysql_error();
}
function SumPollVote( $sID )
{
global $conn;
$strSQL = "SELECT SUM(iVote) AS Total FROM tbl_item WHERE sID=$sID ";
$result = mysql_query( $strSQL, $conn )
or die ( "SELECT SumPollVote มีข้อผิดพลาด" . mysql_error() );
$rs = mysql_fetch_array( $result );
return $rs["Total"];
}
function Insert2Log( $iID, $gIP )
{
global $conn;
$gDateLog = date( "Y-m-d H:i:s" );
$strSQL = "INSERT INTO tbl_log ( iID, gIP, gDateLog ) VALUES ( $iID, '$gIP', '$gDateLog' )";
mysql_query( $strSQL, $conn )
or die ( "INSERT มีข้อผิดพลาด" ) . mysql_error();
}
?>
Tag : PHP, MySQL
Date :
2012-02-06 20:17:40
By :
fasaiaya
View :
1046
Reply :
6
มันมี error ว่าไงอ่ะครับ
Date :
2012-02-06 20:31:49
By :
deawx
Code (PHP)
$conn = mysql_connect( $ServerName, $UserName, $UserPassword ) or die(mysql_error());
จะได้รู้ว่า error เพราะอะไร
Date :
2012-02-06 20:45:54
By :
webmaster
SELECT SumPollVote มีข้อผิดพลาด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 '' at line 1
Date :
2012-02-06 21:28:06
By :
fasaiaya
จะลoงทำค่ะ
Date :
2012-02-06 21:47:33
By :
fasaiaya
ทำแล้วค่ะไม่ได้ผลชวยดูทีนะค่ะ
Code (PHP)
รันแล้วไม่ขึ้นข้อมูล
<table width="50%" border="0" cellspacing="0" cellpadding="1" align="center">
<tr>
<td bgcolor="#FFCC00">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td align="center" class="Tahoma13"><b>:: EOL Poll สรุปผลคะแนน ::</b></td>
</tr>
<tr>
<td bgcolor="#F1F1F1" valign="top" class="Tahoma13">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<?php
include( "phpConfig.php" );
include( "phpFunctionDB.php" );
Conn2DB();
$PollTotal = SumPollVote( $sID );
$strSQL = "SELECT * ";
$strSQL .= "FROM tbl_subject AS s, tbl_item AS i ";
$strSQL .= "WHERE s.sID=i.sID ";
$strSQL .= "AND s.sID='$sID' ";
$res = mysql_query( $strSQL );
while ( $rs = mysql_fetch_array( $res ) )
{
$iVote = $rs[iVote];
if ( $PollTotal == 0 )
$CalPercent = 0;
else
$CalPercent = ( $rs[iVote] / $PollTotal ) * 100;
echo "<tr valign=\"top\">\n";
echo "<td width=\"33%\" class=\"Tahoma13\">$rs[iTitle]</td>\n";
echo "<td width=\"55%\" class=\"Tahoma13\">";
echo "<img src=\"img/green.gif\" width=\"$CalPercent\" height=\"10\"> ";
echo "($iVote)";
echo "</td>\n";
echo "<td width=\"12%\" align=\"right\" class=\"Tahoma13\">";
echo number_format( $CalPercent, 2, '.', ',' );
echo "%</td>\n";
echo "</tr>\n";
}
CloseDB();
?>
</table>
</td>
</tr>
<tr>
<td align="center" class="Tahoma13">[รวมทั้งหมด <b><?php echo $PollTotal; ?> </b>ท่าน]</td>
</tr>
</table>
</td>
</tr>
</table>
Code (PHP)
ไม่ว่าฟังก์ชันไหนก็ รันไม่ได้เลยค่ะ
<?php
$conn;
function Conn2DB()
{
global $conn;
global $ServerName;
global $UserName;
global $UserPassword;
global $DataBaseName;
$conn = mysql_connect( $ServerName, $UserName, $UserPassword )
or die( "äÁèÊÒÁÒöµÔ´µè͡Ѻ MySQL ä´é" );
mysql_query( "SET NAMES utf8", $conn );
mysql_select_db( $DataBaseName, $conn )
or die ( "äÁèÊÒÁÒöàÅ×Í¡ãªé§Ò¹°Ò¹¢éÍÁÙÅ $DataBaseName ä´é" );
}
function CloseDB()
{
global $conn;
mysql_close( $conn );
}
function GetPollTitle( $sID )
{
global $conn;
$strSQL = "SELECT sTitle FROM tbl_subject WHERE sID='$sID' ";
$result = mysql_query( $strSQL, $conn )
or die ( "SELECT GetPollTitle มีข้อผิดพลาด" . mysql_error() );
$rs = mysql_fetch_array( $result );
return $rs[sTitle];
}
function UpdatePollVote( $iID )
{
global $conn;
$strSQL = "UPDATE tbl_item SET iVote=iVote+1 WHERE iID='$iID' ";
mysql_query( $strSQL, $conn )
or die ( "UPDATE มีข้อผิดพลาดเกิดขึ้น" ) . mysql_error();
}
function SumPollVote( $sID )
{
global $conn;
$strSQL = "SELECT SUM(iVote) AS Total FROM tbl_item WHERE sID='$sID' ";
$result = mysql_query( $strSQL, $conn )
or die ( "SELECT SumPollVote มีข้อผิดพลาด" . mysql_error() );
$rs = mysql_fetch_array( $result );
return $rs["Total"];
}
function Insert2Log( $iID, $gIP )
{
global $conn;
$gDateLog = date( "Y-m-d H:i:s" );
$strSQL = "INSERT INTO tbl_log ( iID, gIP, gDateLog ) VALUES ( $iID, '$gIP', '$gDateLog' )";
mysql_query( $strSQL, $conn )
or die ( "INSERT มีข้อผิดพลาด" ) . mysql_error();
}
?>
Date :
2012-02-07 08:44:50
By :
fasaiaya
Load balance : Server 03