• Resolved thenorth

    (@thenorth)


    Can someone please help me with this. Once the Submit button is pressed
    the page shows

    select Date_Format(Start_Date,’%d-%b-%Y’) As Start_Date,Day,No_Of_Nights,CONCAT(‘£’, FORMAT(cost, 2)) as Cost ,Status,PageLink from web152-thenorth.Dukes3 WHERE concatc = ‘August 2015’ ORDER BY Start_Date

    Instead of showing a table of results. Any help would be greatly appreciated. Thank you.

    <h1>Booking Information For No 3 Dukes Cottage</h1>
    
    <form method="post" action="http://dukescottages.com/Newsite/phppage/">
    <input type="hidden" name="submitted" value="true"/>
    
    <label>Search Month to See Availability Details and Prices:
    
    <select name="Category" id="Catergory">
    
    <option>Please Choose Month</option>
    <option>January 2015</option>
    <option>February 2015</option>
    <option>March 2015</option>
    <option>April 2015</option>
    <option>May 2015</option>
    <option>June 2015</option>
    <option>July 2015</option>
    <option>August 2015</option>
    <option>September 2015</option>
    <option>October 2015</option>
    <option>November 2015</option>
    <option>December 2015</option>
    <option>January 2016</option>
    </select>
    </label>
    <input type="submit"/>
    </form>
    
    [insert_php]
    
    if (isset($_POST['submitted'])) {
    
    include('ftp://dukescottages.com/Newsite/wp-content/themes/theretailer/Connection.php');
    
    $Category = $_POST['Category'];
    $criteria= $_POST['criteria'];
    $query = "select Date_Format(Start_Date,'%d-%b-%Y') As Start_Date,Day,No_Of_Nights,CONCAT('&pound;', FORMAT(cost, 2)) as Cost ,Status,PageLink from <code>web152-thenorth</code>.Dukes3 WHERE concatc = '$Category' ORDER BY Start_Date";
    $result = mysqli_query($dbcon, $query) or die($query);
    echo "<table>";
    echo "<tr>
    <th>
    Arrival
    </th>
    <th>
    Arr Day
    </th>
    <th>
    No Nights
    </th>
    <th>
    Cost
    </th>
    <th>
    Status
    </th>
    <th>
    Link
    </th>
    </tr>";
    
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    
    echo "<tr><td>";
    echo $row['Start_Date'];
    echo "</td><td>";
    echo $row['Day'];
    echo "</td><td>";
    echo $row['No_Of_Nights'];
    echo "</td><td>";
    echo $row['Cost'];
    echo "</td><td>";
    echo $row['Status'];
    echo "</td><td>";
    echo $row['PageLink'];
    echo "</td></tr>";
    }
    
    echo "</table>";
    
    } // end of If Statement
    
    [/insert_php]

    https://ww.wp.xz.cn/plugins/insert-php/

