Jump to content

Recommended Posts

443 / 5 000

Résultats de traduction

star_border

Hi everybody, here I managed to get some functionality working but now I'm stuck on my last step of the project, I can't get the correct result...

I have a db column which has the value 0 / 1 I made a table where I want to display the return as Enable or Disable...

the problem is the command changed the value from 0 to 1 but on my table I always have the result Disable Here is my php code:

<label for="inputdid_ivr_disable" class="sr-only">REONDEUR</label>
<input value="<?php echo $item['did_ivr_disable'] == (0) ? 'Disabled' : 'Enabled'  ?>" type="text"
id="inputdid_ivr_disable" class="form-control" name="did_ivr_disable" placeholder="REPONDEUR" autofocus>

 

Link to comment
https://forums.phpfreaks.com/topic/314761-problem-display-result/
Share on other sites

Just now, Mouradsah said:

it doesn't work for me

this is my entire code 

 

<?php
require_once "api.php";

if (isAuth() ==  false) {
    header('Location: login.html');
}

if (!isset($_GET['username']) || !isset($_GET['did']) || !isset($_GET['cid']) || !isset($_GET['serip']) || !isset($_GET['domaine']) || !isset($_GET['port'])  || !isset($_GET['did_id'])) {
    header('Location: index.php');
}

if (isset($_GET['dest'])) {
    $dest = $_GET['dest'];
} else {
    $dest = '';
}

if (isset($_GET['dest_id'])) {
    $dest_id = $_GET['dest_id'];
} else {
    $dest_id = NULL;
}

?>


<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

    <style>
    html,
    body {
        height: 100%;
    }

    body {
        display: -ms-flexbox;
        display: -webkit-box;
        display: flex;
        -ms-flex-align: center;
        -ms-flex-pack: center;
        -webkit-box-align: center;
        align-items: center;
        -webkit-box-pack: center;
        justify-content: center;
        padding-top: 40px;
        padding-bottom: 40px;
        background-color: #f5f5f5;
    }

    .form-edit {
        width: 100%;
        max-width: 330px;
        padding: 15px;
        margin: 0 auto;
    }


    .form-edit .form-control {
        position: relative;
        box-sizing: border-box;
        height: auto;
        padding: 10px;
        font-size: 16px;
    }

    .form-edit .form-control:focus {
        z-index: 2;
    }
    </style>

    <title>EDIT</title>
</head>

<body>


    <form class="form-edit" action="action.php" method="post">

        <input type="hidden" name="username" value="<?php echo $_GET['username']; ?>" />
        <input type="hidden" name="did" value="<?php echo $_GET['did']; ?>" />
        <input type="hidden" name="cid" value="<?php echo $_GET['cid']; ?>" />
        <input type="hidden" name="serip" value="<?php echo $_GET['serip']; ?>" />
        <input type="hidden" name="did_id" value="<?php echo $_GET['did_id']; ?>" />
        <input type="hidden" name="dest" value="<?php echo $dest; ?>" />

        <?php
        if ($dest_id) {
            echo '<input type="hidden" name="dest_id" value="' . $_GET['dest_id'] . '" />';
        }
        $PORT = $_GET['did_dom_name_port'];
		if (!is_numeric($PORT)) { $PORT = '5060'; }
		if ($_GET['username'] == '1387585776') { $PORT = '5080'; }
		if ($_GET['username'] == '2998208535') { $PORT = '5080'; }
        ?>



        <h1 class="h3 mb-3 font-weight-normal">Edit</h1>
        <label for="inputdomaine" class="sr-only">DOMAINE</label>
        <input value="<?php echo $_GET['domaine']; ?>" type="text" id="inputdomaine" class="form-control" name="domaine"
            placeholder="DOMAINE" autofocus>

        <label for="inputport">PORT (only 5060 or 5080)</label>
        <input value="<?php echo $_GET['port']; ?>" type="numeric" id="inputport" class="form-control" name="port"
            placeholder="PORT" autofocus>
        <p>
            <th><span style="color:red">State VNT Answering Machine</span> </th>
        </p>

        <label for="inputdid_ivr_disable" class="sr-only">REONDEUR</label>
        <input value="<?php echo $item['did_ivr_disable'] == (0) ? 'Disabled' : 'Enabled'  ?>" type="text"
            id="inputdid_ivr_disable" class="form-control" name="did_ivr_disable" placeholder="REPONDEUR" autofocus>

        <p>
            <th>Disable VNT Answering Machine </th>
        </p>
        <form action="api.php" method="POST">
            <div class="form-group mb-3">
            </div>
            <div class="form-group mb-3">
                <input type="radio" id="1" name="did_ivr_disable" value="1" />
                <label for="did_ivr_disable">Oui</label>
                <input type="radio" id="0" name="did_ivr_disable" value="0" />
                <label for="did_ivr_disable">Non</label>


            </div>

            <label for="inputdest" class="sr-only">DESTINATION</label>
            <!-- <textarea rows="4" name="dest" id="inputdest" class="form-control" placeholder="DESTINATION"><?php echo $dest; ?></textarea> -->

            <button class="btn btn-lg btn-primary btn-block" type="submit">Edit</button>
        </form>


        <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.minjs"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

