Autor Zpráva
kalbosh
Profil
Toho mi vypisuje pri INSERT do databazi, nevim v cem je chyba

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 'Resource id #6' at line 1


<?php

$id = mss($_GET['id']);

if($id){
	$sql = "SELECT * FROM `forum_sub_cats` WHERE `id`='" . $id . "'";
	$res = mysql_query($sql) or die(mysql_error());
	if(mysql_num_rows($res) == 0){
		echo "The forum you are trying to create a topic on, does not exist\n";
	}else {
		$row1 = mysql_fetch_assoc($res);
		if($row['admin'] == 1 && $admin_user_level == 0){
			echo "You are not an administrator, therefore you cannot post on this forum!\n";
		}else {
		if(!$_POST['submit']){	
		echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
		echo "<form method=\"post\" action=\"./index.php?act=create&id=".$id."\">\n";
		echo "<tr><td>Forum Sub category</td><td><select name=\"cat\">\n";
		$sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1";
		$res = mysql_query($sql2) or die(mysql_error());
		while($row = mysql_fetch_assoc($res)){
 			$sql3 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row['id']."'";
 			$res3 = mysql_query($sql3) or die(mysql_error());
 			
 			echo "<option value=\"0\">" .$row['name']."</option>\n";
 			    while($row2 = mysql_fetch_assoc($res3)){
 			    	$selected = ($row2['id'] == $id) ? " SELECTED" : "";
 			    	echo "<option value=\"" . $row2['id'] . "\"" .$selected . ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row2['name'] . "</option>\n";
 			    }
		}
		echo "</selected></td></tr>\n";
		echo "<tr><td>Topic Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n";
		echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n";
		echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topics\"></td></tr>\n";
		echo "</form></table>\n";
		}else{
			$cat = mss($_POST['cat']);
			$title = mss($_POST['title']);
			$msg = mss($_POST['message']);
			
			if($cat && $title && $msg){
				$sql = "SELECT admin FROM `forum_sub_cats` WHERE `id`='".$cat."'";
				$res = mysql_query($res) or die(mysql_error());
				if(mysql_num_rows($res) == 0){
					echo "This forum sub category does not exist!\n";
				}else {
					$row = mysql_fetch_assoc($res);
					if($row['admin'] == 1 && $admin_user_level !=1){
						echo "You are not an admin therefore you cannot post a new topic on this forum\n";
					}else {
						if(strlen($title) < 3 || strlen($title) > 32 ){
							echo "The title must be between 3 and 32 characters\n";
						}else {
							if(strlen($msg) < 3 || strlen($msg) > 10000){
								echo "The message must be between 3 and 10,000 characters\n";
							}else {
								$date = date("m-d-y") . " at " . date("h:i:s");
								$time = time();
								$sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')";
								$res2 = mysql_query($sql2) or die(mysql_error());
								$tid = mysql_insert_id();
								topic_go($tid);
							}
						}
					}
				}
			}else {
				echo "Please supply all the fields!\n";
			}
		}
	}
  }
}else {
	if(!$_POST['submit']){
		echo "<table border=\"0\" cellspacing=\"3\">\n";
		echo "<form method=\"post\" action=\"./index.php?act=create\">\n";
		echo "<tr><td>Forum Sub category</td><td><select name=\"cat\">\n";
		$sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1";
		$res = mysql_query($sql2) or die(mysql_error());
		while($row = mysql_fetch_assoc($res)){
 			$sql3 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row['id']."'";
 			$res3 = mysql_query($sql3) or die(mysql_error());
 			
 			echo "<option value=\"0\">" .$row['name']."</option>\n";
 			    while($row2 = mysql_fetch_assoc($res3)){
 			    	$selected = ($row2['id'] == $id) ? " SELECTED" : "";
 			    	echo "<option value=\"".$row2['id']."\"".$selected.">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$row2['name']."</option>\n";
 			    }
		}
		echo "</selected></td></tr>\n";
		echo "<tr><td>Topic Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n";
		echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n";
		echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topics\"></td></tr>\n";
		echo "</form></table>\n";
	}else {
		$cat = mss($_POST['cat']);
			$title = mss($_POST['title']);
			$msg = mss($_POST['message']);
			
			if($cat && $title && $msg){
				$sql = "SELECT admin FROM `forum_sub_cats` WHERE `id`='".$cat."'";
				$res = mysql_query($res) or die(mysql_error());
				if(mysql_num_rows($res) == 0){
					echo "This forum sub category does not exist!\n";
				}else {
					$row = mysql_fetch_assoc($res);
					if($row['admin'] == 1 && $admin_user_level !=1){
						echo "You are not an admin therefore you cannot post a new topic on this forum\n";
					}else {
						if(strlen($title) < 3 || strlen($title) > 32 ){
							echo "The title must be between 3 and 32 characters\n";
						}else {
							if(strlen($msg) < 3 || strlen($msg) > 10000){
								echo "The message must be between 3 and 10,000 characters\n";
							}else {
								$date = date("m-d-y") . " at " . date("h:i:s");
								$time = time();
								$sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')";
								$res2 = mysql_query($sql2) or die(mysql_error());
								$tid = mysql_insert_id();
								header("Location: index.php?act=topic&id=".$tid."");
							}
						}
					}
				}
			}else {
				echo "Please supply all the fields!\n";
			}
	}
}
?>
apollon
Profil
$sql = "SELECT * FROM `forum_sub_cats` WHERE `id`='" . $id . "'";


Proč jsou tam ty mezery?

`id`='".$id."'

// máš pravdu, to tam může být. Já jsem to tak nikdy neviděl, proto mi to přišlo špatně
SwimX
Profil
apollon
ty mezery tomu určitě nevadí
si zkus:
<?php
$a = 66;
echo "ahoj"  .  $a   . "ahoj<br>";
echo "ahoj".$a."ahoj<br>";
echo "ahoj{$a}ahoj<br>";
?>
kalbosh
Profil
Nevite co s tim ?
kalbosh
Profil
vubec nechapu co je to za chybu ...
AM
Profil *
Wow, ten kod ma 131 radku :) nech si vyechovat, jak presne ten dotaz vypada, kdyz se promenne nahradi hodnotami, tj echo "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; , pastni to sem, pak se muzeme o necem bavit. Nebo mozna spis ten dotaz patri do fora o MySQL, ale myslim, ze kdyz si ho vyechujes, samotnemu ti dojde, kde je chyba. Kdyz vidim, ze chyba je pobliz 'Resource id #6', je mi uplne jasne, ze ses ani nepodival na to jak ten dotaz po zpracovani promennych vypada nez se posle do MySQL.
Kajman_
Profil *
Na 43. a 102. řádku máte

$res = mysql_query($res) or die(mysql_error());

Asi tam chcete dávat $sql.
kalbosh
Profil
diky moc .. pomohlo to

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0