Viewing 10 replies - 1 through 10 (of 10 total)
  • This is a forum for Insert PHP issues rather than for debugging code.

    Be that as it may, I think the mysqli_query() function is returning false and the
    “or die($query)”
    part of the line is kicking in. It would print the $query value and the PHP script would quit right there.

    Putting your code into a stand-along web page for debugging could help. Temporarily replace [insert_php] and [/insert_php] with <?php and ?> for testing the stand-alone page.

    Will

    Thread Starter thenorth

    (@thenorth)

    Hi thanks Will, the code runs fine on HERE
    with the <?php and ?>
    so I’m not sure why it doesn’t work, except for perhaps the “action=” part. In the old code the page was a PHP page, does this matter in WordPress or is their a way around it?

    Thanks again for the help.

    Noel.

    Noel,

    Put this into a new web page. Name it test.php and upload it to the subdirectory where WordPress is installed.

    <!doctype html>
    <html>
    <body>
    
    <h1>Booking Information For No 3 Dukes Cottage</h1>
    
    <form method="post" action="http://dukescottages.com/Newsite/phppage/">
    <input type="hidden" name="submitted" value="true"/>
    
    <label>Search Month to See Availability Details and Prices:
    
    <select name="Category" id="Catergory">
    
    <option>Please Choose Month</option>
    <option>January 2015</option>
    <option>February 2015</option>
    <option>March 2015</option>
    <option>April 2015</option>
    <option>May 2015</option>
    <option>June 2015</option>
    <option>July 2015</option>
    <option>August 2015</option>
    <option>September 2015</option>
    <option>October 2015</option>
    <option>November 2015</option>
    <option>December 2015</option>
    <option>January 2016</option>
    </select>
    </label>
    <input type="submit"/>
    </form>
    
    <?php
    
    if (isset($_POST['submitted'])) {
    
    include('ftp://dukescottages.com/Newsite/wp-content/themes/theretailer/Connection.php');
    
    $Category = $_POST['Category'];
    $criteria= $_POST['criteria'];
    $query = "select Date_Format(Start_Date,'%d-%b-%Y') As Start_Date,Day,No_Of_Nights,CONCAT('&pound;', FORMAT(cost, 2)) as Cost ,Status,PageLink from <code>web152-thenorth</code>.Dukes3 WHERE concatc = '$Category' ORDER BY Start_Date";
    $result = mysqli_query($dbcon, $query) or die($query);
    echo "<table>";
    echo "<tr>
    <th>
    Arrival
    </th>
    <th>
    Arr Day
    </th>
    <th>
    No Nights
    </th>
    <th>
    Cost
    </th>
    <th>
    Status
    </th>
    <th>
    Link
    </th>
    </tr>";
    
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    
    echo "<tr><td>";
    echo $row['Start_Date'];
    echo "</td><td>";
    echo $row['Day'];
    echo "</td><td>";
    echo $row['No_Of_Nights'];
    echo "</td><td>";
    echo $row['Cost'];
    echo "</td><td>";
    echo $row['Status'];
    echo "</td><td>";
    echo $row['PageLink'];
    echo "</td></tr>";
    }
    
    echo "</table>";
    
    } // end of If Statement
    
    ?>
    
    </body>
    </html>

    Load the page into your browser.

    Let me know how it goes.

    Will

    Thread Starter thenorth

    (@thenorth)

    Hi Will,

    Tried it and still doesn’t seem to want to work. I changed the Action call and the Include for the connection but it returns the SQL Text on the web page

    “select Date_Format(Start_Date,’%d-%b-%Y’) As Start_Date,Day,No_Of_Nights,CONCAT(‘£’, FORMAT(cost, 2)) as Cost ,Status,PageLink from web152-thenorth.Dukes3 WHERE concatc = ‘August 2015’ ORDER BY Start_Date”

    Bizarre. Are database connects or SQL declared differently inside wordpress?

    Appreciate the help.

    Noel

    Yes, it’s die-ing on the the mysqli_query() function.

    I don’t know what
    ftp://dukescottages.com/Newsite/wp-content/themes/theretailer/Connection.php
    contains. But it should contain the variable $dbcon with a valid MySQLi handle. Maybe test Connection.php and see if the issue is in there.

    I think MySQLi is used the same within WordPress as it is outside WordPress.

    Will

    Thread Starter thenorth

    (@thenorth)

    It does Will, see below. Connection is fine (as when it’s not it throws the Error Oh Oh Oh out).
    I’ve even tried bringing the dbcon into the page, but it does not change the outcome

    <?php

    DEFINE (‘DB_USER’, ‘XXXXX’);
    DEFINE (‘DB_PSWD’, ‘XXX’);
    DEFINE (‘DB_HOST’, ‘localhost’);
    DEFINE (‘DB_NAME’, ‘XXXXXX’);

    $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME);

    If (!$dbcon){
    die(‘Error oh oh oh’);
    }

    ?>

    Noel.

    Cool.

    Now that we know it does work with the connection hard coded between the [insert_php]…[/insert_php] tags, it’s nearly certain the include() isn’t working. Try changing “ftp://&#8221; to “http://&#8221;.

    If still no joy, the code in Connection.php can be inserted between the [insert_php]…[/insert_php] tags with the rest of the code instead of being included.

    Will

    Thread Starter thenorth

    (@thenorth)

    Hi Will made some progress with this. It was the PHP Version, so when updated, the coded worked in the Test.php page no problem, however it does not work inside a WordPress. I’ve done some research which seems to suggest you can’t use the Array MSQLI_ASSOC in wordpress and that I have to use WPDB.

    However it now seems that using WPDB in WordPress doesn’t like the DB declaration in the SQL Query, specifically it seems it can’t handle the dash in my dbname web152-thenorth.Dukes3 and it sees the DB as thenorth.Dukes3.

    Not sure what to do now!

    Thread Starter thenorth

    (@thenorth)

    Breakthrough – Page HERE

    I’ve declared the Db Name & Table as $dukdb = (web152-thenorth.Dukes3); and used WHERE $dukdb in the Query.

    I’m using

    $mydb = new wpdb(‘XX’,’XX’,XX’,’localhost’);
    $query = $mydb->get_results($sql2, ARRAY_A) or die(mysql_error());
    Instead of MSQLI_ASSOC

    And instead of using While I now use foreach($query as $row) {
    and it all works with the [insert_php].

    This has been one head scratcher but solved with the help of some of your prompts Will. Thank you very much, hope this helps someone else in the future.

    Thanks again
    Noel.

    You’re welcome and I’m glad you got it working.

    Will

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘My Code doesn't work’ is closed to new replies.