Jump to content

Another set of eyes required, please


MartynLearnsPHP
Go to solution Solved by Ch0cu3r,

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
Share on other sites

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

Link to comment
Share on other sites

  • Solution

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"; 
}
Edited by Ch0cu3r
Link to comment
Share on other sites

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.

Edited by MartynLearnsPHP
Link to comment
Share on other sites

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.

Link to comment
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.