lunes, 9 de febrero de 2015

Routing Script

<html>
<head>
<title>Update a Record in MySQL Database</title>
</head>
<body>

<?php
if(isset($_POST['update']))
{
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = '123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

$emp_id = $_POST['emp_id'];
$emp_salary = $_POST['emp_salary'];

$sql= "INSERT INTO `asterisk`.`pbx` (`pbx_id`, `ip`, `status`, `date`, `name`, `did`, `reserved2`) VALUES (NULL, '$_POST[ip]', 'enabled', CURRENT_TIMESTAMP, '$_POST[name]', '$_POST[did]', '1');";
mysql_select_db('asterisk');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not update data: ' . mysql_error());
}
 header("Location:routing.php");

echo "Updated data successfully\n";
mysql_close($conn);
}
else
{

}
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100"> DID NUMBER</td>
<td><input name="did" type="text" id="did"></td>
</tr>

<tr>
<td width="100"> DNS/IP</td>
<td><input name="ip" type="text" id="ip"></td>
</tr>
<tr>
<td width="100">Trunk Name</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>

<?php

 $dbhost='localhost';
        $dbuser='root';
        $dbpass=123;
        $dbname='asterisk';

        $db = mysql_connect($dbhost, $dbuser, $dbpass) or die("Couldn't connect to the database.");

        mysql_select_db($dbname) or die("Couldn't select the database");

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn )
{
  die('Could not connect: ' . mysql_error());
}

$result = mysql_query("SELECT * FROM `pbx` order by date desc");
echo "<strong>Total  of records</strong> ".mysql_num_rows($result );
echo "<table border='1'  align='center'>

<tr>
<th>ID</th>
<th>DID</th>
<th>DNS/IP</th>
<th>TRUNK</th>
<th>STATUS</th>
<th>DELETE</th>
<th>DATE</th>

</tr>";
   while($row = mysql_fetch_array($result))
    {
  echo "<tr>";
 echo "<td>" . $row['pbx_id'] . "</td>";
          echo "<td>" . $row['did'] . "</td>";
  echo "<td>" . $row['ip'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";


echo "<td><a href=?ID=$row[pbx_id]&status=$row[status]>" ."$row[status]" . "</td></a>";
 
echo "<td><a href=?ID=$row[pbx_id]&del=1>" ."DELETE" . "</td></a>";

 echo "<td>" . $row['date'] . "</td>";


  echo "</tr>";
}

echo "</table>";

mysqli_close($con);
?>

<?php

 $dbhost='localhost';
        $dbuser='root';
        $dbpass=123;
        $dbname='asterisk';

        $db = mysql_connect($dbhost, $dbuser, $dbpass) or die("Couldn't connect to the database.");



if($_GET[ID]>0){

if($_GET[status]=='enabled'){

$status='disabled';

}
if($_GET[status]=='disabled'){
$status='enabled';
}


$query = mysql_query("update  `pbx` set status='$status'  WHERE `pbx_id`= '$_GET[ID]'");
//UPDATE `asterisk`.`pbx` SET `status` = 'enabled' WHERE `pbx`.`pbx_id` = 22;

if ($query) {
    header("Location:routing.php");
}


if (!$query) {
    die('Could not query:' . mysql_error());
}


}
?>



<?php

 $dbhost='localhost';
        $dbuser='root';
        $dbpass=123;
        $dbname='asterisk';

        $db = mysql_connect($dbhost, $dbuser, $dbpass) or die("Couldn't connect to the database.");



if($_GET[ID]>0&& $_GET[del]==1){

$query = mysql_query("DELETE FROM `pbx` WHERE `pbx_id`= '$_GET[ID]'");


if ($query) {
    header("Location:routing.php");
}


if (!$query) {
    die('Could not query:' . mysql_error());
}


}
?>

sábado, 7 de febrero de 2015

regular expresion

http://www.zytrax.com/tech/web/regex.htm#brackets
http://www.opensourceforu.com/2012/06/beginners-guide-gnu-grep-basics-regular-expressions/

ereg_replac

PHP Function ereg_replace()

previous

Advertisements

Syntax

string ereg_replace (string pattern, string replacement, string originalstring);

Definition and Usage

The ereg_replace() function searches for string specified by pattern and replaces pattern with replacement if found. The ereg_replace() function operates under the same premises as ereg(), except that the functionality is extended to finding and replacing pattern instead of simply locating it.
Like ereg(), ereg_replace() is case sensitive.

Return Value

  • After the replacement has occurred, the modified string will be returned.
  • If no matches are found, the string will remain unchanged.

Example

Following is the piece of code, copy and paste this code into a file and verify the result.
<?php

$copy_date = "Copyright 1999";
$copy_date = ereg_replace("([0-9]+)", "2000", $copy_date);
print $copy_date;

?>
This will produce following result
Copyright 2000

remove space and numeric caracter

remover espacios y letras  caracter no numericos
<?php
function onlyAlphanumericAndSpaces($text) {
  # allow only alphanumeric
  return ereg_replace("[^0-9 ]", "", $text );
}

$string=" E#D  re18 09 71 4 4389 ";
$string = str_replace(' ', '', $string);
$string = preg_replace('/\s+/', '', $string);
echo onlyAlphanumericAndSpaces($string);
}








?>



remover caracter no alfa numericos


function onlyAlphanumericAndSpaces($text) {
  # allow only alphanumeric
  return ereg_replace("[^A-Za-z0-9 ]", "", $text );
}

remove space and whitespace from a variable

For just spaces, use str_replace:
$string = str_replace(' ', '', $string);




For all whitespace, use preg_replace:

$string = preg_replace('/\s+/', '', $string); 

http://stackoverflow.com/questions/2109325/how-to-strip-all-spaces-out-of-a-string-in-php 




<?php
function string_to_filename($word) {
    $tmp preg_replace('/^\W+|\W+$/'''$word); // remove all non-alphanumeric chars at begin & end of string
    $tmp preg_replace('/\s+/''_'$tmp); // compress internal whitespace and replace with _
    return strtolower(preg_replace('/\W-/'''$tmp)); // remove all non-alphanumeric chars except _ and -}?>

mySQL select IN range


Is it possible to define a range for the IN part of the query, something like this
SELECT job FROM mytable WHERE id IN (10..15);
Instead of
SELECT job FROM mytable WHERE id IN (10,11,12,13,14,15);
shareimprove this question

1 Answer

up vote 28 down vote accepted
You can't, but you can use BETWEEN
SELECT job FROM mytable WHERE id BETWEEN 10 AND 15
shareimprove this answer