replace MYSQL string using a PHP code -


i have code , couldn't work:

$character_set_array = array();      $character_set_array[] = array('count' => 8, 'characters' => '0123456789');     $temp_array = array();     foreach ($character_set_array $character_set) {         ($i = 0; $i < $character_set['count']; $i++) {             $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];         }     }     shuffle($temp_array);     $pinstart = 'aa';     $pinend = implode('', $temp_array);     $newpin = $pinstart.$pinend;     function regenerate_pin($pin) {        if ($pin == 'pin') { return ''; } else {     $pin = mysql_real_escape_string($pin);  // security!     $result = mysql_query("select pin pins pin='$pin' limit 1");        if(mysql_num_rows($result) == 0) {         return 'this pin has been used';             } else {         $sql = mysql_query("update pins set pins='$newpin'");          return "the pin has been regened, new pin '.$newpin.'";              } } } 

basically i'm trying this: - pin html input box, - check if pin exists in database (works) - if exists, replace $pin $newpin , print out $newpin, how table looks

enter image description here

  • some info table:
  • table name = pins column pin stored named pin

thank reading , hope find quick solution.

your regenerate_pin() function doesn't see $newpin variable , update sql might wrong:

change "update pins set pins='$newpin'" "update pins set pin='$newpin'"

for function have 2 options:

add global $newpin; line inside function regenerate_pin($pin) -code

function regenerate_pin($pin) {    global $newpin; ... } 

or send $newpin variable arbument regenerate_pin-function.'

function regenerate_pin($pin, $newpin) {   ... } 

and have call regenerate_pin function this

regenerate_pin('oldpin', 'newpin'); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -