Mouradsah Posted May 5, 2022 Share Posted May 5, 2022 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> Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/ Share on other sites More sharing options...
benanamen Posted May 5, 2022 Share Posted May 5, 2022 Why not just get it from the DB the way you want it instead of jumping through code? SELECT IF (did_ivr_disable = TRUE, 'Enabled', 'Disabled') AS did_ivr_disable Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595955 Share on other sites More sharing options...
Mouradsah Posted May 5, 2022 Author Share Posted May 5, 2022 9 minutes ago, benanamen said: Why not just get it from the DB the way you want it instead of jumping through code? SELECT IF (did_ivr_disable = TRUE, 'Enabled', 'Disabled') AS did_ivr_disable it doesn't work for me Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595956 Share on other sites More sharing options...
Mouradsah Posted May 5, 2022 Author Share Posted May 5, 2022 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> Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595957 Share on other sites More sharing options...
Barand Posted May 5, 2022 Share Posted May 5, 2022 <input value="<?php echo $item['did_ivr_disable'] == (0) ? 'Disabled' : 'Enabled' ?>" type="text" That line contains the only occurence of $item that I can find in your code - so where is it getting a value? Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595958 Share on other sites More sharing options...
Mouradsah Posted May 5, 2022 Author Share Posted May 5, 2022 (edited) 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 May 5, 2022 by Mouradsah Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595959 Share on other sites More sharing options...
Barand Posted May 5, 2022 Share Posted May 5, 2022 If it's coming from the link's querystring you should be using $_GET['did_ivr_disable'] 1 Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595960 Share on other sites More sharing options...
Mouradsah Posted May 5, 2022 Author Share Posted May 5, 2022 5 minutes ago, Barand said: If it's coming from the link's querystring you should be using $_GET['did_ivr_disable'] Thank's it's work now Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595961 Share on other sites More sharing options...
ginerjm Posted May 6, 2022 Share Posted May 6, 2022 How about this for the test portion: $item['did_ivr_disable'] === 0 ? 'Disabled' : 'Enabled' Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1595963 Share on other sites More sharing options...
Mouradsah Posted May 9, 2022 Author Share Posted May 9, 2022 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> Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596088 Share on other sites More sharing options...
Barand Posted May 9, 2022 Share Posted May 9, 2022 Determine which button needs to be shown as selected and set its "checked" attribute Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596089 Share on other sites More sharing options...
Mouradsah Posted May 9, 2022 Author Share Posted May 9, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596090 Share on other sites More sharing options...
dodgeitorelse3 Posted May 9, 2022 Share Posted May 9, 2022 I don't see a database query. That would be a good place to start. Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596092 Share on other sites More sharing options...
Barand Posted May 9, 2022 Share Posted May 9, 2022 (edited) 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   <input type='radio' name='myradio' value='1' $chk1> Yes"; Edited May 9, 2022 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596093 Share on other sites More sharing options...
Mouradsah Posted May 10, 2022 Author Share Posted May 10, 2022 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   <input type='radio' name='myradio' value='1' $chk1> Yes"; thank's but it show me Always 0 even is 1 on my bd Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596109 Share on other sites More sharing options...
Barand Posted May 10, 2022 Share Posted May 10, 2022 That must be annoying. Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596110 Share on other sites More sharing options...
Mouradsah Posted May 10, 2022 Author Share Posted May 10, 2022 3 minutes ago, Barand said: That must be annoying. I'm sorry I'm new to programming Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596111 Share on other sites More sharing options...
Barand Posted May 10, 2022 Share Posted May 10, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596112 Share on other sites More sharing options...
Mouradsah Posted May 10, 2022 Author Share Posted May 10, 2022 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   <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> Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596114 Share on other sites More sharing options...
Barand Posted May 10, 2022 Share Posted May 10, 2022 11 minutes ago, Mouradsah said: <?php $did_ivr_disable = 0; If you always set it to zero, what other result do expect? I did say that it should be the value from your DB. Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596115 Share on other sites More sharing options...
Mouradsah Posted May 10, 2022 Author Share Posted May 10, 2022 (edited) 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 May 10, 2022 by Mouradsah Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596116 Share on other sites More sharing options...
Barand Posted May 10, 2022 Share Posted May 10, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596117 Share on other sites More sharing options...
Mouradsah Posted May 10, 2022 Author Share Posted May 10, 2022 (edited) 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 May 10, 2022 by Mouradsah Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596118 Share on other sites More sharing options...
dodgeitorelse3 Posted May 10, 2022 Share Posted May 10, 2022 That updates database but I think you also need a select query to be able to have correct radio button ticked when your page loads. Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596119 Share on other sites More sharing options...
Mouradsah Posted May 10, 2022 Author Share Posted May 10, 2022 14 minutes ago, dodgeitorelse3 said: That updates database but I think you also need a select query to be able to have correct radio button ticked when your page loads. how i can do this Quote Link to comment https://forums.phpfreaks.com/topic/314761-problem-display-result/#findComment-1596120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.