내가 뭘 잘못하고 있니?클래스를 사용하여 데이터베이스에 삽입
오류 :
mysql_query() expects parameter 2 to be resource, string given in <b>php_includes/subscribers.php</b> on line <b>11</b><br />
<b>Warning</b>: mysql_query() expects parameter 2 to be resource, string given php_includes/comments.php</b> on line <b>19</b><br />
{"user":null,"comment":null,"error":true,"Comment":null}
코드 :
<?php
if(isset($_POST['task'])&& $_POST['task']=='comment_insert'){
require_once("php_includes/db_conx.php");
$userName= $_POST['userName'];
$userId=(int)$_POST['userId'];
$comment=addslashes(str_replace("\n" , "<br>" , $_POST['comment']));
$std= new stdClass();
$std->user=null;
$std->comment=null;
$std->error=false;
require_once("comments.php");
if(class_exists('Comments') && class_exists('Subscribers'))
{
$userInfo = Subscribers::getSubscriber($userId);
if($userId == null)
{
$std->error=true;
}
$commentInfo = comments ::insert ($comment,$userId);
if($commentInfo == null)
{
$std->error=true;
}
$std -> user = $userInfo;
$std -> Comment = $commentInfo;
}
echo json_encode($std);
}
else{
header('location:/jobs_article.php');
}
?>
/////////////////////////////////subscribers.php//////////////////////
<?php
require_once("comments.php");
class Subscribers{
public static function getSubscriber($userId){
require_once("db_conx.php");
$sql = " select * from users where id = $userId";
$query = mysql_query($db_conx,$sql);
if($query){
if(mysql_num_rows ($query)==1)
{
return mysql_fetch_object($query);
}
} return null;
}
}?>
/////////////////////////////////end of subscribers.php//////////////////////
///////////////////////////////////////////comments.php////////////////////////////
<?php
require_once("db_conx.php");
require_once("subscribers.php");
class Comments {
public static function getComments($userId){
//return a stdclass object from the database
}
public static function insert($userId){
$comment=addslashes($comment);
$sql= "INSERT into job_article_comments VALUES('' , '$comment' , '$userId')";
$query=mysql_query($db_conx,$sql);
if($query){
$insert_id = mysql_insert_id();
$std = new stdClass();
$std->comment_id = $insert_id;
$std->comment = $comment;
$std->userId = $userId;
return $std;
}
return null;
}
}?>///////////////// ///end of comment.php////////////////
mysql_query ($ db_conx, $ sql); mysql_query ($ sql, $ db_conx) 일 수 있습니다. –