Jump to content


Pls help php and forms

  • Please log in to reply
1 reply to this topic

#1 theoretical_dreamer

  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 22 May 2006 - 06:18 AM

Guys need help in using forms, I have 4 fields in my database table named "ipadd". I have a search form that handle the queries inputted by the user. The user will input values in this format "". In the database table, the values in each octet of the IP address is distributed in the four fields. For example using the value "". The value of the 1st Octet "192" is in the 1st field of the database named "IP1". "168" will be in the second field and so on. However the value of the 1st and the second Octet is constant: "10" and "0". The problem is how can I get the value of the third and 4th Octet in php (can I use the trim command?). Please check my code:

case "ip":
$ip1 = 10;
$ip2 = 0; $ip3 = // What should I put in here?
$ip4 = // What should I put in here?
$rs = mysql_query("SELECT * FROM ipadd WHERE IP1 LIKE'%".$_GET['ip1']."%' AND IP2 LIKE'%".$_GET['ip3']."%' AND IP3 LIKE'%".$_GET['ip3']."%'" AND IP4 LIKE'%".$_GET['ip4']."%'");

#2 Kris

  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 22 May 2006 - 09:23 AM

You could use explode(), here's how it works...
$ip = "";
$bits = explode(".",$ip);
echo $bits[0]; //Prints 192
echo $bits[1]; //Prints 168
echo $bits[2]; //Prints 1
echo $bits[3]; //Prints 2

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users