I'm trying to improve my PHP programming skills, can anyone give me any tips or direction based on this code that I wrote?
<?php
include("db.php");
include("function.php");
//variables
$number = htmlspecialchars($_POST['num']);
$date = date("Y-m-d");
//validate phone number
if (strlen($_POST['num']) != 12){
print "Invalid Phone Number.";
die();
}
//check how many times the number was called today
$callstoday = mysql_query("
SELECT number
FROM numbers
WHERE number = '$number'
AND date
LIKE '$date%'")
or die(mysql_error());
$callstotal = mysql_num_rows($callstoday);
//cant do more than 5 calls
if ($callstotal < 5){
//do nothing
}else{
print "Not Allowed";
die();
}
//break up the number in 3 parts
$bits = explode("-", $number);
$data = get_carrier("http://site.com/?action=carrierlookup&p1=".$bits[0]."&p2=".$bits[1]."&p3=".$bites[2]."&iecache=0");
//check when they want to call
if ($_POST['when'] == 'now' ){
$when = "0";
}elseif($_POST['when'] == 'secs'){
$when = "30";
}elseif($_POST['when'] == 'minute'){
$when = "60";
}elseif($_POST['when'] == '2minute'){
$when = "120";
}elseif($_POST['when'] == '5minute'){
$when = "300";
}
//check for carrier
if(strstr($data, 'Cingular')){
$carrier = "AT&T";
}elseif(strstr($data, 'Sprint')){
$carrier = "Sprint";
}elseif(strstr($data, 'Verzion')){
$carrier = "Verzion";
}elseif(strstr($data, 'T-Mobile')){
$carrier = "T-Mobile";
}elseif(strstr($data, 'Boost')){
$carrier = "Boost Mobile";
}elseif(strstr($data, 'Cricket')){
$carrier = "Cricket";
}elseif(strstr($data, 'Alltel')){
$carrier = "Alltel";
}elseif(strstr($data, 'Unable')){
$carrier = "Unknown Carrier";
}
//inset number and carrier into database.
mysql_query("INSERT INTO numbers (number, carrier)
VALUES ('$number', '$carrier')");
print "success";
mysql_close($con);
//call out to the number
$strippednumber = str_replace("-", "", $number);
$call = call("http://domain.com");
?>