Autor Zpráva
ondrej16556
Profil
Dobrý deň,
Chcem vypísať dáta z tabuliek ale stále mi to vypíše:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 10
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 13
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 16
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 19
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 22
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 25
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 28
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 32
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 35
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 38
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 41
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 44
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 47
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/users/adminstr/stredovek.comehere.cz/web/Dedina/stavat.php on line 50
SQL dotaz nešlo provést


Inde mi to funguje.

Kód súboru stavba.php:
<form action="stavat.php" method="post"><div class="text">
Zadaj ID budovi: <input type="text" name="id">
<input type="submit" value="Postaviť budovu">
</div></form>


Kó súboru stavat.php:
<?php	require_once '../db.php';
		$cas = date("i");
		$id = $_POST['id'];
		@$conn = mysql_connect($dbhost,$dbuser,$dbpass)
			or die ('Zlyhalo pripojenie k databáze');
		mysql_select_db($_SESSION['server']);
	//výpis z databáze
		$query = "SELECT drevo FROM vsetky_budovy WHERE id = $id and username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($bdrevo) = mysql_fetch_row($result);
		$query = "SELECT hlina FROM vsetky_buodvy WHERE id = $id and username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($bhlina) = mysql_fetch_row($result);
		$query = "SELECT kamen FROM vsetky_buodvy WHERE id = $id and username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($bkamen) = mysql_fetch_row($result);
		$query = "SELECT obilie FROM vsetky_buodvy WHERE id = $id and username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($bobilie) = mysql_fetch_row($result);
		$query = "SELECT sobilie FROM vsetky_buodvy WHERE id = $id and username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($bsobilie) = mysql_fetch_row($result);
		$query = "SELECT sobilie FROM vsetky_buodvy WHERE id = $id and username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($bsobilie) = mysql_fetch_row($result);
		$query = "SELECT nazov FROM vsetky_budovy WHERE id = $id and username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($nazov) = mysql_fetch_row($result);
			
		$query = "SELECT drevo FROM dedina WHERE username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($drevo) = mysql_fetch_row($result);
		$query = "SELECT hlina FROM dedina WHERE username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($hlina) = mysql_fetch_row($result);
		$query = "SELECT kamen FROM dedina WHERE username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($kamen) = mysql_fetch_row($result);
		$query = "SELECT obilie FROM dedina WHERE username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($obilie) = mysql_fetch_row($result);
		$query = "SELECT zlato FROM dedina WHERE username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($zlato) = mysql_fetch_row($result);
		$query = "SELECT sobilie FROM dedina WHERE username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($sobilie) = mysql_fetch_row($result);
		$query = "SELECT tobilie FROM dedina WHERE username = '{$_SESSION["username"]}'";
			$result = mysql_query($query);
			list($tobilie) = mysql_fetch_row($result);
	//koniec výpisu
	
     $query = sprintf("INSERT INTO budovy(username,nazov,stupen,nova,koniec) VALUES ('%s','%s','%s','%s');",
	 			mysql_real_escape_string($_SESSION['username']),
				mysql_real_escape_string($nazov),
				mysql_real_escape_string($cas),
				mysql_real_escape_string($cas+5));
      $result = mysql_query($query) or die("SQL dotaz nešlo provést"); //vloženie údajov o novej budove do databáze
	  
	  //definovanie premenných
	  
	  $kondrevo = $drevo-$bdrevo;
	  $konhlina = $hlina-$bhlina;
	  $konkamen = $kamen-$bkamen;
	  $konobiblie = $obilie-$bobilie;
	  $konsobilie = $sobilie-$bsobilie;
	  $tazba = $tobilie-$bsobilie;
	  $query = "UPDATE dedina(drevo,kamen,hlina,obilie,sobilie,tobilie) VALUES ('$kondrevo','$konhlina','$konkamen',$konobilie','$konsobilie','$tazba')";
	  $result = mysql_query($query) or die("Nepodarilo sa :(");
	  
	  mysql_close($conn);
?>


Trápim sa už nad tým celé dopoludnie. Poradili by ste mi prosím, v čom je chyba?
nightfish
Profil
ondrej16556:
Poradili by ste mi prosím, v čom je chyba?
nikoliv, ale poradím ti, jak to zjistíš sám
viz databázové FAQ, konkrétně část nadepsanou Warning: ...(): supplied argument is not a valid MySQL result resource
ondrej16556
Profil
Ďakujem, prišiel som na to. Zabudol som zapnúť sessions a ešte som zadal chybný názov tabuľky
tiso
Profil
ondrej16556: čo takto zmenšiť počet dotazov zo 16 na 4?
ondrej16556
Profil
a ako?
nightfish
Profil
$result = mysql_query("SELECT drevo, kamen, hlina, obilie, zlato, sobilie, tobilie 
FROM dedina 
WHERE username = '{$_SESSION["username"]}'");
list($drevo, $kamen, $hlina, $obilie, $zlato, $sobilie, $tobilie) = mysql_fetch_row($result);
ondrej16556
Profil
Ďakujem, skúsim

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: