Jump to content

Recommended Posts

I have a silly problem in PHP im trying to move a date filled in on a form into mysql.

 

My problem is in getting php not to mess up my date  :(

 

Here is where it goes wrong:

$date = $_POST['date']

 

The post value contains a date in this format YYYY-MM-DD

 

and whenever i do the above transfer it subtracts the months and the days from the year

 

help

Link to comment
https://forums.phpfreaks.com/topic/141976-silly-problem/
Share on other sites

try

 

$date = (string) $_POST['date'];

 

it continues to subtract

 

Then there is something up with your form or your server. Anything coming in from an html form or get/post data should be stored as a string and not acted on literally.

 

Post the form code for us and more of the page where that is happening; Something else is going on.

Link to comment
https://forums.phpfreaks.com/topic/141976-silly-problem/#findComment-743391
Share on other sites

The naming in this is all shortend from dutch but you should be able to make out where i send and get the values from.

I highlighted the date related parts in red.

The get values have no effect ive changed the value completely without any change to the outcome.

The server im running this on is Local XAMPP default install no changes made.

 

Form:

 

$snr = $_GET['snr'];

$soknr = $_GET['son'];

$thnr = $_GET['t'];

$kwart = $_GET['k'];

$goedk = $_GET['g'];

$score = $_GET['s'];

$datbeh = $_GET['d'];

$ec = $_GET['e'];

 

if ($goedk == -1) {

$a = SELECTED;

}

else {

$b = SELECTED;

}

 

echo "

<form method=post action=func_edit_sok.php>

<table class=tabel1>

<input type=hidden name=snr value=$snr>

<tr>

<td>SOK NR</td><td><input READONLY type=text class=input3 name=sok value=$soknr></td>

</tr>

<tr>

<td>Thema NR</td><td><input READONLY type=text class=input3 name=thema value=$thnr></td>

</tr>

<tr>

<td>Kwartaal NR</td><td><input type=text class=input2 name=kwart value=$kwart></td>

</tr>

<tr>

<td>Goekgekeurd</td><td><select name=goedk>

<option value=-1 $a>Ja</option>

<option value=0 $b>Nee</option>

</select></td>

</tr>

<tr>

<td>Score</td><td><input type=text class=input2 name=score value=$score></td>

</tr>

<tr>

<td>Datum behaald</td><td><input type=text class=input2 name=dat value=$datbeh> (JJJJ-MM-DD)</td>

</tr>

<tr>

<td>EC</td><td><input type=text class=input2 name=ec value=$ec></td>

</tr>

<tr>

<td><a href=javascript:history.back(-1)>Terug</a></td><td><input type=submit value=Opslaan class=button1></td>

</tr>

</table>

</form>";

 

Handler:

 

include "dbcon.php";

 

if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {

//toekennen waardes voor controle gemak + html php tags verwijderen.

$goedgk = $_POST['goedk'];

$score = $_POST['kwart'];

$snr = $_POST['snr'];

$datbeh = (string) $_POST['dat'];

$ec = $_POST['ec'];

$thema = $_POST['thema'];

$kwart = $_POST['kwart'];

$klopt = 0;

$sok = $_POST['sok'];

 

$res = mysql_query("SELECT * FROM thema WHERE themanr=$thema");

$rel = mysql_fetch_array($res);

 

if($rel['1ekwartgegeven'] == -1 && $kwart == 1){

$klopt = 1;

}

elseif($rel['2ekwartgegeven'] == -1 && $kwart == 2){

$klopt = 1;

}

elseif($rel['3ekwartgegeven'] == -1 && $kwart == 3){

$klopt = 1;

}

elseif($rel['4ekwartgegeven'] == -1 && $kwart == 4){

$klopt = 1;

}

else {

echo "Dit thema is niet beschikbaar in kwartaal $kwart de wijziging van het kwartaal kan niet worden doorgevoerd drup op Terug<br />";

echo "<a href=javascript:history.back(-1)>Terug</a>";

}

 

if($klopt == 1){

mysql_query("UPDATE SOK SET Kwartaalnr=$kwart, Goedgekeurd=$goedgk, Score=$score, DatumBehaald=$datbeh, EC=$ec

WHERE SOKnr=$sok") or die (mysql_error());

header("Location: index.php?page=ov_s&snr=$snr");

}

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/141976-silly-problem/#findComment-743400
Share on other sites

I would use quotes in your html around the attributes.

 

<td>Datum behaald</td><td><input type='text' class='input2' name='dat' value='$datbeh'> (JJJJ-MM-DD)</td>

 

Try that out and see if that maybe works. I am still unsure on why it would be subtracting each other, if that does not work try to change this part also:

 

$datbeh = (string)$_GET['d'];

 

And see if that works or not. Also you should really use single quotes around your mysql data.

 

mysql_query("UPDATE SOK SET Kwartaalnr='$kwart', Goedgekeurd='$goedgk', Score='$score', DatumBehaald='$datbeh', EC='$ec'
WHERE SOKnr='$sok'") or die (mysql_error());

 

Give those a try and see if that fixes the issue.

Link to comment
https://forums.phpfreaks.com/topic/141976-silly-problem/#findComment-743407
Share on other sites

I would use quotes in your html around the attributes.

 

<td>Datum behaald</td><td><input type='text' class='input2' name='dat' value='$datbeh'> (JJJJ-MM-DD)</td>

 

Try that out and see if that maybe works. I am still unsure on why it would be subtracting each other, if that does not work try to change this part also:

 

$datbeh = (string)$_GET['d'];

 

And see if that works or not. Also you should really use single quotes around your mysql data.

 

mysql_query("UPDATE SOK SET Kwartaalnr='$kwart', Goedgekeurd='$goedgk', Score='$score', DatumBehaald='$datbeh', EC='$ec'
WHERE SOKnr='$sok'") or die (mysql_error());

 

Give those a try and see if that fixes the issue.

 

doesnt change anything.

 

I changed the form to a GET form and the values all get sent correctly in the URL &dat=2009-11-11

 

but when they get moved over from the GET to the normal variable it treats it like calculation and makes it 1987

Link to comment
https://forums.phpfreaks.com/topic/141976-silly-problem/#findComment-743427
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.