Jump to content

Still Learning


cbrooks

Recommended Posts

Ok, I have a bunch of pages that are working as desired. Reading/displaying info from database. Have a new form where user enters data and then on 'Submit' it digest the data and either inserts a new record or updates an older record.

 

So what is the easiest (and best) method to comfirm that the user 'Does Really' want to update data that is already on file.

 

My initail thought was to use a JavaScript 'confirm(message)' popup, if this is the way to go, how do you pass the return value from the 'confirm(message)' back to your PHP page?

Link to comment
https://forums.phpfreaks.com/topic/182829-still-learning/
Share on other sites

OK, this is what I came up with:

 

First the javascript function:

<code>

function testit(Param, id1, id2, id3){

var message ="Are you sure that you want to change the current data?\n" +

            "Click OK to proceed or Cancel to abort?";

            answer = confirm(message);

window.location.href = "tshowconfirm.php?which=" + answer + "&picked=" + Param + "&id1=" + id1 + "&id2=" + id2 + "&id3=" + id3;

}

</code>

 

 

Next the data input:

<code>

<?php

      echo "<td><select name=\"maybe\" id=\"maybe\" onchange=\"testit(this.value, '{$user}', '{$company}', '{$ship_to_nbr}');\">";

?>

</code>

 

and the output from tshowconfirm.php:

<code>

<?php

  $update_t_f=$_GET['which'];

  $selection=$_GET['picked'];

  $user = $_GET['id1'];

  $company = $_GET['id2'];

  $shiptonbr = $_GET['id3'];

  echo "Update Table : ".$update_t_f."<br />";

  echo "Selection is: ".$selection."<br />";

  echo "User is : ".$user."<br />";

  echo "Company is : ".$company."<br />";

  echo "Shipping is : ".$shiptonbr."<br />";

  ?>

 

It does work, allows me to input my data, calls the javascript code, then relays 'answer' with data to either update or save to the next php script for final action

 

May not be the prettiest or cleanest code, but for a test it works for me.

Link to comment
https://forums.phpfreaks.com/topic/182829-still-learning/#findComment-965058
Share on other sites

That is very vulnerable to a whole slew of security risks, but I'm glad it works. However, you could just do

answer = confirm(message);
if (answer){
window.location.href = "tshowconfirm.php?which=" + answer + "&picked=" + Param + "&id1=" + id1 + "&id2=" + id2 + "&id3=" + id3;
}

instead so that the user can stay on the page if he chooses to abort, instead of being taken to that page.

 

Link to comment
https://forums.phpfreaks.com/topic/182829-still-learning/#findComment-965062
Share on other sites

I understand on the if (answer) {

 

OK, since I'm 'Still Learning' do you mind taking a few minutes and pointing out some of the security risks?

 

The code that I showed was just something simple to allow me to test/learn passing variables back and forth between JavaScript and PHP, not the actual code that I am using in my actual pages.

Link to comment
https://forums.phpfreaks.com/topic/182829-still-learning/#findComment-965070
Share on other sites

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.