Why am I only receiving the first word from the database field?

0

The code below returns values from the database, however the model field only returns me the first word of the table field, the rest of the template name does not appear. What am I doing wrong?

<?php
include('conecta.php');

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 



$sql = "SELECT product_id, model, price FROM ocqp_product LIMIT 5";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {



        echo '<form action="" method="post">
        <input type="text" name="pid" value='. $row["product_id"].' ><br>
        <input type="text" name="model" value='. $row['model'].' ><br>
        <input type="text" name="price" value='. $row["price"].' ><br>


        </form>';
   }
} else {
echo "0 results";
}
$conn->close();

Structure

link

    
asked by anonymous 08.09.2016 / 18:07

3 answers

3

Try this, you were not putting quotation marks in value .

echo '<form action="" method="post">
        <input type="text" name="pid" value="'. $row["product_id"].'" ><br>
        <input type="text" name="model" value="'. $row['model'].'" ><br>
        <input type="text" name="price" value="'. $row["price"].'" ><br>


        </form>';
    
08.09.2016 / 18:33
0

Augusto is correct yet add

echo '<input type="" name="" value="'.$row['name'].'" />';
    
08.09.2016 / 19:02
0

Why do you mix Mysqli methods, I recommend using Object Oriented mode, in case your code looks like this:

   <?php
include('conecta.php');

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 



$sql = "SELECT product_id, model, price FROM ocqp_product LIMIT 5";
$result = $conn->query($sql);

if ($conn->num_rows($result) > 0) {
    // output data of each row
    while($row = $conn->fetch_assoc($result)) {



        echo '<form action="" method="post">
        <input type="text" name="pid" value="'. $row["product_id"].'" ><br>
        <input type="text" name="model" value="'. $row['model'].'" ><br>
        <input type="text" name="price" value="'. $row["price"].'" ><br>


        </form>';
   }
} else {
echo "0 results";
}
$conn->close();

Yeah, and you forgot the quotes in value!

    
08.09.2016 / 19:03