0

i have a problem with my php and sql code. I trying to make code that when i enter some data that related with the database, the output should show 'zero' if the row user_designid equal to 0 and if vice versa it will show 'one'. but the problem is both of output only show the first anwser ('zero').

Php file (co.php is my config)

 <?php
 require "co.php";
 $link = mysqli_connect($h,$u,$p,$db);

 if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
 }
echo "Connected successfully";

$q = "select * from tab_ss_user where User_name ='".$_POST['name']."'";
$result = mysqli_query($link,$q);


if($result){
echo "<table border='1' >
<tr>
<td align=center> <b>user Id No</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Password</b></td>
<td align=center><b>responsibility</b></td></td>";

while($data = mysqli_fetch_row($result))
{   
echo "<tr>";
echo "<td align=center><option>$data[0]</option></td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center>$data[2]</td>";

    //this is the problem
if($data['User_DesignID'] == 0 ){
      echo "<td align=center> zero </td>";
 }
else{
      echo "<td align=center> one </td>";
 }


   echo "</tr>";
 }
   echo "</table>";
 }

  else{
   echo ' Failed';
 }
 ?>

that all thank you.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nexz
  • 93
  • 1
  • 10

3 Answers3

1

You are not referencing the field correctly See enter link description here

When using mysqli_fetch_row, the result is an associative array so $data['User_DesignID'] will not be referenced correctly.

Jeffrey Hitosis
  • 325
  • 3
  • 13
0

please make sure your column name is "User_DesignID"
if($data['User_DesignID'] == 0 ){

0

(Posted on behalf of the OP).

Thanks to Jeffrey idea, I have found an answer (please refer to Jeffrey's answer on this page).

And also if you want to use column name instead please use mysqli_fetch_assoc instead of row.

halfer
  • 19,824
  • 17
  • 99
  • 186