Jump to content

mysql select statement is not taking space in consideration


Ivan007
Go to solution Solved by kicken,

Recommended Posts

I want to display  data in my table tbljobcategory but for example , if the return data is Infomation and Technology it is only returning Infomation...

 

 

<?php $stmt = $pdo->prepare("select * from tbljobcategory where category_id=:catid");
 $stmt -> execute(array(":catid"=>$_GET["catid"])); 
$rows = $stmt ->fetch(PDO::FETCH_ASSOC);
$CategoryName = htmlspecialchars($rows["Category"]); 
?> 
<div class="card text-center form-add" style="width:35%;"> <div class="card-header"> Edit Job Category </div> 
  <div class="card-body"> 
    <form method="post" action=""> 
      <div class="mb-3"> 
        <label for="exampleFormControlInput1" class="form-label">Current Job Category</label> 
        <input class="form-control" type="text" value=<?php echo "$CategoryName " ;?> disabled readonly> </div> 
      <div class="mb-3"> <label for="exampleFormControlTextarea1" class="form-label">New Job Category</label> 
        <input class="form-control" type="text" name="NCategory" placeholder="New Job Category" aria-label="default input example"> </div> 
      <button type="submit" name="btn-update" class="btn btn-primary">Save Changes</button> 
      	<button type="submit" name="btn-cancel" class="btn btn-secondary">Cancel</button> </div> </form>

 

Link to comment
Share on other sites

  • Solution
4 hours ago, Ivan007 said:
<input class="form-control" type="text" value=<?php echo "$CategoryName " ;?> disabled readonly>

Think about how that will get rendered after the PHP code is processed.  You'll have:

<input class="form-control" type="text" value=Information and Technology  disabled readonly> 

You've set the value to just Information.  The words and and Technology become unknown attributes.

You need to put quotes around the value attribute content if you want to be able to use spaces.

 

Link to comment
Share on other sites

If you look at the html source you will see that it is the same as before...

<input class="form-control" type="text" value=Information and Technology  disabled readonly> 

It needs to be

<input class="form-control" type="text" value="Information and Technology"  disabled readonly>
                                              ^                          ^ 

The php needs to be

<?php
            
               echo '<input class="form-control" type="text"  value="'.$CategoryName.'"   disabled readonly>';
               ?>

or, using a double-quoted string

<?php
            
               echo "<input class='form-control' type='text'  value=\"$CategoryName\"   disabled readonly>";
               ?>

 

Link to comment
Share on other sites

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.