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());
}


}
?>

No hay comentarios:

Publicar un comentario