Jump to content

Another set of eyes required, please


MartynLearnsPHP

Recommended Posts

I am trying to update task based progress updates. I've got a very simple database that needs to be updated with:

 

Database name: progress

1. ID (auto increment)

2. admin (name of the project manager)

3. adminid (ID of the project manager in the project manager db)

4. member (name of the member of the project in the members db)

4. project (particular project being updated)

5. status (progress of the project as a number between 10 and 90)

6. timestamp

 

I have the following php script update insert a new line into my progress table:

if (!empty($_POST['progress'])) {
	if(Input::exists()) {
		if(Token::check(Input::get('token'))) {
			$adminprogress = Input::get('admin');
			$adminidprogress = Input::get('adminid');
			$memberprogress = Input::get('member');
			$projectprogress = Input::get('project');
			$statusprogress = Input::get('status');
			$timestamp = date('Y-m-d H:i:s');
			
			$progressupdate = DB::getInstance()->insert(progress, array(
				'admin' => $adminprogress,
				'adminid' => $adminidprogress,
				'member' => $memberprogress,
				'project' => $projectprogress,
				'status' => $statusprogress,
				'timestamp' => $timestamp
			));

			Redirect::to('memberattire1.php');
		}
	}
}

And I have the following code in the body of my page:

<form method="post" action="">
<label>
	<select name="status">
				<option value=choose>---Please Select---</option>
				<option value = "0">(10%) Bunker Registered</option>
				<option value = "10">(20%) First discussions held</option>
				<option value = "20">(30%) Initial research undertaken</option>
				<option value = "30">(40%) Ideas shared</option>
				<option value = "40">(50%) Enquiries made</option>
				<option value = "50">(60%) Results of enquiries shared</option>
				<option value = "60">(70%) Preferences shared</option>
				<option value = "70">(80%) Decisions made</option>
				<option value = "80">(90%) Decisions being executed</option>
				<option value = "90">(100%) Project Completed</option>
	</select>
</label>
<br><br>
<input type="hidden" name="member" value="<?php echo $membername; ?>">
<input type="hidden" name="admin" value="<?php echo $admin; ?>">
<input type="hidden" name="adminid" value="<?php echo $adminid; ?>">
<input type="hidden" name="project" value="attire1">
<input type="hidden" name="token" value="<?php if(isset($token)) { echo $token; } else { echo $token = Token::generate(); } ?>" >
<input type="submit" value="Submit Update" name="progress">
</form>

I know my $membername, $admin and $adminid are ok because I can simply echo them out to confirm them, so there is something silly in my coding that I've overlooked.

 

Can someone with a fresh pair of eyes see a typo or missed semi-colon or whatnot?

 

Many thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/293037-another-set-of-eyes-required-please/
Share on other sites

I'm getting no errors.

 

It's supposed to insert a new record into the progress table with the following columns being populated: admin, adminid, member, project, status and timestamp.

 

At present? Nothing is happening. Nothing at all.

I don't know what framework you're using, but I'd do an else on the Input::exists() and Token::check(Input::get('token')) if's to see if that's where it's barfing. If not, it may be the DB methods - again, hard to tell without knowing what you're using. I don't see any egregious typos or anything like that, though...

You need to debug your script. Basic way to do this is to echo something out at various stages in your script to see where it is failing. Example

echo 'Check if $_POST[\'progress\'] is not empty... ';
if (!empty($_POST['progress'])) {

    echo 'TRUE<br />';

    echo 'Check Input::exists()...';
    if(Input::exists()) {
        echo "TRUE<br />";

        echo 'Check Token::check(Input::get(\'token\')) passes...';
        if(Token::check(Input::get('token'))) {

            echo "TRUE<br />";

            $adminprogress = Input::get('admin');
            $adminidprogress = Input::get('adminid');
            $memberprogress = Input::get('member');
            $projectprogress = Input::get('project');
            $statusprogress = Input::get('status');
            $timestamp = date('Y-m-d H:i:s');

            $data = array(
                'admin' => $adminprogress,
                'adminid' => $adminidprogress,
                'member' => $memberprogress,
                'project' => $projectprogress,
                'status' => $statusprogress,
                'timestamp' => $timestamp
            );

            echo "Values passed to the database";
            printf('<pre>%s</pre>', print_r($data, 1));

            $progressupdate = DB::getInstance()->insert(progress, $data);

            echo "Query inserted data into the progress table... " . ($progressupdate ? 'TRUE' : 'FALSE');

            // for debug purposes only the following lines has been commented.
            //Redirect::to('memberattire1.php');
        }
    }
    else 
    { 
       echo "FALSE";
    }
} 
else
{ 
   echo "FALSE"; 
}

I'm using phpMyAdmin databases.

 

My DB methods work - this is about the 30th different page that I have used them on and about the 100th different input form.

 

Likewise, the inpu::exists() code is exactly the same as is used elsewhere on the page.

 

The only thing I can imagine wrong is a typo, but like you say I just can't see where it could be. And I've been staring at this small bit of coding for 2 days now...

 

EDIT:

Sorry ch0cu3r - I posted before refreshing the page and seeing your post. I'll check that out now.

Right. The problem seems to be with my Check Token, which is coming up with a FALSE reading.

 

Thanks for the help. At least I know where to look now, although I'm not sure why I have this problem because it is the exact code that I have been using on numerous scripts throughout my site.

Aha! I've figured it out. Another of my table updates simply had...

<input type="hidden" name="token" value="<?php echo Token::generate(); ?>" >

whereas when there are more than form they all need to have...

<input type="hidden" name="token" value="<?php if(isset($token)) { echo $token; } else { echo $token = Token::generate(); } ?>" >

Thanks everyone for taking the time to look and help me out here.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.