Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Date/Calendar functions and parameterized queries help needed.

  1. #1
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Date/Calendar functions and parameterized queries help needed.

    Are mysqli functions disabled by default in the php configurations for new hosting account users?

    I have been banging my head over the past 2 days, trying to get parameterized queries to work on my website for an insert statement, but it keeps giving me error messages. I have searched online for a solution high and low, but the only ones I can find for the specific error message that I recieve is that they ask to check the query itself or the connection string, both of which in my case have been checked thoroughly, and work absolutely fine in other areas of the site that don't work on parameterized queries.
    And they also ask to check the syntax, which again, has been tripple checked by me, but it still throws the error.


    Secondly, in the same insert statement, I need to post user comments on the same webpage, using a form at the bottom of the page. The form will collect data like the user's name, email, and the comment text, and will pass this data along with a timestamp to the backend database. Now I am located in the Indian Standard Time timezone, whereas the server I'm on (cossacks), is somewhere in the United States. And I'm a total noob where converting dates/time across timezones is concerned, even in the offline world.
    Could someone please help me with a script/function that gets the exact datetime on the cossacks server at the moment when the user hits the submit button, then converts it to my local time (IST), and submits that converted datetime to the backend db, at the same time also accounting for daylight savings if any? Or are there any built-in scripts/functions in php that already do this that I am unaware of?

  2. #2
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: Date/Calendar functions and parameterized queries help needed.

    Please post the error message to check what could be the problem
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  3. #3
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Date/Calendar functions and parameterized queries help needed.

    These are the error messages I am getting -

    Fatal error: Call to a member function bind_param() on a non-object in /home/[domain]/public_html/[webpage].php on line 194

    Fatal error: Function name must be a string in /home/[domain]/public_html/[webpage].php on line 193

    Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage].php on line 15

    Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage].php on line 24

    Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage].php on line 26

    Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage].php on line 28



    Edit: Oh, BTW, I forgot to mention, I still get these error messages, despite having just upgraded my php version to 2 on x10.



    Edit2:
    I don't seem to be getting any response here, am I in the wrong section?
    Last edited by parkourmumbai; 10-09-2008 at 02:12 AM. Reason: Automerged Doublepost

  4. #4
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: Date/Calendar functions and parameterized queries help needed.

    Quote Originally Posted by parkourmumbai View Post
    Are mysqli functions disabled by default in the php configurations for new hosting account users?
    I believe you have to upgrade your php to intermediate to do that. I got mine working on intermediate level.

    http://x10hosting.com/account

    check here and login with your forum account.

  5. #5
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Date/Calendar functions and parameterized queries help needed.

    Dude, I've already mentioned above that I've done that, upgraded to intermediate php (ver 2). But parameterized queries still won't work on my website. :dunno:

  6. #6
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: Date/Calendar functions and parameterized queries help needed.

    Why didn't you ever try to post the part of the code here? How can people help if they don't know where the problem comes from.. it says boolean given means that it probably is returning false, and <this is not an object>->bind_param() is what it's saying...

    if you want to know if mysqli is disabled in your account type and save <?php phpinfo(); ?> and run it, if you see it there, then mysqli is not the problem
    Last edited by natsuki; 10-09-2008 at 09:33 AM.

  7. #7
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: Date/Calendar functions and parameterized queries help needed.

    The following error clearly shows a coding error:

    Fatal error: Function name must be a string in /home/[domain]/public_html/[webpage].php on line 193

    Show us the source and we may be able to help a little more.
    - When in doubt, refer to the PHP manual.

  8. #8
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Date/Calendar functions and parameterized queries help needed.

    I've checked phpinfo(), and mysqli is enabled on my account.


    Allright, the code I'm using is the same as is mentioned in the online php manual on the php website, on a test page on my website.
    But it still gives me a variation of those above mentioned error messages, based on whether I'm using the procedural style or the object-oriented style for coding the parameterized query.

    PHP Code:
    <?php
    $mysqli 
    = new mysqli('localhost''username''password''databasename');
    /* check connection */
    if (mysqli_connect_errno()) {
        
    printf("Connect failed: %s\n"mysqli_connect_error());
        exit();
    }
    $stmt $mysqli->prepare("Insert Into Table (Date, Name, Email, VisitorIp, Text, Field6) Values (?, ?, ?, ?, ?, ?)");
    $stmt->bind_param('sssssi'$Date$Name$Email$VisitorIP$Text$Field6);
     
    $Date "1998-7-3";
    $Name "John Cusack";
    $Email "123@email.com";
    $VisitorIP "192.168.1.1";
    $Text "Test Data. Test Data.";
    $Field6 1;
     
    /* execute prepared statement */
    $stmt->execute();
    printf("%d Row inserted.\n"$stmt->affected_rows);
    /* close statement and connection */
    $stmt->close();
    /* close connection */
    $mysqli->close();
    ?>
    (Some variables have been changed for security purposes, but I can attest that in the actual code they are accurately supplied)

    This code throws the following error message -
    Fatal error: Call to a member function bind_param() on a non-object in /home/[domain]/public_html/[webpage] on line n




    Okay, here is the same code as above, but this time using procedural style, as opposed to the object-oriented style above.

    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost''username''password''databasename');
    /* check connection */
    if (!$link) {
        
    printf("Connect failed: %s\n"mysqli_connect_error());
        exit();
    }
    $stmt mysqli_prepare($link"Insert Into Table (Date, Name, Email, VisitorIP, Text, Field6) Values (?, ?, ?, ?, ?, ?)");
    mysqli_stmt_bind_param($stmt'sssssi'$Date$Name$Email$VisitorIP$Text$Field6);
    $Date "1998-7-3";
    $Name "John Cusack";
    $Email "123@email.com";
    $VisitorIP "192.168.1.1";
    $Text "Test Data. Test Data.";
    $Field6 1;
     
    /* execute prepared statement */
    mysqli_stmt_execute($stmt);
    printf("%d Row inserted.\n"mysqli_stmt_affected_rows($stmt));
    /* close statement and connection */
    mysqli_stmt_close($stmt);
    /* close connection */
    mysqli_close($link);
    ?>
    Again, some details have been obscured for security purposes.

    And these are the error messages I get this time 'round -
    Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n

    Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n

    Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n
    0 Row inserted.
    Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n



    And this is the page on the php website where I got the proforma code -
    http://us2.php.net/manual/en/mysqli-stmt.bind-param.php
    Last edited by parkourmumbai; 10-10-2008 at 04:05 AM. Reason: Automerged Doublepost

  9. #9
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: Date/Calendar functions and parameterized queries help needed.

    this means the problem is originating from $stmt = $mysqli->prepare(blah); or $stmt = mysqli_prepare(blah); gotta try it first to check

    EDIT: your bind_params work a treat, I tested it without touching your params

    you just have either some syntax or table related errors in your prepare statement. If you really have a Date column in your table then that makes it ambiguous. Put backticks (`) on columns which resemble SQL reserved words: `Date` instead of Date or better yet, put backticks on them all to be safe.
    or put this:
    PHP Code:
    $stmt $mysqli->prepare("Insert Into `blah` (`blah`,....) Values (?, ?, ?, ?, ?, ?)");
    if (
    $mysqli->errno)
    {
        die(
    $mysqli->error);

    Last edited by natsuki; 10-11-2008 at 04:21 AM.

  10. #10
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Date/Calendar functions and parameterized queries help needed.

    'Hell no, I never use any sql or php reserved words, I know that would be programming suicide. The actual field and variable where I've used Date actually is in camelcase notation and reads something like tablenameDate or $tablenameDate, I've just obscured it over here.

    Even my prepare statements are exactly the way they're supplied here, except for my changing the names altogether like tablenameDate to simply Date.

Closed Thread
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers