Autor Zpráva
lmdizajn
Profil *
Mam vytvorene tabulky v databazy, vytvorene pomoc PHP scriptu, to fungovalo. Ale ked som si chcel vytovrit script na pridavanie zaznamov, tak to uz nefunguje. Niekde som urcite nieco domrvil, ale neviem tam tu chybu naist, alebo co som tam zabudol pripisat. Malo byto fungovat tak, ze sa nacita stranka s formularom, vyplnis udaje, kliknes a posle to do databazy, je tam i kontrola vypisania 2 poli a aj cookies.
Stranka s formularom:
<?
error_reporting(7);
/*
PRIDAJ TRATE
*/

require_once("config.php");

$extratitle="PRIDAJ TRATE";

include "head.php";

if ($_GET["okno"] == "pomoc") {
	echo "Pomoc";
} Else {
	
	$error="";
	If($_POST['submit']) {
		extract($_POST, EXTR_SKIP);
	
		If((trim($nazov)=="") OR ($nazov=="Nazov-trate")) {
			$error.="Napis nazov!<br />";
		}
	
		If((trim($hesloedit)=="") {
			$error.="Napis heslo!<br />";
		}
		
		If($error) {
			
			$display_message=$error;
			
		} Else {
			
			$ph->query("INSERT INTO ".$tbl_prefix."_trate VALUES('NULL', '".addslashes($nazov)."', '".addslashes($pic)."', '".addslashes($miesto)."', '".addslashes($mesto)."', '".addslashes($dlzka)."', '".addslashes($typ)."', '".addslashes($obrazky)."', '".addslashes($hesloedit)."', '".addslashes($ulozil)."')");

			setcookie("ulozil",$ulozil,time()+108000);		
			header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
			exit;
		}
	}
	
?>


<form method="post" action="<?=$_SERVER['PHP_SELF'];?>" name="phform">
<table class="table" align="center" width="100%">
	
		<? If($display_message) { ?>
	
	<tr>
		<td align="center" class="error"><?=$display_message;?></td>
	</tr>

	<? } ?>
	
	<tr>
		<td align="center" class="pridaj">
		If($_COOKIE['ulozil']) {
		$ulozil=htmlspecialchars(stripslashes($_COOKIE['ulozil']));
		}
			Nazov odkazu: <input type="text" name="nazov" size="45" onfocus="Clear(this)" value="Nazov-trate"/><br />
			URL obrazka: <input type="text" name="pic" size="45" onfocus="Clear(this)" value="http://<?=$_SERVER['HTTP_HOST'];?>/obrazky/ico_trate.jpg" /><br />
			Miesto <input type="text" name="miesto" size="45" onfocus="Clear(this)" /><br />
			Mesto: <input type="text" name="mesto" size="45" onfocus="Clear(this)" /><br />
			Dlzka: <input type="text" name="dlzka" size="45" onfocus="Clear(this)" /><br />
        Vyber TYP trate: 
        <select name="typ" size="1" onfocus="Clear(this)" />
        <option value="skok" style="color: orange">Skok</option>
						    <option value="sprint" style="color: green" selected="selected">Sprint</option>
						    <option value="ine" style="color: pink">Ine</option>
						    <option value="slalom" style="color: red">Slalom</option>
						    <option value="smyk" style="color: purple">Smyk</option>
 						 </select>
			Obrazky: <textarea type="text" name="obrazky" cols="40" rows="4" onfocus="Clear(this)" /></textarea>
			Heslo pre neskorsiu editaciu: <input type="password" name="hesloedit" size="45" onfocus="Clear(this)" /><br />
			Ulozil: <input type="text" name="ulozil" size="45" onfocus="Clear(this)" value="<?=$ulozil;?>" /><br />
			<input type="hidden" name="submit" value="true" /><br />
			<input type="submit" name="submit" value=" Pridaj! " /><br />
	
	

<a href="javascript:void(0);" onclick="phPopUp('<?=$_SERVER['PHP_SELF']."?okno=pomoc";?>',300,400,1)" class="alt"><!-- Extra --></a> | <a href="http://<?=$_SERVER['HTTP_HOST'];?>" class="alt">Domov</a>

		</td>

	</tr>

</table>
</form>
<?}?>
</body>
</html>

Dalej v head.php je len hlavicka stranky, v config.php su hesla a uzivatelske mena pre DB a vo function je script na DB...
config.php :
<?
error_reporting(7);
/*
CONFIG
*/

// Your mysql host, this is usally localhost.
$sql_host="localhost";

// Your mysql username. This usually be obtained from your control panel or your host.
$sql_user="xx";

// Please ask your host if you don't know this.
$sql_pass="xx";

// Your mysql database. This usually be obtained from your control panel or your host.
$sql_db="xx";

//This is used if you want to install multiple copies of this script on the same database.
$tbl_prefix="s2g";

require_once("functions.php");

$ph = new phdb;
$ph->connect($sql_host,$sql_user,$sql_pass,$sql_db);
unset($sql_host,$sql_user,$sql_pass,$sql_db);
?>

v functions.php ( to nie je moj script, su tam i veci na prepis smailov a podobne... ) je :
<?

error_reporting(7);
/*
FUNKCIE
*/

class phdb {

function connect($host="localhost",$user,$pass,$data,$persistency=False) {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->data = $data;
$this->persistency = $persistency;

If($this->persistency) {
$this->link=@mysql_pconnect($this->host,$this->user,$this->pass);
} Else {
$this->link=@mysql_connect($this->host,$this->user,$this->pass);
}

If(($this->link) AND ($this->data)) {
If(@mysql_select_db($this->data,$this->link)) {
return True;
}
}
return False;
}

function fetch($query="") {
$query=mysql_fetch_array($query);
return($query);
}

function query($query="",$sup="") {
If($sup) {
$query=mysql_query($query,$this->link);
} Else {
$query=mysql_query($query,$this->link);
}
return($query);
}

function rows($query="") {
$query=@mysql_num_rows($query);
return($query);
}
function free($query="") {
@mysql_free_result($query);
}
function result($query="",$sup="") {
$query=$this->query($query,$sup);
$result=$this->fetch($query);
$this->free($query);
return($result);
}
function getrows($querystring="") {
$query=$this->query($querystring);
$result=$this->rows($query);
$this->free($query);
return($result);
}
function disconnect() {
@mysql_close($this->link);
}
}


function isurl($key) {

If(!$url=@parse_url($key)) {
return False;
} Elseif(($url[scheme]!="http") AND ($url[scheme]!="https")) {
return False;
} Elseif(!eregi("^[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,8}$", $url[host])) {
return False;
} Elseif(!eregi("^[0-9a-z/_\.@~\-]*$", $url[path])) {
return False;
}
return True;

}


function phrase($key) {
global $ph, $use_filter, $tbl_prefix, $wordwrap,$smilies_find,$smilies_replace;

$domains=array("com","net","org","sk","cz","biz","info","eu");
$search=explode(" ",$key);

for($word=0;$word<count($search);$word++) {
If(eregi("^(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))+$",$search[$word])){
$search[$word]="[email]".$search[$word]."[/email]";
} Elseif((substr($search[$word],0,4)=="www.") OR (@in_array(substr(strrchr(strtolower($search[$word]), "."), 1),$domains)) AND (!eregi("://",$search[$word]))){
$search[$word]="http://".$search[$word]."";
}
}

$key=implode(" ",$search);

If($use_filter) {
$query=$ph->query("SELECT * FROM ".$tbl_prefix."_filter");
while($result=$ph->fetch($query)) {

If(!$result[repla
lmdizajn
Profil *
NEVLOZILO TO CELE

v functions.php ( to nie je moj script, su tam i veci na prepis smailov a podobne... ) je :
<?
error_reporting(7);
/*
FUNKCIE
*/

class phdb {
	
	function connect($host="localhost",$user,$pass,$data,$persistency=False) {
		$this->host = $host;
		$this->user = $user;
		$this->pass = $pass;
		$this->data = $data;
		$this->persistency = $persistency;
		
		If($this->persistency) {
			$this->link=@mysql_pconnect($this->host,$this->user,$this->pass);
		} Else {
			$this->link=@mysql_connect($this->host,$this->user,$this->pass);
		}
		
		If(($this->link) AND ($this->data)) {
			If(@mysql_select_db($this->data,$this->link)) {
				return True;
			}
		}
		return False;
	}
	function fetch($query="") {
		$query=mysql_fetch_array($query);
		return($query);
	}
		function query($query="",$sup="") {
		If($sup) {
			$query=mysql_query($query,$this->link);
		} Else {
			$query=mysql_query($query,$this->link);
		}
		return($query);
	}
	
	function rows($query="") {
		$query=@mysql_num_rows($query);
		return($query);
	}
	function free($query="") {
		@mysql_free_result($query);
	}
	function result($query="",$sup="") {
		$query=$this->query($query,$sup);
		$result=$this->fetch($query);
		$this->free($query);
		return($result);
	}
	function getrows($querystring="") {
		$query=$this->query($querystring);
		$result=$this->rows($query);
		$this->free($query);
		return($result);
	}
	function disconnect() {
		@mysql_close($this->link);
	}
}
function isurl($key) {
	
	If(!$url=@parse_url($key)) {
		return False;
	} Elseif(($url[scheme]!="http") AND ($url[scheme]!="https")) {
			return False;
	} Elseif(!eregi("^[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,8}$", $url[host])) {
			return False;
	} Elseif(!eregi("^[0-9a-z/_\.@~\-]*$", $url[path])) {
			return False;
	}
	return True;
}
function phrase($key) {
	global $ph, $use_filter, $tbl_prefix, $wordwrap,$smilies_find,$smilies_replace;
	
	$domains=array("com","net","org","sk","cz","biz","info","eu");
	$search=explode(" ",$key);
	
	for($word=0;$word<count($search);$word++) {
		If(eregi("^(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))+$",$search[$word])){
			$search[$word]="[email]".$search[$word]."[/email]";
		} 	Elseif((substr($search[$word],0,4)=="www.") OR (@in_array(substr(strrchr(strtolower($search[$word]), "."), 1),$domains)) AND (!eregi("://",$search[$word]))){
			$search[$word]="http://".$search[$word]."";
		}
	}
	$key=implode(" ",$search);

	If($use_filter) {
		$query=$ph->query("SELECT * FROM ".$tbl_prefix."_filter");
		while($result=$ph->fetch($query)) {
			
			If(!$result[replacewith]) {
				$result[replacewith]="**";
			}
			
			$key=str_replace($result[find],$result[replacewith],$key);
		}
	}
	$key=eregi_replace("(^|[>[:space:]\n])([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])([<[:space:]\n]|$)","\\1[url]\\2://\\3\\4[/url]\\5", $key);
	
	$search = array(
		"/(\[)(color)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/color)(((=)(\\4)([^\"']*)(\\4]))|(\]))/siU",
		"/(\[)(b)(])(.*)(\[\/b\])/siU",
		"/(\[)(i)(])(.*)(\[\/i\])/siU",
		"/(\[)(u)(])(.*)(\[\/u\])/siU",
		"/(\[)(s)(])(.*)(\[\/s\])/siU",
		"/(\[)(move)(])(.*)(\[\/move\])/siU",
	);
	$replace = array(
		"<font color=\"\\5\">\\7</font>",
		"<b>\\4</b>",
		"<i>\\4</i>",
		"<u>\\4</u>",
		"<s>\\4</s>",
		"<marquee>\\4</marquee>",
	);
	
	$i=0;
	foreach ($smilies_find as $smiley){
		$key=str_replace($smiley, "<img src=\"".$smilies_replace[$i]."\" alt=\"".$smiley."\" />", $key);
		$i++;
	}
	$key=preg_replace($search, $replace, $key);
	$key=str_replace("\\'", "'", $key);
	$key=preg_replace("#\[url\]([a-z]+?://){1}(.*?)\[/url\]#si", "<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>", $key);
	$key=preg_replace("#\[url\](.*?)\[/url\]#si", "<a href=\"http://\\1\" target=\"_blank\">\\1</a>", $key);
	$key=preg_replace("#\[url=([a-z]+?://){1}(.*?)\](.*?)\[/url\]#si", "<a href=\"\\1\\2\" target=\"_blank\">\\3</a>", $key);
	$key=preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", "<a href=\"http://\\1\" target=\"_blank\">\\2</a>", $key);
	$key=preg_replace("#\[email\](.*?)\[/email\]#si", "<a href=\"mailto:\\1\">\\1</a>", $key);
	$key=preg_replace("#\[email=(.*?){1}(.*?)\](.*?)\[/email\]#si", "<a href=\"mailto:\\1\\2\">\\3</a>", $key);
	$key=str_replace("{", "{", $key);
	
	$key=preg_replace('%(\s*)([^>]{'.$wordwrap.',})(<|$)%e',"'\\1'.wordwrap('\\2', '".$wordwrap."', '\n', 1).'\\3'", $key); 
	
	return(stripslashes($key));
}

?>
lmdizajn
Profil *
A ze by spojenie s DB malo fungovat viem lebo tento script presiel v pohode a nainstaloval ( vytvoril ) tabulky v databazy... :
<?
error_reporting(7);
/*
INSTALACIA - TRATE , AUTA , VIDEA
*/

require_once("config.php");

###Install###
//VIDEA
if ($_GET["instalacia"] == "videa") { 
	$ph->query("CREATE TABLE ".$tbl_prefix."_videa (
	  id int(11) NOT NULL auto_increment,
  	  nazov varchar(50) default NULL,
  	  pic varchar(100) default NULL,
	  popis varchar(255) default NULL,
	  aktery varchar(255) default NULL,
  	  typ varchar(50) default NULL,
	  hesloedit varchar(100) default NULL,
	  ulozil varchar(50) default NULL,
	   PRIMARY KEY  (id)
	) TYPE = MYISAM;") or die(mysql_error());
		Echo("Databaza VIDEA bola nainstalovana! Doinstalujte <a href=\"".$_SERVER['PHP_SELF']."\">dalsie</a> alebo zmazte subor!\n");
}
//AUTA
if ($_GET["instalacia"] == "auta") {
	$ph->query("CREATE TABLE ".$tbl_prefix."_auta (
	  id int(11) NOT NULL auto_increment,
  	  nazov varchar(50) default NULL,
  	  pic varchar(100) default NULL,
	  znacka varchar(50) default NULL,
	  typ varchar(50) default NULL,
	  motor varchar(50) default NULL,
	  rok varchar(50) default NULL,
	  vykon varchar(50) default NULL,
	  zrychlenie varchar(50) default NULL,
	  specialitky varchar(255) default NULL,
	  obrazky varchar(255) default NULL,
	  hesloedit varchar(100) default NULL,
	  ulozil varchar(50) default NULL,
	   PRIMARY KEY  (id)
	) TYPE = MYISAM;") or die(mysql_error());
		Echo("Databaza AUTA bola nainstalovana! Doinstalujte <a href=\"".$_SERVER['PHP_SELF']."\">dalsie</a> alebo zmazte subor!\n");
}
// TRATE
if ($_GET["instalacia"] == "trate") {
	$ph->query("CREATE TABLE ".$tbl_prefix."_trate (
	  id int(11) NOT NULL auto_increment,
	  nazov varchar(50) default NULL,
  	  pic varchar(100) default NULL,
	  miesto varchar(100) default NULL,
	  mesto varchar(50) default NULL,
	  dlzka varchar(50) default NULL,
	  typ varchar(50) default NULL,
	  obrazky varchar(255) default NULL,
	  hesloedit varchar(100) default NULL,
	  ulozil varchar(50) default NULL,
	   PRIMARY KEY  (id)
	) TYPE = MYISAM;") or die(mysql_error());
		Echo("Databaza TRATE bola nainstalovana! Doinstalujte <a href=\"".$_SERVER['PHP_SELF']."\">dalsie</a> alebo zmazte subor!\n");
} 

If($instalacia=="") {
	Echo("Klikni sem a nainstaluj <a href=\"".$_SERVER['PHP_SELF']."?instalacia=trate\">databazu TRATE!</a> alebo <a href=\"".$_SERVER['PHP_SELF']."?instalacia=auta\">databazu AUTA!</a> alebo <a href=\"".$_SERVER['PHP_SELF']."?instalacia=videa\">databazu VIDEA!</a>\n");
}
?>


Moc dakujem ak mi niekto pomoze a najde mi tam chybu, som to uz po nociach kukal no a nic... Dufam ze to bude fungovat a ze sa takato DB s formularom a podobne co chcem dorobit zide aj inym a potom by som to sem funkcne vsetko dal... Diky
lmdizajn
Profil *
A ze by spojenie s DB malo fungovat viem lebo tento script presiel v pohode a nainstaloval ( vytvoril ) tabulky v databazy... :
<?
error_reporting(7);
/*
INSTALACIA - TRATE , AUTA , VIDEA
*/

require_once("config.php");

###Install###
//VIDEA
if ($_GET["instalacia"] == "videa") { 
	$ph->query("CREATE TABLE ".$tbl_prefix."_videa (
	  id int(11) NOT NULL auto_increment,
  	  nazov varchar(50) default NULL,
  	  pic varchar(100) default NULL,
	  popis varchar(255) default NULL,
	  aktery varchar(255) default NULL,
  	  typ varchar(50) default NULL,
	  hesloedit varchar(100) default NULL,
	  ulozil varchar(50) default NULL,
	   PRIMARY KEY  (id)
	) TYPE = MYISAM;") or die(mysql_error());
		Echo("Databaza VIDEA bola nainstalovana! Doinstalujte <a href=\"".$_SERVER['PHP_SELF']."\">dalsie</a> alebo zmazte subor!\n");
}
//AUTA
if ($_GET["instalacia"] == "auta") {
	$ph->query("CREATE TABLE ".$tbl_prefix."_auta (
	  id int(11) NOT NULL auto_increment,
  	  nazov varchar(50) default NULL,
  	  pic varchar(100) default NULL,
	  znacka varchar(50) default NULL,
	  typ varchar(50) default NULL,
	  motor varchar(50) default NULL,
	  rok varchar(50) default NULL,
	  vykon varchar(50) default NULL,
	  zrychlenie varchar(50) default NULL,
	  specialitky varchar(255) default NULL,
	  obrazky varchar(255) default NULL,
	  hesloedit varchar(100) default NULL,
	  ulozil varchar(50) default NULL,
	   PRIMARY KEY  (id)
	) TYPE = MYISAM;") or die(mysql_error());
		Echo("Databaza AUTA bola nainstalovana! Doinstalujte <a href=\"".$_SERVER['PHP_SELF']."\">dalsie</a> alebo zmazte subor!\n");
}
// TRATE
if ($_GET["instalacia"] == "trate") {
	$ph->query("CREATE TABLE ".$tbl_prefix."_trate (
	  id int(11) NOT NULL auto_increment,
	  nazov varchar(50) default NULL,
  	  pic varchar(100) default NULL,
	  miesto varchar(100) default NULL,
	  mesto varchar(50) default NULL,
	  dlzka varchar(50) default NULL,
	  typ varchar(50) default NULL,
	  obrazky varchar(255) default NULL,
	  hesloedit varchar(100) default NULL,
	  ulozil varchar(50) default NULL,
	   PRIMARY KEY  (id)
	) TYPE = MYISAM;") or die(mysql_error());
		Echo("Databaza TRATE bola nainstalovana! Doinstalujte <a href=\"".$_SERVER['PHP_SELF']."\">dalsie</a> alebo zmazte subor!\n");
} 

If($instalacia=="") {
	Echo("Klikni sem a nainstaluj <a href=\"".$_SERVER['PHP_SELF']."?instalacia=trate\">databazu TRATE!</a> alebo <a href=\"".$_SERVER['PHP_SELF']."?instalacia=auta\">databazu AUTA!</a> alebo <a href=\"".$_SERVER['PHP_SELF']."?instalacia=videa\">databazu VIDEA!</a>\n");
}
?>


Moc dakujem ak mi niekto pomoze a najde mi tam chybu, som to uz po nociach kukal no a nic... Dufam ze to bude fungovat a ze sa takato DB s formularom a podobne co chcem dorobit zide aj inym a potom by som to sem funkcne vsetko dal... Diky
lmdizajn
Profil *
Sorry za zdvojeny prispevok...
A este som zabudol, ze na stranke pridaj_trate.php sa po spusteny nezobrazi absolutne nic... Ani head.php sa nenacita...
Alphard
Profil
lmdizajn:
1. smažte apostrofy kolem null
2. Nečekejte, že někdo bude číst ty stovky řádků kódu. Nikoho tady nezajímá metoda isurl() apod. když problém je úplně jinde.
Nefunguje vám vkládání do databáze, takže sem dejte jeden dotaz (ten insert), jeho konečnou podobu (s již doplněnými proměnnými) a chybu, kterou vrátí mysql_error(), to bude pro začátek stačit
lmdizajn
Profil *
Jo, skusim diky
lmdizajn
Profil *
Tak tento test subor funguje a prida do tabulky vsetky polozky, ale ked je vnutry tej celej stranky, ako je hore vidno v pridaj_trate.php tak to nefunguje. Takze tam je niekde chyba...
Toto ide aj vypise Oks...
<?
error_reporting(7);
/*
PRIDAJ TRATE
*/
require_once("config.php");
$extratitle="PRIDAJ TRATE";
include "head.php";
			$ph->query("INSERT INTO ".$tbl_prefix."_trate VALUES(NULL, '".addslashes(nazov)."', '".addslashes(pic)."', '".addslashes(miesto)."', '".addslashes(mesto)."', '".addslashes(dlzka)."', '".addslashes(typ)."', '".addslashes(obrazky)."', '".addslashes(hesloedit)."', '".addslashes(ulozil)."')");

			header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
			echo "Oks";
			exit;
?>
</body>
</html>
Alphard
Profil
co píše mysql_error()?
lmdizajn
Profil *
Tam je problem niekde inde... ( ziaden error nehlasi ) Nezbehne vobec nacitanie stranky, ani formular mi neukaze ( ked spustam celu tu stranku pridaj_trate.php ) ... Keby to uz konecne poslalo, tak je to v poriadku, kedze ked som rozdelil tie subory do dvoch, 1 - tam je formular a 2 - tam je script na posielanie do DB, tak to funguje... Ale tak by som to nechcel... No ved este uvidim, co z toho vznikne... Inak diky...

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: