Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ขึ้น Error แบบนี้อะครับ 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



 

ขึ้น Error แบบนี้อะครับ 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

 



Topic : 111772



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์




คือผมทดลองสร้างเว็บบอร์ดใน Appserv ครับรันได้ไม่มีปัญหา

พอโยนไฟล์ลง server (Linux SIS)ที่จำลองขึ้นมาด้วยโปรแกรม VMware ด้วย Filezilla แล้วลองเปิดหน้า แสดงความคิดเห็น ดันขึ้น Error แบบนี้

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

ไม่ทราบว่าเป็นเพราะ อะไรหรอครับ อันนี้โค้ด
Code (PHP)
<?php require_once('Connections/MyConnect.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO ans (w_id, a_detail, a_date, Username) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['w_id'], "int"),
                       GetSQLValueString($_POST['a_detail'], "text"),
                       GetSQLValueString($_POST['a_date'], "date"),
                       GetSQLValueString($_POST['Username'], "text"));

  mysql_select_db($database_MyConnect, $MyConnect);
  $Result1 = mysql_query($insertSQL, $MyConnect) or die(mysql_error());

  $insertGoTo = "webboard.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_login = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_login = $_SESSION['MM_Username'];
}
mysql_select_db($database_MyConnect, $MyConnect);
$query_login = sprintf("SELECT * FROM member WHERE Username = %s", GetSQLValueString($colname_login, "text"));
$login = mysql_query($query_login, $MyConnect) or die(mysql_error());
$row_login = mysql_fetch_assoc($login);
$totalRows_login = mysql_num_rows($login);

mysql_select_db($database_MyConnect, $MyConnect);
$query_web = "SELECT web.w_id, web.w_topic, web.w_detail, web.w_date, member.Username, member.Photo, member.Firstname, member.Lastname FROM web, member WHERE web.Username=member.Username  AND web.w_id=$w_id";
$web = mysql_query($query_web, $MyConnect) or die(mysql_error());
$row_web = mysql_fetch_assoc($web);
$totalRows_web = mysql_num_rows($web);

mysql_select_db($database_MyConnect, $MyConnect);
$query_ans = "SELECT ans.a_id, ans.a_detail, ans.a_date, member.Firstname, member.Lastname, member.Photo, member.Username, ans.w_id FROM ans, member WHERE ans.Username=member.Username  AND ans.w_id=$w_id";
$ans = mysql_query($query_ans, $MyConnect) or die(mysql_error());
$row_ans = mysql_fetch_assoc($ans);
$totalRows_ans = mysql_num_rows($ans);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['uname'])) {
  $loginUsername=$_POST['uname'];
  $password=$_POST['pword'];
  $MM_fldUserAuthorization = "LV";
  $MM_redirectLoginSuccess = "loginok.php";
  $MM_redirectLoginFailed = "loginfail.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_MyConnect, $MyConnect);
  	
  $LoginRS__query=sprintf("SELECT Username, Password, LV FROM member WHERE Username=%s AND Password=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $MyConnect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'LV');
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<style type="text/css">
a:link {
	color: #00F;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #00F;
}
a:hover {
	text-decoration: none;
	color: #F00;
}
a:active {
	text-decoration: none;
	color: #00F;
}
</style>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#F4F4F4"><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><div align="right">
          <form id="form1" name="form1" method="post" action="<?php echo $loginFormAction; ?>">
            <?php if($row_login['Username']=="") { ?>
            <label for="uname">Username : </label>
            <input type="text" name="uname" id="uname" placeholder=" Username"/>
            <label for="pword">Password : </label>
            <input type="password" name="pword" id="pword" placeholder=" Password"/>
            <input name="button" type="submit" class="btn" id="button" value="Login" />
            <a href="register.php">
              <input name="button" type="button" class="btn" id="button" value="Register"/>
              </a>
            <?php }else{ ?>
            ยินดีต้อนรับคุณ : 
            
            &nbsp;<?php echo $row_login['Username']; ?> <a href="<?php echo $logoutAction ?>">
              <input name="button" type="button" class="btn" id="button" value="ออกจากระบบ"/>
              </a> <a href="profile_edit.php">
                <input name="button" type="button" class="btn" id="button" value="แก้ไขข้อมูลส่วนตัว"/>
                </a>
            <?php } ?>
          </form>
        </div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor="#99FF00"><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><table width="1000" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td bgcolor="#00FFFF">&nbsp;<a href="webboard.php">Webboard</a></td>
          </tr>
          <tr>
            <td align="center" bgcolor="#FFFFFF"><p>&nbsp;</p>
              <table width="80%" border="0" cellspacing="0" cellpadding="3">
                <tr>
                  <td width="18%" align="center" bgcolor="#00FFFF">หัวข้อ</td>
                  <td colspan="3" bgcolor="#00FFFF"><?php echo $row_web['w_topic']; ?></td>
                  </tr>
                <tr>
                  <td align="center" bgcolor="#CCCCCC"><img src="img-member/<?php echo $row_web['Photo']; ?>" width="150" /></td>
                  <td colspan="3" valign="top" bgcolor="#E6E6E6"><p><?php echo $row_web['w_detail']; ?></p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p></td>
                  </tr>
                <tr>
                  <td align="center" bgcolor="#999999">ผู้โพส</td>
                  <td width="41%" bgcolor="#999999"><?php echo $row_web['Firstname']; ?> <?php echo $row_web['Lastname']; ?></td>
                  <td width="14%" align="center" bgcolor="#999999">

                   <?php if($row_login['LV']=="admin"||$row_login['Username']==$row_web['Username']) { ?>
                   แก้ไข | ลบ
                   <?php } ?></td>
                  <td width="27%" align="right" bgcolor="#999999">เมื่อเวลา : <?php echo $row_web['w_date']; ?></td>
                </tr>
              </table>
              <?php if($row_ans['a_id']=="") { ?><h2>
                <br />
                ยังไม่มีผู้แสดงความคิดเห็น <?php }else{ ?>
                <br />
              </h2>
              <?php do { ?>
                <table width="70%" border="0" cellspacing="0" cellpadding="3">
                  <tr>
                    <td colspan="4" align="center" bgcolor="#006600"><font color="#FFFFFF"><strong>ความคิดเห็นที่ <?php echo ++$n; ?></strong></font></td>
                    </tr>
                  <tr>
                    <td width="18%" align="center" bgcolor="#CCCCCC"><img src="img-member/<?php echo $row_ans['Photo']; ?>" width="150" /></td>
                    <td colspan="3" valign="top" bgcolor="#E6E6E6"><p><?php echo $row_ans['a_detail']; ?></p>
                      <p>&nbsp;</p>
                      <p>&nbsp;</p>
                      <p>&nbsp;</p>
                      <p>&nbsp;</p></td>
                    </tr>
                  <tr>
                    <td align="center" bgcolor="#999999">ผู้โพส</td>
                    <td width="32%" bgcolor="#999999"><?php echo $row_ans['Firstname']; ?> <?php echo $row_ans['Lastname']; ?></td>
                    <td width="15%" align="center" bgcolor="#999999"><?php if($row_login['LV']=="admin"||$row_login['Username']==$row_ans['Username']) { ?>
                      <a href="comment_edit.php?a_id=<?php echo $row_ans['a_id']; ?>&amp;w_id=<?php echo $row_web['w_id']; ?>">แก้ไข</a> | <a href="comment_delete.php?a_id=<?php echo $row_ans['a_id']; ?>&amp;w_id=<?php echo $row_web['w_id']; ?>">ลบ</a><?php } ?></td>
                    <td width="35%" align="right" bgcolor="#999999">เมื่อเวลา : <?php echo $row_ans['a_date']; ?></td>
                    </tr>
                </table>
                <br />
<?php } while ($row_ans = mysql_fetch_assoc($ans)); ?>
<?php } ?>
<br />
<br />
<br /><?php if($row_login['Username']=="") {}else{ ?>
<hr />
              <form action="<?php echo $editFormAction; ?>" id="form2" name="form2" method="POST">
                <table width="200" border="1">
                  <tr>
                    <td><img src="img-member/<?php echo $row_login['Photo']; ?>" width="150" /><br />
                      <?php echo $row_login['Firstname']; ?> <?php echo $row_login['Lastname']; ?></td>
                    <td><textarea name="a_detail" id="a_detail" cols="80" rows="10"></textarea></td>
                  </tr>
                </table>
                <label for="a_detail"><br />
                </label>
                <br />
                <input type="submit" name="button2" id="button2" value="แสดงความคิดเห็น" />
                <input name="a_date" type="hidden" id="a_date" value="<?php echo date("Y-m-d H:i:s");?>" />
                <input name="Username" type="hidden" id="Username" value="<?php echo $row_login['Username']; ?>" />
                <input name="w_id" type="hidden" id="w_id" value="<?php echo $row_web['w_id']; ?>" />
                <input type="hidden" name="MM_insert" value="form2" />
              </form><?php } ?>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor="#CCCCCC"><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($login);

mysql_free_result($web);

mysql_free_result($ans);
?>





Tag : PHP, MySQL









ประวัติการแก้ไข
2014-10-07 00:37:48
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-10-07 00:23:26 By : team000000 View : 1026 Reply : 4
 

 

No. 1



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้คือไฟล์ MyConnect.php ครับ
Code (PHP)
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_MyConnect = "localhost";
$database_MyConnect = "test_webboard1";
$username_MyConnect = "admin";
$password_MyConnect = "123456";
$MyConnect = mysql_pconnect($hostname_MyConnect, $username_MyConnect, $password_MyConnect) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("Set Names UTF8"); 
?>


ผิดพลาดประการใด ขอคำชี้แนะด้วยครับ

กำลังหัดทำ








ประวัติการแก้ไข
2014-10-07 00:36:15
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-07 00:24:57 By : team000000
 


 

No. 2



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์


แก้ไขได้แล้วนะครับ

ต้องสร้างตัวแปร รับค่าที่ส่งมา $w_id=$_GET['w_id'];

งงอยู่ตั้งนาน แต่ทำไมใน Appserv ถึงไม่มีปัญหา
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-07 14:29:03 By : team000000
 

 

No. 3



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


Appserv แปลงค่าตัวแปร GET POST มาอยู่ในรูปตัวแปรที่พร้อมใช้งานได้เลย

ส่วน ใน linux ไม่ได้แปลงค่าให้ครับ

เช่น $_GET['data']; Appserver แปลงค่าให้ สามารถเรียกใช้ echo $data แบบนี้ได้เลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-07 20:38:52 By : Chaidhanan
 


 

No. 4



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เลิกใช้ Dreamweaver ครับ แล้วหันมาเขียนเองครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-07 21:21:22 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขึ้น Error แบบนี้อะครับ 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
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่