Archive for November, 2012

using insert and update in php

I have this code in recording timein and timeout

$query=mysql_query("Select * FROM tblattendance where IDNumber='" . $_POST['IDNumber'] . "' ");
list($exists) = mysql_fetch_row($query);


$sql="UPDATE $tbl_name SET TimeoutAM=CURTIME() WHERE IDNumber='" . $_POST['IDNumber'] . "' ORDER BY  Date DESC, TimeinAM DESC LIMIT 1"; 
$sql="INSERT INTO $tbl_name SET Date=CURRENT_DATE(), TimeinAM=CURTIME(), IDNumber='$idnumber', FirstName='$fname', MiddleName='$mname', LastName='$lname' ";       

My problem is that if the IDNumber doesn’t exist it will add a new record with timein and then update the timeout. But when I tried to add again the same IDNumber it didn’t add a new record but instead it’s just update the existing record the timeout columns. What shall I do to add a record again?

Mysql update command failing

Unbelievably, I have an exact script with a different variable than “additional” that works. However, even though there is a mysql column for additional, I can’t get it to update. I have even tried changing additional to something else, yet it fails to work with this column. What is conflicting?

echo "yup";
$lt2 = "yup";
$blah = "yup";
$username = "yup";
$lt1 = "yup";
$dbh = new PDO(censored);
$sql = "UPDATE purchases SET additional = ? WHERE username = ? AND blah = ? AND kusername = ?";
$q = $dbh->prepare( $sql );
$params = array( $lt1, $lt2, $username, $blah );
$q->execute( $params );
$doc = new DOMDocument();
$r = $doc->createElement("location" );
$doc->appendChild( $r );
foreach ( $q->fetchAll() as $row) {
   $e = $doc->createElement( "location" );
    $e->setAttribute( 'name', $row['additional'] );

    $r->appendChild( $e );

print $doc->saveXML();

echo "work";

Can’t write Session variables on certain occasions?

For some reason session won’t keep the variable stored. But when the browser is restarted it corrects the error. Why is this? Here is the warning… Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0

SQL output shows in PHP in table format

I have 4 tables , in this all tables have 3 rows[record] and 3 column[field] filed like Date Name Total. This table like bellow

Fist Table

Date                  Name                      Total
2012-11-07             Manoj                       10
2012-11-08             Ganesh                       4
2012-11-09             Sri                         30

Second Table

Date                   Name                      Total
2012-11-07               Raju                         5
2012-11-08               ggg                          3
2012-11-09               Shshi                       30

Third Table

Date                   Name                      Total
2012-11-07              Ram                         2
2012-11-08               gm                         5
2012-11-09             Shsse                       30

I need Output Like following type in php

 Date          Total
 2012-11-07      17
 2012-11-08      12
 2012-11-09      90

It should display all total in between date in PHP

Protecting certain fields in a dynamic table

I have used a describe statement and converted my code to be dynamic . So each and every field in the Table is displayed to the user(since I have used the describe statement) . can anyone tell me , How can I make a few fields not to be shown to the user ?

For example
Say I have a table by name Table1

Fields are Field1 Field2 Field3 Filed4 Field5

I have used Describe Table1;

I do not want the field 3 and field4 to appear to the user

can anyone help me on this please ?

Thank you in advance

Undefined variable: argc [APP/webroot/cron_dispatcher.php, line <b>87</b>]<

I am running a cron job using the cron_dispatcher.php file. But I’m getting the following error message:

Undefined variable: argc [APP/webroot/cron_dispatcher.php, line 87]

My Code at Line 87 is

define('CRON_DISPATCHER', true);
if ($argc == 2) {
    $Dispatcher = new Dispatcher();
    $Dispatcher -> dispatch($argv[1]);

My crone command is
/web/cgi-bin/php5 /my/path/to/html/app/webroot/cron_dispatcher.php /users/test/

Thank you.

Line separation for multiple headers using PHP’s stream_context_create(); to prepare HTTP POST?

EDIT: resolved. It was a problem with the company’s RegEx statement to determine valid inputs.

I am trying to use a relatively undocumented API (AgentAchieve by Core Logic), and in my futile attempts to get a POST request through, I cannot seem to get the API to accept more than the first header I put in the string.


I am thinking either Agent Achieve is broken OR there is some exotic flavor of header item delineations I have never heard of before. What should I try?

If I put the authentication token header first, I get access and some error about how I failed to specify Content-Type. If I specify Content-Type: application/json first, I get authentication errors. What gives??

Thanks for your help!

EDIT: resolved. It was a problem with the company’s RegEx statement to determine valid inputs.

I want to restrict access to certain web directories through URL

I am doing project using zend framework-2. I want to restrict access to certain web directories through URL(if user without log in). if user tried to log in I need to redirect login page. this is what I do(rough idea not codes ).


 if(username and password ok){
     setcookie('username', $username);
     setcookie('password', $password);

     //redirect to AlbumController indexAction
     return $this->redirect()->toRoute('album', array('controller' => 'album', 'action' => 'index'));

so within AlbumControoler I added this code

public function indexAction()
    if(isset ($_COOKIE['username']) && isset ($_COOKIE['password'])){
        //some codes
        //if user not logged redirect to loogin page 
        return $this->redirect()->toRoute('auth', array('controller' => 'auth', 'action' => 'index'));

so if I use this way I need to add above codes every action. so my question is is this way ok? or is their easy way to do that?

PHP: remove small words from string ignoring german characters in the words

I am trying to create slugs for urls.

I have the following test string :


I want to remove small words less than three characters from this string.

So, I want the output to be


I have tried this code :

$kw = strtolower($kw);
$kw = preg_replace("/\b[^-]{1,2}\b/", "-",  $kw);
$kw = preg_replace('/-+/', '-', $kw);
$kw = trim($kw, '-');
echo $kw;

But the result is :


so, the German character ö is getting removed from the string
and German word Schönheit is being treated as two words.

Please suggest how to solve this.

Thank you very much.

Parsing URL value after ‘#’ in a URL

I’m trying to do a very simple sign on using Microsoft Live Connect, but I’m having problems parsing the returning token. I call this URL:

It takes me to the Microsoft server, logs me in, confirms permissions, and then loads the callback URL correctly, looking like this:

Now the question is how do I get these tokens? How am I supposed to parse that? They use a ‘#’ instead of ‘?’.. so $_GET is empty, $_POST is empty, and $_SERVER['REQUEST_URI'] doesn’t show anything.
Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.