-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
So you want to remove any bold tags that are within the highlighted string?
-
Why my search engine Goes wrong Everytime I have User Logged In
Ch0cu3r replied to ava5193's topic in PHP Coding Help
Your query is most probably returning an error. Check that they query has executed ok before getting the results $query = mysql_query($query); //Execute the query $query // when mysql returns an error, mysql_query will return false if(!$query) { // output the error from query trigger_error('Query has failed: ' . mysql_error()); } -
you may have tried the original code which had an error. Try my example again it does get the date and time from $filename. The following code will read any file that starts with cells_ and ends in a csv file extension grabbing the date & time from the filename foreach (glob("cells_*.csv") as $filename) { list(, $date, $time) = explode('_', substr($filename, 0, -4)); $date = substr($date, 0, 4) . '/' . substr($date, 4, 2) . '/' . substr($date, 6, 2); $time = substr($time, 0, 2) . ':' . substr($time, 2, 2) . ':' . substr($time, 4, 2); echo "The datetime for $filename is $date at $time<br />"; }
-
If you already have the filename and want to get the date/time value from it you could do $filename = "cells_20140106_165532.csv"; list(, $date, $time) = explode('_', substr($filename, 0, -4)); $date = substr($date, 0, 4) . '/' . substr($date, 4, 2) . '/' . substr($date, 6, 2); $time = substr($time, 0, 2) . ':' . substr($time, 2, 2) . ':' . substr($time, 4, 2); echo "The file was create on $date at $time";
-
I do not see how you can convert multiple conditions into an array. Can you explain what you are wanting to do.
-
Try <?php $datei = $_POST["tanggal"]; $day_number = $_POST["hari_ke"]; $shift_start = $_POST["shift_mulai"]; $shift_1dan2 = isset($_POST["shiftAlt"]) ? true : false; $pattern_shift = $_POST["pola_shift"]; if ($pattern_shift == 1) { $hpattern = 7; } else { $hpattern = 14; } $shiftStart = array( 1, // first shift value 2 // secound shift value ); if($shift_start == 2) $shiftStart = array_reverse($shiftStart); // reverse the shift values date_default_timezone_set('UTC'); $hasil = explode("-", $datei); $d1=$hasil[2]; // day $m1=$hasil[1]; // month $y1=$hasil[0]; $num = cal_days_in_month(CAL_GREGORIAN, $m1, $y1); $d2 = $num; // array for lembur sequane $seq['lembur'] = array(); $seq['lembur'][0] = $day_number; // array for kerja sequance $seq['kerja'] = array(); $seq['kerja'][0] = $day_number; //$seq['kerja2'] = array(); //$seq['kerja2'][0] = 4; // array for shift sequance $seq['shift'] = array(); //$seq['shift2'] = array(); // the max number foreach sequance , 'kerja2' => 7 $seqances = array('lembur' => 7, 'kerja' => $hpattern); $x = 0; // generate the sequances for($i = 0; $i < $d2; $i++) { // generate the number sequances for lembur and kerja foreach($seqances as $key => $maxSeq) { // if current postion is set, then skip it if(isset($seq[$key][$i])) continue; // get previous number in current squance $num = $seq[$key][$i - 1] + 1; // is number greater than the max sequance number // reset sequance if($num > $maxSeq) $num -= $maxSeq; // add number to current sequance $seq[$key][$i] = $num; } $kerjaValue = $seq['kerja'][$i]; // default shift value to off $shiftValue = 'Off'; // if shift not with 1 dan 2 if(!$shift_1dan2) { // Shift pattern 14/1 if($hpattern == 14 && $kerjaValue < 14) $shiftValue = $shiftStart[1]; if($kerjaValue < 7) $shiftValue = $shiftStart[0]; } // shift 1 dan 2 elseif($shift_1dan2) { if($kerjaValue < $hpattern) $shiftValue = ($x % 2 == 0) ? $shiftStart[0] : $shiftStart[1]; // alternate between shift values, when x is dividable by 2 if($shiftValue == 'Off') $x++; // increment x when shift is Off } $seq['shift'][$i] = $shiftValue; } ?> <style> th { color: red; width: 20px;} td { text-align: center; } </style> <table> <tr> <th>Tanggal</th> <th><?php echo implode('</th><th>', range(1, $d2)); ?></th> </tr> <?php foreach($seq as $key => $sequance): ?> <tr> <td><?php echo ucwords($key) ?></td> <td><?php echo implode('</td><td>', $sequance); ?></td> </tr> <?php endforeach; ?> </table>
-
Have a read of this thread http://forums.phpfreaks.com/topic/283274-simple-math-problem/ You should be able to find a solution within there.
-
Once you have processed the form, perform a header redirect.
-
Maybe use cURL With cURL you can send a request to a server and retrieve the response.
-
Create a recursable function, passing the value by reference function array_escape($array) { // loop over array, foreach($array as $key => &$value) { // value is array?, call the function again if(is_array($value)) $value = array_escape($value); else $value = htmlspecialchars($value, ENT_QUOTES); // apply htmlspecialchars } return $array; // return the array } $array = array( 'key1' => '"test"', 'key2' => 't\'wp', 'some "other \'value\'', 'key3' => array('name'=> "'part2'", 'age' => 'part3') ); printf('<pre>%s</pre>', print_r(array_escape($array), true));
-
You need to concatenate the $_SERVER['PHP_SELF'] variable into the string, or wrap it within curly braces // wrapped in curly braces echo " ... <td> <a href={$_SERVER['PHP_SELF']}?id=$count>U pdate </a></td> </tr>"; // OR Concatenate echo " ... <td> <a href=".$_SERVER['PHP_SELF']."?id=$count>U pdate </a></td> </tr>"; Also if you want to output a double quote you need to escape it (\") echo " ... <td> <a href=\"".$_SERVER['PHP_SELF']."?id=$count\">U pdate </a></td> </tr>";
-
Doing a lazy match seems to work fine. Change the regex to preg_match_all("~VI.([^=]+)=\s*(\[?{.*?}\]?);~is", $data, $matches);
- 16 replies
-
- preg_match
- preg_match_all
-
(and 1 more)
Tagged with:
-
Where are you getting that from? As it is not valid JSON syntax, my regex will match it however json_decode will not decode it, due to having too many (closing) } braces. VI.data={"data1":"text1","data2":"text2","data3":"text3",data4:{text4a:1,text4b:1},"data5":"text5","data6":"text6","data7":"text7",data8:"text8"}}; // ^ too many braces here, making it invalid JSON
- 16 replies
-
- preg_match
- preg_match_all
-
(and 1 more)
Tagged with:
-
Ok, change the regex match to preg_match_all("~VI.([^=]+)=\s*(\[?{[^;]+}\]?)~is", $data, $matches); And change $jsVar = $matches[1][$key]; to $jsVar = trim($matches[1][$key]);
- 16 replies
-
- preg_match
- preg_match_all
-
(and 1 more)
Tagged with:
-
Try these attached files. I changed the 1 dan 2 option into a checkbox. You can select how the shift starts from a single drop down menu. shift.php shift_form.php
-
Change preg_match_all to preg_match_all("~VI.([^\s]+)\s*=\s*(\[?{[^;]+}\]?)~is", $data, $matches);
- 16 replies
-
- preg_match
- preg_match_all
-
(and 1 more)
Tagged with:
-
Are you entering the username and password in your login form? Could you post the login form too
- 12 replies
-
- login
- checklogin
-
(and 2 more)
Tagged with:
-
Not quite understanding your question. Are you wanting to make a dropdown and then chose which shift to display, eg if you select shift 1 you'd see Shift 1 2 2 2 2 2 2 2 Off 1 1 1 1 1 1 2 2 2 2 2 2 2 Off 1 1 1 1 1 1 2 2 If you select shift 2 then shift2 will be shown Shift2 2 2 Off 1 1 1 1 1 1 Off 2 2 2 2 2 2 Off 1 1 1 1 1 1 Off 2 2 2 2 2 2 Off If you select both then shift 1 and 2 will be shown Shift 1 2 2 2 2 2 2 2 Off 1 1 1 1 1 1 2 2 2 2 2 2 2 Off 1 1 1 1 1 1 2 2 Shift2 2 2 Off 1 1 1 1 1 1 Off 2 2 2 2 2 2 Off 1 1 1 1 1 1 Off 2 2 2 2 2 2 Off
-
The session data still exists from the last loggin. This is because your logout code is not removing the session correctly, use session_destroy() for this instead. To test your code add session_destroy() after session_start() now run your code. Remove session_destory() after you have ran the code, this to clear the sessions of any data.
- 12 replies
-
- login
- checklogin
-
(and 2 more)
Tagged with:
-
Oops, change echo "Attempting to login....<br>" to echo "Attempting to login....<br>"; I left the semi-colon off of the end of line 13 which is causing the error. Try to login again and post the messages you get.
- 12 replies
-
- login
- checklogin
-
(and 2 more)
Tagged with:
-
Use this as login.php. Post what messages are displayed. <?php ini_set('display_errors', 1); error_reporting(E_ALL); session_start(); /*Om användaren har tryck på loggut-knappen så verkställs sessionen.*/ if (isset($_POST['action']) && $_POST['action']=='logout') { session_unset(); } echo "Attempting to login....<br>" if (! isset($_SESSION['username'])) { if (isset($_POST['username'])) { $username = addslashes($_POST['username']); $pswd = addslashes($_POST['pswd']); echo "Username $username<br>Password $pswd<br>"; /*Här försöker vi koppla upp mot databasen*/ mysql_connect('localhost', 'root', '') or die("Kan inte koppla upp mot db-servern"); mysql_select_db("db_film") or die("Kan inte koppla upp mot db"); /*Här hämtas namn, användarnamn och lösenord från tabellen users i databasen. Om de inskrivna värdena stämmer överens med uppgifterna i databasen så skickas vi till publishpost.php. */ $query = "SELECT username FROM users WHERE username='$username' AND pswd=md5('$pswd')"; echo "Query to run...<pre>$query</pre>"; $result = mysql_query($query); if (mysql_num_rows($result) == 1) { echo 'Success logged in! Credentials matched<br>'; // $_SESSION['firstname'] = mysql_result($result,0,"firstname"); $_SESSION['username'] = mysql_result($result,0,"username"); $user = $_POST['username']; $salt = "somestring"; $_SESSION['token'] = md5($salt . $user . $salt); $token = $_SESSION['token']; printf('<pre>$_SESSION data = %s</pre>', print_r($_SESSION, true)); //header("location: publishpost.php"); } /*Om uppgifterna inte stämmer så stannar användaren kvar på login.php och en text skrivs ut som talar om att man inte har blivit inloggad.*/ else { echo "Login failed! Username/password wrong<br>"; $username = $_SESSION['username']; //header("location: login.php"); echo ("Du är inte inloggad"); } } else { echo "\$_POST['username'] does not exist<br>Can not loggin"; } } else { echo "\$_SESSION['username'] exists. Already logged in?<br>"; } ?>
- 12 replies
-
- login
- checklogin
-
(and 2 more)
Tagged with:
-
PHP OOP Upload file & submit to database with user_id
Ch0cu3r replied to Snitz's topic in PHP Coding Help
In the uploadPhoto method you're not using $fields anywhere, You set the user_id, but nothing for the url field. public function uploadPhoto($fields = array()) { $photo = $this->_db->insert('userPhotos', array('user_id' => $this->data()->id)); if(!$photo) { throw new Exception('There was a problem creating your account.'); } } I assume you need to add the url field as the second param of insert method, eg $photo = $this->_db->insert('userPhotos', array('user_id' => $this->data()->id, 'url' => $fields['url'])); -
That is because you are echo'ing the query before hand echo "<pre>$query</pre>"; Remove or comment the line above. This will cause the header redirect from working.
- 12 replies
-
- login
- checklogin
-
(and 2 more)
Tagged with:
-
You could try <?php // get the query string and parse into an array parse_str($_SERVER['QUERY_STRING'], $queryStringArray); // add full to array $queryStringArray['full'] = 1; // rebuild the query string $queryString = '?' . http_build_query($queryStringArray); ?> <a href="<?php bloginfo('url'); echo $queryString; ?>">Continue to Website</a>
-
It seems some of the decimals are not being converted correctly here cijena_EUR = CONVERT(REPLACE(@cijena_EUR, ",", "."), DECIMAL(10,2)) , cijena_DD = CONVERT(REPLACE(@cijena_DD, ",", "."), DECIMAL(10,2)) , Can you post some same data?