Jump to content

select month from date


piheshpi90

Recommended Posts

i thought it will represent the value i insert in the form

 

$colname_Recordset3 = "-1";
if (isset($_POST['s'])) {
  $colname_Recordset3 = (get_magic_quotes_gpc()) ? $_POST['s'] : addslashes($_POST['s']);
}

$query_Recordset3 =sprintf( "SELECT * FROM aktiviti WHERE month(`date_n`) = s ", $colname_Recordset3);

 

i try SELECT * FROM aktiviti WHERE MONTH(`date_n`) = 9 and it work.but when i change it to s, it doesnt.

error say--> Unknown column 's' in 'where clause'.

 

 

Link to comment
Share on other sites

That whole thing is a bit off. Since $_POST['s'] is being used to retrieve the month, and it's numeric, you should be validating it and casting it as an integer. Then in the sprintf(), you can use %d, since the value is expected to be an intger.

 

if( isset($_POST['s']) && ctype_digit($_POST['s']) ) {
     $colname_Recordset3 = (int) $_POST['s'];
} else {
     // you can trigger an error, set a default value, etc here if needed.
}

$query_Recordset3 =sprintf( "SELECT * FROM aktiviti WHERE month(`date_n`) = %d ", $colname_Recordset3);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.