Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Utorok, 24. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Triggers

phpMyEdit Configuration     Triggers
Odoslať novú tému   Odpovedať na tému    
 
Zorro     Založený: 17.05.2019   Príspevky: 2  
Príspevok Zaslal: 2019-05-17 11:49
Návrat hore  Odpovedať s citátom     

I have a database of school alumni of 612 records and many more entries will be added. phpMyEdit works great showing all the records, sorting, etc.
However, I have a field in the database that needs to be a random unique text of three letters and three digits. I had Excel do this before I imported the existing information. When a new record (name) is added, this field needs to be automatically updated with a unique combination of three letters and three digits.

I made a project that will update the last record when run alone. However, when I add $opts[triggers][insert][after] = 'add_code.inc'; to my main project and run it I get a 500 error - The website cannot display the page and the error log has this error, "PHP Parse error: syntax error, unexpected T_STRING in ..../alumni/members.php on line 102." If I remove the $opts[triggers][insert][after] = 'add_code.inc'; line, I do not get an error. I did a test and change the code in add_code.inc to just echo "Hello World" and my program runs but I get Hello World at the top of the web page.

Any ideas what is wrong with the $opts[triggers] line? Or does the include file needs to be changed?

Thank you for your help.

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2019-05-17 21:34
Návrat hore  Odpovedať s citátom     

Look online for a PHP syntax checker. Otherwise post the code it looks like the triggers line is missing ' around the three components

 
Zorro     Založený: 17.05.2019   Príspevky: 2  
Príspevok Zaslal: 2019-05-17 23:28
Návrat hore  Odpovedať s citátom     

doug Napísal:
Look online for a PHP syntax checker. Otherwise post the code it looks like the triggers line is missing ' around the three components


Here is the code for my main file that I call members.php:

<?php
include 'add_code.inc';

// MySQL host name, user name, password, database, and table
$opts['hn'] = 'localhost';
$opts['un'] = '*****';
$opts['pw'] = '*****';
$opts['db'] = '*****';
$opts['tb'] = 'members';

// Name of field which is the unique key
$opts['key'] = 'id';

// Type of key field (int/real/string/date etc.)
$opts['key_type'] = 'int';

// Sorting field(s)
$opts['sort_field'] = array('Last_Name','First_Name');

// Number of records to display on the screen
// Value of -1 lists all records in a table
$opts['inc'] = 15;

// Options you wish to give the users
// A - add, C - change, P - copy, V - view, D - delete,
// F - filter, I - initial sort suppressed
// $opts['options'] = 'ACPVDF';
$opts['options'] = 'AVCF';

// Number of lines to display on multiple selection filters
$opts['multiple'] = '4';

// Navigation style: B - buttons (default), T - text links, G - graphic links
// Buttons position: U - up, D - down (default)
$opts['navigation'] = 'DB';

// Display special page elements
$opts['display'] = array(
'form' => true,
'query' => true,
'sort' => true,
'time' => true,
'tabs' => true
);

// Set default prefixes for variables
$opts['js']['prefix'] = 'PME_js_';
$opts['dhtml']['prefix'] = 'PME_dhtml_';
$opts['cgi']['prefix']['operation'] = 'PME_op_';
$opts['cgi']['prefix']['sys'] = 'PME_sys_';
$opts['cgi']['prefix']['data'] = 'PME_data_';
$opts[&#8217;execute&#8217;] = 0;
$opts[&#8217;display&#8217;][&#8217;sort&#8217;] = true;
$opts[&#8217;navigation&#8217;] = 'UDBTG'; // all navigations styles

$opts[&#8217;triggers&#8217;][&#8217;insert&#8217;][&#8217;after&#8217;] = 'add_code.inc&#8217;;

$opts['fdd']['id'] = array(
'name' => 'ID',
'select' => 'N',
'maxlen' => 4,
'sort' => true,
'options' => 'RL'
);

*** This field is to get an unique code on Add from the Include file ****
$opts['fdd']['Code'] = array(
'name' => 'Code',
'select' => 'T',
'maxlen' => 6,
'sort' => true,
'options' => 'RL'
);
***************

$opts['fdd']['Last_Name'] = array(
'name' => 'Last Name',
'select' => 'T',
'maxlen' => 30,
'sort' => true,
&#8217;required&#8217; => true
);
$opts['fdd']['First_Name'] = array(
'name' => 'First Name',
'select' => 'T',
'maxlen' => 30,
'sort' => true
);

// Now important call to phpMyEdit
require_once 'phpMyEdit.class.php';
new phpMyEdit($opts);

?>


Here is the code of the include file, add_code.inc:

<?php
// MySQL host name, user name, password, database, and table
$dbhost = 'localhost';
$dbuser = '*****';
$dbpass = '*****';
$dbtable = '*****';
$opts['tb'] = 'members';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbtable) or die("Connect failed: %s\n". $conn -> error);

// Loop until a value is found that is not in the database
$unique = "false";
while ( $unique == "false" ) {
$c = chr(mt_rand(65, 90)) . chr(mt_rand(65, 90)) . chr(mt_rand(65, 90)) . mt_rand(100, 999);
$sql = "SELECT * FROM members WHERE Code = '$c'";
$result = $conn->query($sql);
if($result->num_rows == 0) {
// add new code to add to menber's record
$sql = 'SELECT * FROM members Order By id Desc Limit 1';
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
$row_2_update = $row["id"];
$query = "UPDATE `members` SET `Code`='".$c."' WHERE `id` = $row_2_update";
$unique = "true";
} else {
$unique = "false";
return true;
}
}

$result = mysqli_query($conn, $query);

if($result)
{
return true;
}else{
return false;
}
mysqli_close($conn);
return false;
?>

By adding the "return false;" at the last line, I do not get an error. But the field 'Code" does not get updated on Add. If I refresh the page, the last entry I added is duplicated but the "Code" field is not updated.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov