Jee Garin
Jee Garin

Reputation: 3

$_POST stops at the first space it sees

I Have this code in PHP that generates the values in a Drop Down Box that is stored in a Database.

<select name=getdate>
        $con = mysqli_connect("localhost","root","","dbjobsheetsf");
        $sql1 = "SELECT colDate FROM tbljs ";
        $queryR = mysqli_query($con, $sql1);    
        $p = 0;
                    while($r = mysqli_fetch_array($queryR)) {   
                            echo "<option value=".$r['colDate'].">".$r['colDate']."</option>"; 
                    }

            mysqli_close($con); 

</select>

Example, the current value is Thursday, August 28, 2014. The problem is when i execute the code;

echo $_POST['getdate'];

the only value that is echoed is Thursday,

For Short, It stops at the first space it sees. What should I do?

The date is generated by JAVASCRIPT so it'll be hard for me to change those spaces to underlines, so I must retain the spaces.

Miss Jenz's code helped me a lot! Thanks!

Upvotes: 0

Views: 189

Answers (5)

Shen Siddharta
Shen Siddharta

Reputation: 50

$cdate = $_POST['getdate'];
$dates = date('Y-m-d H:i:s', strtotime($cdate) );

echo $dates

you have to use date function to convert it into standard format

Upvotes: 0

Marcus Rommel
Marcus Rommel

Reputation: 1294

If you try to print out the array $r and you see the whole date, serialize the value or store it in a text variable and then pass it to PHP. This should work.

If you print out the array and you don't get the whole date, recheck your query.

Why don't you try to put your date in a string variable and pass this through POST?

Upvotes: 0

Mad Angle
Mad Angle

Reputation: 2330

You missed some '' in the option value section. Try this code

<?php
    $con = mysqli_connect("localhost","root","","dbjobsheetsf");
    $sql1 = "SELECT colDate FROM tbljs ";
    $queryR = mysqli_query($con, $sql1);    
    $p = 0;
    while($r = mysqli_fetch_array($queryR)) {   
        echo '<option value="'.$r['colDate'].'">'.$r['colDate'].'</option>'; 
    }
    mysqli_close($con);
?>
</select>

Upvotes: 1

Ravi Mehta
Ravi Mehta

Reputation: 448

    <select name=getdate>
<?php
            $con = mysqli_connect("localhost","root","","dbjobsheetsf");
            $sql1 = "SELECT colDate FROM tbljs ";
            $queryR = mysqli_query($con, $sql1);    
            $p = 0;
                        while($r = mysqli_fetch_array($queryR)) {   
                                echo "<option value='".$r['colDate']."'>".$r['colDate']."</option>";
                        }

                mysqli_close($con); 
    ?>
    </select>

Upvotes: 0

Jenz
Jenz

Reputation: 8369

You have to enclose the value of options inside quotes like

echo "<option value='".$r['colDate']."'>".$r['colDate']."</option>"; 
                    ^                 ^

Upvotes: 6

Related Questions