0

I have to filter some row by date from one web page to another :

This is the first page

<?php while($row = mysql_fetch_array($result)){ ?>      
    <tr>
        <td><a href="meeting_view.php?meet=<?php echo $row[2];?>" target = '_blank' ><?php echo date("d-m-Y", strtotime($row[2]));?></a>
</td><?php}?>

This is meeting_view.php

$meet = $_GET['meet'];
$result = mysql_query("SELECT * FROM meeting WHERE meeting_date=$meet");

It's not working, what's wrong in my script ?

agus priyo
  • 95
  • 1
  • 9

4 Answers4

2

Change

$result = mysql_query("SELECT * FROM meeting WHERE meeting_date=$meet");

To

$result = mysql_query("SELECT * FROM meeting WHERE meeting_date='$meet'");
William Madede
  • 727
  • 4
  • 8
  • Always a pleasure mate...For future ref, please start learning more about mysqli and pdo to be safe when coming to database vulnerabilities...done – William Madede Dec 02 '15 at 08:24
2

Although William's answer is correct and will help you fix your immediate issue I would like to mention a couple more problems I notice:

  1. You should avoid using the mysql extension because it's been deprecated since PHP 5.5 see here
  2. Your code is currently vulnerable to SQL Injection. Please take a look here to check out how you can protect your database.

Cheers

Community
  • 1
  • 1
mrun
  • 744
  • 6
  • 19
  • 24
1

Just make some change as below:

<td> <a href="meeting_view.php?meet='<?php echo $row[2];?>'"   // add quotes
        target = '_blank' >
        <?php echo date("d-m-Y", strtotime($row[2]));?>
     </a>
</td>

Also change :

$result = mysql_query("SELECT * FROM meeting WHERE meeting_date='".$meet."')"; 
Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
0
  1. You might have two meetings at the same time. To select the correct one, you should use id's instead of the time.

  2. To make the script faster and easier, let MySQL do the date conversion.

  3. Using associative arrays makes the script easier to debug and read!

  4. Another important view is to use Mysqli insted of Mysql! It is just as simple, but works in future updates of PHP.

  5. Make sure the input is what you want. Convert the sent id to an integer with intval( $_REQUEST['id'] ). Otherwise someone might insert this id through an url: "0; DROP TABLE meeting;" which would select row with id 0 and delete the whole table. This is called SQL-injection as mrun said in his answer!

I would rewrite everything like this:

// $sql = 'SELECT *, DATE_FORMAT("%d-%m-%Y", meeting_date) AS date FROM meeting';
<?php while($row = mysqli_fetch_assoc($result)){ ?>      
    <tr>
        <td><a href="meeting_view.php?id=<?= $row['id'] ?>" 
               target='_blank' ><?= $row['date'] ?></a>
</td><?php}?>

And:

$result = mysqli_query('SELECT * FROM meeting WHERE id=' 
        . intval( $_REQUEST['id'] ) );
Hasse Björk
  • 1,431
  • 13
  • 19