0

I've been giving myself a basic refresher course in PHP without using template engines (although I've learnt some Smarty and Twig recently I felt I should keep practising basic PHP), and this is my basic page displaying a list of vehicles and when they were registered:

 <?php 
 // Connects to your Database 
 mysql_connect("localhost", "testing", "testingpass") or die(mysql_error()); 
 mysql_select_db("cars1") or die(mysql_error()); 
 $data = mysql_query("SELECT * FROM autos") 
 or die(mysql_error()); 
 echo "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 "<tr>"; 
 //echo "<td>"date("d M Y",strtotime($info['registered']));"</td> "; 
 echo "<td><tr>".$info['make'] ." ".$info['model'] ."</td><tr> "; 
 } 
 echo "</table>"; 
 ?> 

It works if the datetime is commented out, but if it's uncommented the page appears blank - I'm using MAMP as my webserver, latest PHP.

For a simple page this works well, but how should I format this date? (I used the tutorial at http://erikastokes.com/mysql-help/display-mysql-dates-in-other-formats.php to try this).

What changes should I make to fix this problem with the date and time, as otherwise it works well as a basic MySQL php query.

4
  • add error_reporting(E_ALL) to the top. your errors are off by default. Commented Mar 18, 2013 at 17:29
  • 2
    learn how to to use echo, read documentation Commented Mar 18, 2013 at 17:30
  • do a var_dump($info]); and you will see what is wrong Commented Mar 18, 2013 at 17:30
  • DOTS: echo "<td>".date("d M Y",strtotime($info['registered']))."</td>"; Commented Mar 18, 2013 at 17:31

2 Answers 2

2

it should be like this

echo "<td>".date("d M Y",strtotime($info['registered']))."</td> ";

You have to use . for concantinate string.

Sign up to request clarification or add additional context in comments.

1 Comment

he also has "<tr>"; without echo, you might want to point that too
0

First off, the reason your screen is blank, is because most default PHP installs have error reporting turned off. You'll need to edit your php.ini file to fix that. Open and search for display_errors and change it.

Second, the first error you're missing is you just have "<tr>" with no echo before it.

The second error you're most likely not seeing is that you're missing a concatenating operator .

echo "<td>"date("d M Y",strtotime($info['registered']));"</td> "

should be

echo "<td>" . date("d M Y",strtotime($info['registered'])) . "</td> "

2 Comments

error_reporting() would not work here, as he would need to have display_errors enabled. Also, you could not set it at runtime, as this was a parse error.
Good call, changed to have OP look for that in his php.ini

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.