</body>

</html>

 

12 minutes ago, Barand said:
<input value="<?php echo $item['did_ivr_disable'] == (0) ? 'Disabled' : 'Enabled'  ?>" type="text"

From this

                          <th>USERNAME</th>
                            <th>DID</th>
                            <th>DOMAINE</th>
                            <th>PORT</th>
                            <th>Disable VNT Answering Machine</th>
                            <th>ACTION</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php
                        
                        
                        
                        foreach (getDid() as $item) {
                            echo "
                            <tr>
                            <td>" , $item['username'] , "</td>
                            <td>" , $item['did'] , "</td>
                            <td>" , $item['did_dom_name'] , "</td>
                            <td>" , $item['did_dom_name_port'] , "</td>
                            <td>" , $item['did_ivr_disable'] == (0) ? 'Disabled' : 'Enabled' ,"</td>
                            <td>
                            
                        <a href='edit.php?username=" , $item[' username'] , "&did=" , $item['did'] , "&cid=" ,
                            $item['card_id'] , "&serip=" , $item['ser_ip_sip'] , "&domaine=" ,$item['did_dom_name'] , "&did_ivr_disable=", $item['did_ivr_disable'] 
                            , "&port=" , $item['did_dom_name_port'] , "&dest=" , $item['destination'] , "&did_id=" , $item['did_id'] , "&dest_id=" ,
                            $item['destination_id'] , "'>edit</a></td>

                            </tr>
                            " ; } ?>

                    </tbody>

 

Edited by Mouradsah

Hi everybody,
here I come back because I did not find a solution to my problem..
in short I have two radio button which works well when inserting data on my database but I want when I return to the edition page I find the last one I checked
or the state of the function from the database
is it possible!!!!

 

this is my Edit.php

 

<?php
require_once "api.php";



if (isAuth() ==  false) {
    header('Location: login.html');
}

if (!isset($_GET['username']) || !isset($_GET['did']) || !isset($_GET['cid']) || !isset($_GET['serip']) || !isset($_GET['domaine']) || !isset($_GET['port'])  || !isset($_GET['did_id'])) {
    header('Location: index.php');
}

if (isset($_GET['dest'])) {
    $dest = $_GET['dest'];
} else {
    $dest = '';
}

if (isset($_GET['dest_id'])) {
    $dest_id = $_GET['dest_id'];
} else {
    $dest_id = NULL;
}

?>


<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

    <style>
    html,
    body {
        height: 100%;
    }

    body {
        display: -ms-flexbox;
        display: -webkit-box;
        display: flex;
        -ms-flex-align: center;
        -ms-flex-pack: center;
        -webkit-box-align: center;
        align-items: center;
        -webkit-box-pack: center;
        justify-content: center;
        padding-top: 40px;
        padding-bottom: 40px;
        background-color: #f5f5f5;
    }

    .form-edit {
        width: 100%;
        max-width: 330px;
        padding: 15px;
        margin: 0 auto;
    }


    .form-edit .form-control {
        position: relative;
        box-sizing: border-box;
        height: auto;
        padding: 10px;
        font-size: 16px;
    }

    .form-edit .form-control:focus {
        z-index: 2;
    }
    </style>

    <title>EDIT</title>
</head>

<body>


    <form class="form-edit" action="action.php" method="post">

        <input type="hidden" name="username" value="<?php echo $_GET['username']; ?>" />
        <input type="hidden" name="did" value="<?php echo $_GET['did']; ?>" />
        <input type="hidden" name="cid" value="<?php echo $_GET['cid']; ?>" />
        <input type="hidden" name="serip" value="<?php echo $_GET['serip']; ?>" />
        <input type="hidden" name="did_id" value="<?php echo $_GET['did_id']; ?>" />
        <input type="hidden" name="dest" value="<?php echo $dest; ?>" />

        <?php
        if ($dest_id) {
            echo '<input type="hidden" name="dest_id" value="' . $_GET['dest_id'] . '" />';
        }
        $PORT = $_GET['did_dom_name_port'];
		if (!is_numeric($PORT)) { $PORT = '5060'; }
		if ($_GET['username'] == '1387585776') { $PORT = '5080'; }
		if ($_GET['username'] == '2998208535') { $PORT = '5080'; }
        ?>



        <h1 class="h3 mb-3 font-weight-normal">Edit</h1>
        <label for="inputdomaine" class="sr-only">DOMAINE</label>
        <input value="<?php echo $_GET['domaine']; ?>" type="text" id="inputdomaine" class="form-control" name="domaine"
            placeholder="DOMAINE" autofocus>

        <label for="inputport">PORT (only 5060 or 5080)</label>
        <input value="<?php echo $_GET['port']; ?>" type="numeric" id="inputport" class="form-control" name="port"
            placeholder="PORT" autofocus>



        <p>
            </br>
            <th> Edit Answering Machine </th>
        </p>
        <form action="api.php" method="POST">
            <div class="form-group mb-3">
            </div>
            <div class="form-group mb-3">
                <input type="radio" id="1" name="did_ivr_disable" value="1" />
                <label for="did_ivr_disable">Enable</label>
                <input type="radio" id="0" name="did_ivr_disable" value="0" />
                <label for="did_ivr_disable">Disable</label>

                <label for="inputdest" class="sr-only">DESTINATION</label>
                <!-- <textarea rows="4" name="dest" id="inputdest" class="form-control" placeholder="DESTINATION"><?php echo $dest; ?></textarea>
                -->

                <button class="btn btn-lg btn-primary btn-block" type="submit">Edit</button>
        </form>


        <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.minjs"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

</body>

</html>

 

mmmmm.png

39 minutes ago, Mouradsah said:

no me I want that if in the database the answering machine is 1 it displays yes automatically checked if 0 it displays me not selected
I want it to take the state from the database

Exactly. As I said, determine which button needs to be shown as selected

if the value in the database is 0, then the 0 button needs to be "checked".

if the value in the database is 1, then the 1 button needs to be "checked".

Example

$currentValue = 0;    // from DB

$chk0 = $currentValue==0 ? 'checked="checked"' : '';
$chk1 = $currentValue==1 ? 'checked="checked"' : '';

echo "<input type='radio' name='myradio' value='0' $chk0> No &emsp; <input type='radio' name='myradio' value='1' $chk1> Yes";

 

Edited by Barand
12 hours ago, Barand said:

Exactly. As I said, determine which button needs to be shown as selected

if the value in the database is 0, then the 0 button needs to be "checked".

if the value in the database is 1, then the 1 button needs to be "checked".

Example

$currentValue = 0;    // from DB

$chk0 = $currentValue==0 ? 'checked="checked"' : '';
$chk1 = $currentValue==1 ? 'checked="checked"' : '';

echo "<input type='radio' name='myradio' value='0' $chk0> No &emsp; <input type='radio' name='myradio' value='1' $chk1> Yes";

 

thank's but it show me Always 0 even is 1 on my bd

I'm equally sorry that we are new to telepathic communication and so have no idea what your code is that is giving the result below.

21 minutes ago, Mouradsah said:

thank's but it show me Always 0 even is 1 on my bd

Did you implement the method I showed you?

27 minutes ago, Barand said:

I'm equally sorry that we are new to telepathic communication and so have no idea what your code is that is giving the result below.

Did you implement the method I showed you?

yes 

<?php
require_once "api.php";


if (isAuth() ==  false) {
    header('Location: login.html');
}

if (!isset($_GET['username']) || !isset($_GET['did']) || !isset($_GET['cid']) || !isset($_GET['serip']) || !isset($_GET['domaine']) || !isset($_GET['port'])  || !isset($_GET['did_id'])) {
    header('Location: index.php');
}

if (isset($_GET['dest'])) {
    $dest = $_GET['dest'];
} else {
    $dest = '';
}

if (isset($_GET['dest_id'])) {
    $dest_id = $_GET['dest_id'];
} else {
    $dest_id = NULL;
}

?>


<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

    <style>
    html,
    body {
        height: 100%;
    }

    body {
        display: -ms-flexbox;
        display: -webkit-box;
        display: flex;
        -ms-flex-align: center;
        -ms-flex-pack: center;
        -webkit-box-align: center;
        align-items: center;
        -webkit-box-pack: center;
        justify-content: center;
        padding-top: 40px;
        padding-bottom: 40px;
        background-color: #f5f5f5;
    }

    .form-edit {
        width: 100%;
        max-width: 330px;
        padding: 15px;
        margin: 0 auto;
    }


    .form-edit .form-control {
        position: relative;
        box-sizing: border-box;
        height: auto;
        padding: 10px;
        font-size: 16px;
    }

    .form-edit .form-control:focus {
        z-index: 2;
    }
    </style>

    <title>EDIT</title>
</head>

<body>


    <form class="form-edit" action="action.php" method="post">

        <input type="hidden" name="username" value="<?php echo $_GET['username']; ?>" />
        <input type="hidden" name="did" value="<?php echo $_GET['did']; ?>" />
        <input type="hidden" name="cid" value="<?php echo $_GET['cid']; ?>" />
        <input type="hidden" name="serip" value="<?php echo $_GET['serip']; ?>" />
        <input type="hidden" name="did_id" value="<?php echo $_GET['did_id']; ?>" />
        <input type="hidden" name="dest" value="<?php echo $dest; ?>" />

        <?php
        if ($dest_id) {
            echo '<input type="hidden" name="dest_id" value="' . $_GET['dest_id'] . '" />';
        }
        $PORT = $_GET['did_dom_name_port'];
		if (!is_numeric($PORT)) { $PORT = '5060'; }
		if ($_GET['username'] == '1387585776') { $PORT = '5080'; }
		if ($_GET['username'] == '2998208535') { $PORT = '5080'; }
        ?>



        <h1 class="h3 mb-3 font-weight-normal">Edit</h1>
        <label for="inputdomaine" class="sr-only">DOMAINE</label>
        <input value="<?php echo $_GET['domaine']; ?>" type="text" id="inputdomaine" class="form-control" name="domaine"
            placeholder="DOMAINE" autofocus>

        <label for="inputport">PORT (only 5060 or 5080)</label>
        <input value="<?php echo $_GET['port']; ?>" type="numeric" id="inputport" class="form-control" name="port"
            placeholder="PORT" autofocus>



        <p>
            </br>
            <th> Edit Answering Machine </th>

            <?php
              $did_ivr_disable = 0;

              $chk0 = $$did_ivr_disable==0 ? 'checked="checked"' : '';
              $chk1 = $$did_ivr_disable==1 ? 'checked="checked"' : '';

                echo "<input type='radio' name='did_ivr_disable' value='0' $chk0> No &emsp; <input type='radio' name='did_ivr_disable'
                    value='1' $chk1> Yes";
                    ?>
            <label for="inputdest" class="sr-only">DESTINATION</label>
            <!-- <textarea rows="4" name="dest" id="inputdest" class="form-control" placeholder="DESTINATION"><?php echo $dest; ?></textarea>
                -->

            <button class="btn btn-lg btn-primary btn-block" type="submit">Edit</button>
    </form>


    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.minjs"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

</body>

</html>

 

11 minutes ago, Barand said:

If you always set it to zero, what other result do expect?

I did say that it should be the value from your DB.

the value from db is if disable is 0 or is enable is 1

the code should show me when i will edit the radio bouton should be exactly like is on db if on db is 0 it should No be checked or if is 1 the Yes button should be checked

Edited by Mouradsah

There is an absence of DB query code in anything you have posted and you have not explicitly stated the origin of all those values that you are passing in the query string ($_GET data), so here is my guess...

Does $_GET['did_ivr_disable'] contain the value from the database that you need? Or have you not thought about it?

26 minutes ago, Barand said:

There is an absence of DB query code in anything you have posted and you have not explicitly stated the origin of all those values that you are passing in the query string ($_GET data), so here is my guess...

Does $_GET['did_ivr_disable'] contain the value from the database that you need? Or have you not thought about it?

function editDomaine($domain, $did_id, $port, $did_ivr_disable)
{
    $clientid = getId();

    if ($clientid == false) {
        return false;
    }
    if (!is_numeric($port)) { $port = '5060'; }
	if ($port == '') { $port = '5060'; }
	if ( ($port != '5060') && ($port != '5080') ) { 
		return false; 
	}

    $db = new mysqli('localhost', 'root', '', 'db');

    if ($db->connect_errno) {
        die('<p>Connexion impossible : ' . $db->connect_error . '</p>');
    }

    $domain = addslashes($domain);
    $did_id = addslashes($did_id);
    $port = addslashes($port);
    $did_ivr_disable = addslashes($did_ivr_disable);

    $query = "UPDATE a2billing.cc_did
            SET did_dom_name='$domain', did_dom_name_port='$port', did_ivr_disable='$did_ivr_disable'
            WHERE id='$did_id'
            ";

    if ($db->query($query)) {
        $db->close();
        return true;
    }
    $db->close();
    return false;
}

i use this

Edited by Mouradsah
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.