Jump to content
php.lv forumi

inet_aton , ntoa


Nezinītis

Recommended Posts

Sveiki.

Izmeklējos, bet tā arī nevarēju sekmīgi atrast, ko man vajag. :x

 

Griežos pie jums.

 

Kā pareizi kvērijā tiek izmantots inet_aton un inet_ntoa?

Vēlos Ip adresi glabāt tabulā ar integer tipu.

 

Mēģinu -

$kveerijs=mysql_query("INSERT INTO issues (subject, content, type, project_id, user_id, status, ip_add) VALUES (".S($subject).",".S($content).",".S($type).",".S($project_id).",".S($_SESSION['u_id']).",".S($veert_main).",inet_aton(".$ip."))")or die('buum, nomira.');

bet dabuju ar lineāru pa pirkstiem. :(

Edited by Nezinītis
Link to comment
Share on other sites

Ip adrese ir string tips, tāpēc to jāliek apostrofos. Doma aptuveni tāda:

 

mysql_query("insert into table (ip) values ('$ip')");

 

bump.

 

A viņš man php mainīgo tāpat arī apēdīs? Kaut kur esi aizdomājies. :)

+ ja uzraksta pareizo tavu variantu.. tāpat tas neko nedod.. :x

Edited by Nezinītis
Link to comment
Share on other sites

Pārveido jau php pusē uz int -

Kaapec?? Kaads labums?? Sarezgiitaks kods?

Nav ko mociit PHP, ja to lieliski var izdariit ar SQL funkciju ...

 

to Nezinītis: tev viss itkaa pareizi tik, padotaa IP bija jaieliek pedinjas (strings)

Piedevam neaizmirti ka lai glabatu IP kaa integer, jaizmanto atribuuts UNSIGNET (pie datu tipa)

Link to comment
Share on other sites

Nu tak, tur nav problēma.. viss kvērijs -

$kveerijs=mysql_query("INSERT INTO issues (subject, content, type, project_id, user_id, status, ip_add) VALUES (".S($subject).",".S($content).",".S($type).",".S($project_id).",".S($_SESSION['u_id']).",".S($veert_main).",inet_aton('".$ip."'))")or die(mysql_error());

Link to comment
Share on other sites

Pirms paša vaicājuma izpildīšanas izvadi kāds šis izskatās.

 

echo("INSERT INTO issues (subject, content, type, project_id, user_id, status, ip_add) VALUES (".S($subject).",".S($content).",".S($type).",".S($project_id).",".S($_SESSION['u_id']).",".S($veert_main).",inet_aton('".$ip."'))");

Link to comment
Share on other sites

Pārveido jau php pusē uz int - http://lv.php.net/manual/en/function.ip2long.php

Wrong, PHP, cik atceros, strādā tikai ar signed int.

 

Par tēmu: piekritīšu Maris-S, vaina, laikam, ir S() funkcijai. Ja tā returno string, tad šis query nestrādās. Vispār, tev tur nekur nav '(quote), neticu, ka visi fieldi ir skaitļi.

Edited by Леший
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...