Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
Pravilno korištenje ' i " u varijabli

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
domagoj.k



Joined: 17 Apr 2006
Posts: 11

PostPosted: 19.08.2006 21:39    Post subject: Pravilno korištenje ' i " u varijabli Add user to your forum ignore list Reply with quote

Iz php forme treba nešto u mysql.

ovako ga stavlja u mysql
red='$varijabla'

a u $varijabl se nalazi kod ovog tipa <bla bla width="400"/><bla bla nesto="$visina">

I uvijek mi javlja neki problem. ako je "prošo php" (znači bez parse error unexpected T_NESTO) onda mi javi da imam error u mysql sintaksi...

Kako se to pravilno radi? Evo ovaj moj "bla bla" kod, kako ga napisat pravilno?
Back to top
View user's profile Send private message Visit poster's website
gog



Joined: 18 Jun 2004
Posts: 679
Location: zagreb

PostPosted: 19.08.2006 22:44    Post subject: Add user to your forum ignore list Reply with quote

red = " ....... '" . $var . "' ......";

ili red = '......\'' . $var . '\'....'
Back to top
View user's profile Send private message Visit poster's website
domagoj.k



Joined: 17 Apr 2006
Posts: 11

PostPosted: 20.08.2006 00:01    Post subject: Add user to your forum ignore list Reply with quote

Ne radi mi, da ja sad ne pišem koje mi errore izbacuje, evo koda kojeg želim pod ovim navodnicima ' ' (ne dvostrukim) pa ako netko može pravilno napisat:

<object width="400" height="325"><param name="movie" value="$video"></param><embed src="$video" type="application/x-shockwave-flash" width="400" height="325"></embed></object>
Back to top
View user's profile Send private message Visit poster's website
Tedius



Joined: 22 Dec 2003
Posts: 149
Location: Zagreb

PostPosted: 20.08.2006 00:11    Post subject: Add user to your forum ignore list Reply with quote

Kad spremaš varijablu zatvori ju sa addslashes($var), kad ju čupaš van onda staviš stripslashes().... pogledaj detalje u manualu.
Back to top
View user's profile Send private message Visit poster's website
gog



Joined: 18 Jun 2004
Posts: 679
Location: zagreb

PostPosted: 20.08.2006 00:23    Post subject: Add user to your forum ignore list Reply with quote

OK, nisam odmah skužio što te muči, pogledja http://hr.php.net/mysql_real_escape_string

Code:
// Quote variable to make safe
function quote_smart($value)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   }
   // Quote if not a number or a numeric string
   if (!is_numeric($value)) {
       $value = "'" . mysql_real_escape_string($value) . "'";
   }
   return $value;
}
Back to top
View user's profile Send private message Visit poster's website
domagoj.k



Joined: 17 Apr 2006
Posts: 11

PostPosted: 20.08.2006 10:34    Post subject: Add user to your forum ignore list Reply with quote

Dobro, ali nije mi varijabla jedini problem. Error se javlja i bez nje, jer ja krivo pišem " i ' unutar ovih navodnika: ' '
Stavim prijje navodnika / npr Value=/'bla/' ali ni tako neće...
Back to top
View user's profile Send private message Visit poster's website
gog



Joined: 18 Jun 2004
Posts: 679
Location: zagreb

PostPosted: 20.08.2006 11:57    Post subject: Add user to your forum ignore list Reply with quote

Al si ga zakomplicirao, ajde prekopiraj doslovno dio kod-a (upit!!) koij te muči...
Back to top
View user's profile Send private message Visit poster's website
domagoj.k



Joined: 17 Apr 2006
Posts: 11

PostPosted: 20.08.2006 13:03    Post subject: Add user to your forum ignore list Reply with quote

Već jesam. Ali evo detaljnije:

$video = $_POST['video'];

$glavno = "<object width='400' height='325'><param name='movie' value='$video'></param><embed src='$video' type='application/x-shockwave-flash' width='400' height='325'></embed></object>";

