Jump to content

my variable doesn't show the right type


Flaviaac

Recommended Posts

Hi guys, 

I have a odd problem here.

I'm a beginner and I have no idea what it can be.. 😑

ps. English is not my first language, so I hope you can understand... ☺️

 

In dropdown field below, I put in value property the ID column, but when it registers in the database, it saves as string type and not as integer.

<?php
$sql = "SELECT id, sigla FROM local ORDER BY sigla ASC";
$result = $conn->query($sql);
?>
.
.
.
<select name="local" class="form-control">
  <option selected>Selecione...</option>
  <?php
  while($row = $result->fetch_assoc()){                                  
    echo "<option value=".$row['id'].">".$row['sigla']."</option>";                                  
  }                              
  ?>                            
</select>
.
.
.

I used a var_dump() on ID to know what would happend, and it shows as string type.

<pre>
<?php
$sql = "SELECT id, sigla FROM local ORDER BY sigla ASC";
$result = $conn->query($sql);
$row = $result->fetch_assoc();  
var_dump($row['id']);
?>
</pre>

Result:

  string(1) "5"

 

 

This is the database:

-- phpMyAdmin SQL Dump
-- version 4.8.3
-- https://www.phpmyadmin.net/


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Banco de dados: `arq`
--

-- --------------------------------------------------------

--
-- Estrutura para tabela `local`
--

CREATE TABLE `local` (
  `id` int(11) NOT NULL,
  `SIGLA` mediumtext NOT NULL,
  `LOCAL` mediumtext NOT NULL,
  `TELEFONE` mediumtext NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Fazendo dump de dados para tabela `local`
--

INSERT INTO `local` (`id`, `SIGLA`, `LOCAL`, `TELEFONE`) VALUES
(1, 'AAC', 'AAC', '2222-2222'),
(2, 'DSV', 'DSV', '1111-1111'),
(3, 'SCA', 'SCA', '3333-3333');

--
-- Índices de tabelas apagadas
--

--
-- Índices de tabela `local`
--
ALTER TABLE `local`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT de tabelas apagadas
--

--
-- AUTO_INCREMENT de tabela `local`
--
ALTER TABLE `local`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Thank you so much!!

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...