WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Exec-PHP day reads problem! (4 posts)

  1. Attila
    Member
    Posted 1 year ago #

    Hi Everyone!

    I have a short PHP code which is dosen't work under WordPress Exec-PHP.

    $day = $_GET['day'];
    $date = (string)$day;
    $query = "SELECT * FROM date_".$date;

    I think the problem is in the first line, but I don't have any idea what is the solution. The expected result is something this:

    SELECT * FROM date_130131

    Have you any idea?

    Thanks,
    Attila

  2. catacaustic
    Member
    Posted 1 year ago #

    You can do that all in one line:

    $query = "SELECT * FROM date_".mysql_real_escape_string ($_GET ["day"])

    But... I don't know if that's going to get what you want. Do you really have a separate DB table for every day that you are going to query (in your example the table name is 'date_130131')? If so that sounds like it's a really bad way to do it.

    Also, look at what I've done, and take a lot of notice of the mysql_real_escape_string() function. You must use this any time you are going to use any SQL query that you are going to run. I cannot stress this enough. without it you are leaving yourself open to SQL injection and risk having your whole DB either compromised or wiped out.

  3. Attila
    Member
    Posted 1 year ago #

    I know it is a strange solution, but my basic problem is the $day = $_GET['day']; have a result if i call the PHP directly in the browser. But if I run the same program in Exec-PHP inside a WordPress based page it has no result. And I don't know why?

  4. Attila
    Member
    Posted 1 year ago #

    $day = date(ymd);
    $date = (string)$day;
    $query = "SELECT * FROM date_".$date;

    I found the answer. It was my fault. :)
    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags