Jump to content

Johnain

Members
  • Posts

    64
  • Joined

  • Last visited

Everything posted by Johnain

  1. Yikes cracked it - after 6 hours. Yippee. The solution (simple as always) was ... function calcdate($indate, $noofdays) { // calculates a number of days from the supplied date, plus (no sign needed) or minus (give - sign in $noofdays // Assumes that indate is yyyy-mm-dd and the outdate will be in the same format. $date = strtotime(date("Y-m-d", strtotime($indate)) . " +".$noofdays ." day"); return date("Y-m-d", $date) ; }
  2. Hi all I am constantly baffled by the unbelievable difficulty of carrying out simple date manipulations in PHP. I have just spent around six hours trying to add a day to a date and I still do not have the answer. I have a date stored in a date filed in my MySQL database in the format YYYY-DD-MM. All I want to do is retrieve it, add a day to it and display it in an HTML form as DD-MM-YYYY. I already have a function that will reverse it to DD-MM-YYYY for display and another that will reverse it back to my YYYY-MM-DD format when I wish to write it back to the database, so it's just adding a day (or two days, or any other number of days) that I need to do. But the apparently simple task of adding one (or more) days to it has proved beyond me. I have scoured the web and seen almost every solution known to mankind. Most of them incredibly complex. It must be me being an idiot. Can anybody help, please. My latest attemp is this ... function calcdate($indate, $noofdays) { // calculates a number of days from the supplied date, plus (no sign needed) or minus (give - sign in $noofdays // Assumes that indate is yyyy-mm-dd and the outdate will be in the same format. $date = strtotime(date("Y-m-d", strtotime($indate)) . " +".$noofdays ." day"); return $date ; } But it returns a number !
  3. Thanks for that. In the end I came to much the same conclusion and what I now do is simply load up one array with the values that I want and another array with the IDs that I want so that when (much later in the script) I want to use them in an SQL update I simply lookup the two arrays. In fact it's an excellent example of using experience of what's easy in one language and trying to apply it in another without thinking it through properly. So I need to be more careful next time. But a big word of thanks to those who helped me.
  4. Ok, I replaced my original eval with eval($varval) ; But I got Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/q07peri/public_html/admin/mdprodcodeedit.php(102) : eval()'d code on line 1 I made no changes to $varval itself
  5. Ok, echo comes up with $varval = "$1_saleprice = $_POST['1_saleprice']"; If I was writing the line of code I would write ... $1_saleprice = $_POST['1_saleprice'] ; So it looks about right to me. It looks as though I have not grasped eval() properly.
  6. Hi All I have never used eval() before to generate and execute php code. The code that I am trying to generate is a varying number of rows that should say (and execute) ... $incomingvariable = $_POST['incomingvariable'] ; ... where the incoming variable will be 1_saleprice to (for example ) 10_saleprice when $pricecount (see below) has a value of 10 The variable $pricecount has a value of 8 with the data I am using and it IS passed correctly (I use EngInSite debugger so I know that). I am using a for loop. The variable that holds the number of incoming records is called $pricecount. It reads like this ... 93 for ($z = 1; $z <= $pricecount; $z += 1) 94 { 95 $y = trim($z) ; 96 97 $varval = "$" . $y . "_saleprice = $" . "_POST['" . $y . "_saleprice'] ;" ; 98 99 eval("\$varval = \"$varval\";"); 100 } You will see that I have put the terminating executing code semi-colon into the variable $varval in this example and I still get an error with or without it. (I split the $ and the _POST because otherwise it reads it directly as $_POST[') The error WITH the semi colon is ... Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/q07peri/public_html/admin/mdprodcodeedit.php(99) : eval()'d code on line 1 The error WITHOUT the closing semi-colon is exactly the same.
  7. I have got a function that the EnginSite Editor/Debugger is failing on a given line. I cannot for the life of me work out why, and the debugger has decided that is not going to accept breakpoints today (no idea why, it did yesterday). It has also decided that it's too tired to evaluate statements or to give values on watchpoints, poor labm ! There is no help to be got at EngInSite, they are not answering e-mails at the support desk. This is the function .... function getgentext($textref, $langue, $text) { // $textref is the reference of the text - NOT the row id in the table // $sessionlangue is the language // $text is to identify which text is returned // 1 = long text // 2 = medium text // 3 = short text // 4 = Column header text $sql = "SELECT * FROM peri_othertexts where textref = $textref and langue = $langue ; $result = mysql_query($sql) or die('SQL Query failed ... ' . mysql_error()); $num_rows = mysql_num_rows($result); $rowcontent = mysql_fetch_row($result) switch($num_rows) { case 0 : switch($langue) { case 'FR' : $retval = 'Texte non disponible'; break; case 'EN' : $retval = 'Text not available'; break; default : $retval = 'Text not available'; } default: switch($text) { case 1: $retval = $rowcontent['textlong'] ; break; case 2: $retval = $rowcontent['textmed'] ; break; case 3: $retval = $rowcontent['textshort'] ; break; case 4: $retval = $rowcontent['textcolhead'] ; break; default: $retval = $rowcontent['textlong'] ; break; } } return $retval ; } The highlighted line is the one that gets this message Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\htdocs\perigordirect\includes\db_lib.php on line 45 PHP Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\htdocs\perigordirect\includes\db_lib.php on line 45 But clearly there is a record found, or else it would have taken case 1 of the $num_rows switch. I have checked and there is data there. Cheers John
  8. Thanks Haku, I really appreciate that. By the way, in case you are wondering whether I feel a complete plonker, the answer is yes. I do. Talk about the obvious. But thanks again
  9. Hi I am using XHTML (T). I am successfully retrieveing data from a MySQL database field of type Text. I want to show it in a form so a user can edit it and then I can save it back to my table. However I can only see two tab types that might be relevant. 1. <input> that lets me assign an initial value but will not allow me to specify columns or rows. 2. <textbox> That will give me rows, columns and scrolling - but will not let me assign an initial value. Am I missing something? Is there a simple solution? Regards John
  10. That is really good. Thanks. As you say, it may not do it all. But it is a good looking solution. Thanks
  11. Hi all I am building my first PHP display and update form, and so far it runs like a dream (tp my amazement). However I am taking my time with this because I want it to be a "standard form" ... almost a class, for future forms of the same type. Basically, it does this. 1 Selects all data from a MySQL table, sticks it in a table for on-screen display and then shows it. Scrollbars, locked columns on the left , alternate colours on rows and other magic. Now I want to offer the user the opportunity to redisplay the form with filters and sort orders initiated by on-screen buttons. I tried onclick, but it will not go to my PHP function. Do I have to set up a "mini form" for each button and redisplay the whole page with the newly sorted and filtered data, or is there something I am missing? John
  12. You are right Adam. I thoght I had grasped it, but clearly I have not. I will take your advice. Regards and thanks John
  13. Oh, then I have really misunderstood. How then can I make a variable used in one form useable in another within the same session? Do I have to write it to a table? Regrds John
  14. $_SESSION['stepno'] = $stepno; I understood that this would add it to the session variables and that normal chages to the values of ordinary $ variables would be used to update it session wide. Is that not correct? Regrds John
  15. I want $stepno to equal 2. I do not want to change the session number. My understanding is that I have defined $stepno as session wide, so that if I alter its value in one HTML/PHP doc, it will be valid within other HTML/PHP docs within the same session. regards John
  16. I have a script where I logon, kick off a session, and set session variables ... session_start(); ================= lots of code ================ $_SESSION['username'] = $_POST['uname']; $_SESSION['password'] = $_POST['passwd']; $_SESSION['stepno'] = $stepno; // Set stepno This then lets me get to another script where I start a session and then set $stepno to 1, which works and is used later in the script successfully. Later I try to update $stepno. I put my own version of a debug into it. The script says ... session_start(); ================= lots of code ================ echo("<p>Step ".$stepno."</p><br />"); echo(print_r($_SESSION)); $stepno = 2; echo(print_r($_SESSION)); Array ( [username] => johnain [password] => b9f70cbb473c65c19063cc40e14be4c4 [stepno] => ) 1 Array ( [username] => johnain [password] => b9f70cbb473c65c19063cc40e14be4c4 [stepno] => ) 1 I have two questions 1. Why is the value of 1 (which is the correct value in the first print_r) outside the closing array bracket? 2. Why is the change of $stepno from 1 to 2 ignored so that the second print_r still shows a value of 1? Is there some setting I have not made? Regards John
  17. Hi Guys I finally worked it out with your help. My basic error was forgetting that I was constructing a string containing an SQL statment, not the statement itself! The solution is ... $qry = "SELECT * FROM users WHERE username = "."'".$uname."'"; I hope I do not do anything as daft again ... but I bet I do Regards to you all and thanks for all of your help. John
  18. Hi Ken Thanks for that, but it hasn't fixed the problem. I am going to work line by line though this and see if I can spot the problem. Thanks for your help Regards John
  19. sorry, just to be clear, it is these statments that I have the problem with ... case 2: // Start step 2. User details maintenance. if (!get_magic_quotes_gpc()) { $_POST['uname'] = addslashes($_POST['uname']); } ?> <br /><h4>User maintenance - Maintain user details for ...<br /> <?echo($uname) ?></h4> <? $qry = "SELECT * FROM users WHERE username = '$uname'"; //$qry = "SELECT username, password FROM users WHERE username = '".$_POST['uname']."'"; $check = $db_object->query($qry); if (DB::isError($check) || $check->numRows() == 0) { die("That username (".$uname.") does not exist in our database."); } break; The select will find my record when I use a constant for the key, but not when I use $uname. Regards John
  20. Hi Ken You will find the code in reply 3 above. Regards John
  21. Are there any hidden characters in a record retrieved from a table? Is the field length a consideration? Sorry to ask such basic questions, but I am a newcomer ! Regards John
  22. that is right, I realised that just after I posted, but I put it in anyway. I changed to <form method="post" action="../scripts/changeuser.php"> ... and it refinds the form (as it did before) but still comes back saying ... "That username ( JohnAin ) does not exist in our database." Which of course is not the case since a select using the constant "JohnAin" does find and retrieve the record. Regards John
  23. Oh no. How embarrassing! I will Thanks and regards John
  24. Hi I changed line 111/112 to read if (DB::isError($check) || $check->numRows() == 0) { die("That username (".$uname.") does not exist in our database."); and the darned thing echoed out ok for me there too. it read JohnAin which is exactly the constant I used to get a successful retrieval. Phew !!! Regrds John
×
×
  • 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.