$sql = "INSERT INTO tablica SET
description='$description',
...
main='$glavno',
...
Back to top
View user's profile Send private message Visit poster's website
gog



Joined: 18 Jun 2004
Posts: 679
Location: zagreb

PostPosted: 20.08.2006 14:16    Post subject: Add user to your forum ignore list Reply with quote

Ufff, mislim da bi malo trebao pročitati o osnovama php-a.

Code:
$video="neki tekst";
$film = "bla bla bla='$video' bla";
echo $film;


dobit ćeš ->
Quote:
bla bla bla='$video' bla
, a ne
Quote:
bla bla bla='neki tekst' bla
kao što si možda očekivao.

Riješenja ima više, evo jednog:

Code:
$video="neki tekst";
$film = "bla bla bla='" . $video . "' bla";
echo $film;


ili drugog

Code:
$video="neki tekst";
$film = 'bla bla bla=\'' . $video . '\' bla";
echo $film;


Znači da bi tvoj kô trebao izgledati ovako nekako:

Code:

// Quote variable to make safe
function quote_smart($value)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   }
   // Quote if not a number or a numeric string
   if (!is_numeric($value)) {
       $value = "'" . mysql_real_escape_string($value) . "'";
   }
   return $value;
}


$video = $_POST['video'];

$glavno = "<object width='400' height='325'><param name='movie' value='" . $video . "'></param><embed src='" . $video . "' type='application/x-shockwave-flash' width='400' height='325'></embed></object>";

$glavno = quote_smart($glavno);

$sql = "INSERT INTO tablica SET
description='$description',
...
main='$glavno',
...


Kro quote_smart bi trebao provući i $description i sve druge varijable, pa nije loše držati ih u nekom arrayu i prošteta se kroz njega sa forearch ili array_walk...
Back to top
View user's profile Send private message Visit poster's website
Gale



Joined: 04 Apr 2005
Posts: 120

PostPosted: 20.08.2006 14:50    Post subject: Add user to your forum ignore list Reply with quote

gog wrote:
Ufff, mislim da bi malo trebao pročitati o osnovama php-a.

Code:
$video="neki tekst";
$film = "bla bla bla='$video' bla";
echo $film;


dobit ćeš ->
Quote:
bla bla bla='$video' bla
, a ne
Quote:
bla bla bla='neki tekst' bla
kao što si možda očekivao.



dobit će
Quote:
bla bla bla='neki tekst' bla
Back to top
View user's profile Send private message Visit poster's website
gog



Joined: 18 Jun 2004
Posts: 679
Location: zagreb

PostPosted: 20.08.2006 15:07    Post subject: Add user to your forum ignore list Reply with quote

Ufff, posipam se pepelom, bio sam uvjeren da varijablu ako unutar dvostrukih ogradiš jednostrukima da će se doslovno ispisati... Embarassed Embarassed Embarassed

OK, onda samo upogoni ovaj quotesmart i trebalo bi raditi...
Back to top
View user's profile Send private message Visit poster's website
domagoj.k



Joined: 17 Apr 2006
Posts: 11

PostPosted: 21.08.2006 18:22    Post subject: Add user to your forum ignore list Reply with quote

Hvala na odgovorima, ali:

Fatal error: Call to undefined function: quote_smart()
Back to top
View user's profile Send private message Visit poster's website
gog



Joined: 18 Jun 2004
Posts: 679
Location: zagreb

PostPosted: 22.08.2006 19:17    Post subject: Add user to your forum ignore list Reply with quote

Pa ono, moraš imati tu funkciju upisanu:

Code:
// Quote variable to make safe
function quote_smart($value)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   }
   // Quote if not a number or a numeric string
   if (!is_numeric($value)) {
       $value = "'" . mysql_real_escape_string($value) . "'";
   }
   return $value;
}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group