Jump to content

roopurt18

Staff Alumni
  • Posts

    3,746
  • Joined

  • Last visited

    Never

Everything posted by roopurt18

  1. I don't have the time right now to sort out your difficulty, or I'd help you further. I'm also not really familiar with phpbb3 so I can't tell you what you may be doing wrong. What I can say is make sure you've read and understand the documentation for phpbb3. Take any error messages your receiving and search for them on Google. Use numerous, different, and specific searches. I promise you you're not the first person to encounter whatever this problem is so out there somewhere is someone else who posted and received help for the same issue. Best of luck!
  2. Empty your tables and try your experiments again. I changed line 112 from $player['id'] to $player['player_id'], which I believe should fix it. <?php require('includes/application_top.php'); // if the customer is not logged on, redirect them to the login page if (!tep_session_is_registered('customer_id')) { $navigation->set_snapshot(); tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); } ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <?php require('includes/form_check_coach.js.php'); ?> </head> <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"> <!-- header //--> <?php require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <!-- body //--> <?php mydbg( 'POST: ' ); mydbg( $_POST );//%% if( !empty( $_POST ) ) { /** * If you print_r( $_POST ) you will find that you have an array named 'players'. * Each index into this array will be POSITIVE and the players database ID if they already exist in the database * The index will be NEGATIVE if the player is new and needs to be inserted. * * And then each player is an array where the associative names should match your column names, * so that you can easily generate your insert / update statements based on what I * showed you earlier. */ foreach( $_POST['player'] as $player_id => $player_info ) { // ADDED A CHECK FOR IF THE PLAYER IS EMPTY! $emptyplayer = $player_info; // Copy the array unset( $emptyplayer['customer_id'] ); // Remove customer_id from empty player $emptyplayer = trim( implode( " ", $emptyplayer ) ); $emptyplayer = !strlen( $emptyplayer ); // true if empty, false otherwise foreach( $player_info as $k => $v ) { $player_info[$k] = "'" . mysql_real_escape_string( $v ) . "'"; } if( $player_id < 0 ) { if( $emptyplayer ) { mydbg( 'Skipped player' );//%% continue; // SKIP TO NEXT PLAYER } // OOPS! SINCE 'player_id' IS AUTO-INCREMENTING, WE DO NOT HAVE TO INSERT IT. // THEREFORE THE FOLLOWING LINE IS COMMENTED OUT (i.e. you can remove it from your code). //$player_info['player_id'] = "'" . mysql_real_escape_string( $player_id ) . "'"; $stmt = "insert into `rosters` ( " . implode( ', ', array_keys( $player_info ) ) . " ) values ( " . implode( ', ', $player_info ) . " )"; mydbg( 'Insert player' );//%% }else if( !$emptyplayer ){ // player_id GREATER THAN ZERO, SO PLAYER EXISTS IN DATABASE. PLAYER IS NOT // EMPTY, SO WE UPDATE HIM! foreach( $player_info as $k => $v ) { // SLIGHTLY MORE READABLE $player_info[$k] = "`{$k}`={$v}"; } $stmt = "update `rosters` set " . implode( ', ', $player_info ) . " where " . "`player_id`='" . mysql_real_escape_string( $player_id ) . "'"; mydbg( 'Update player' );//%% }else{ // player_id GREATER THAN ZERO SO HE EXISTS IN DATABASE. PLAYER IS EMPTY // SO WE DELETE HIM! $stmt = "delete from `rosters` where `player_id`='" . mysql_real_escape_string( $player_id ) . "'"; mydbg( 'Delete player' );//%% } $r = mysql_query( $stmt ); // check for errors and success if( !$r ) { mydbg( $stmt );//%% mydbg( mysql_error() );//%% } } } echo "<form action=\"roster.php\" method=\"post\"><table>"; // The reason your players are not selected from the database and displayed in the form // is because $sqlplayers is NULL; you are not running any query. $sqlplayers = "select * from `rosters` where `customer_id`='" . mysql_real_escape_string( $customer_id ) . "'"; $result = mysql_query( $sqlplayers ); $maxrows = 15; $insid = -1; // create a blank player template $cols = array( 'fname' => 'size="10"', 'lname' => 'size="10"', 'address' => 'size="15"', 'city' => 'size="15"', 'state' => 'size="2"', 'zip' => 'size="10"', 'phone' => 'size="10"', 'email' => 'size="20"', 'number' => 'size="2"', 'gradyear' => 'size="4"', 'height_feet' => 'size="1"', 'height_inches' => 'size="4"' ); $blankplayer = array(); foreach( $cols as $c => $extra ) { $blankplayer['player_roster_' . $c] = ''; // MODIFIED TO ADD player_roster_ prefix } // we now have a blank player template for( $i = 1; $i <= $maxrows; $i++ ) { echo "<tr>"; if( $result ) { $player = mysql_fetch_assoc( $result ); mydbg( $player );//%% } if( !$player ) { // We've run out of players, so create a blank one to insert $result = null; // stop trying to access result $player = $blankplayer; $player['player_id'] = $insid--; // first blank player is id -1, second is -2, third is -3, etc. } // dump the fields $firstcol = true; foreach( $cols as $c => $extra ) { $c = 'player_roster_' . $c; // MODIFIED TO ADD player_roster_ prefix echo "<td>"; if( $firstcol === true ) { echo "<input type=\"hidden\" name=\"player[{$player['player_id']}][customer_id]\" value=\"{$customer_id}\" />"; } echo tep_draw_input_field( "player[{$player['player_id']}][{$c}]", $row[$c], $extra ) ."</td>"; } $player = null; // important! echo "</tr>"; } ?> </table><input type="submit" name="editplayers" value="Submit" /> </form> <?php mydbg( null, false ); /*%%REMOVE ME dump debugging */?> <!-- footer //--> <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> <?php /** * Simple debugging function. If $add is true, it adds debugging message. If $add is * is false, it dumps debugging messages that were added. * * @param mixed $msg * @param bool $add */ function mydbg( $msg, $add = true ) { static $msgs = array(); if( $add === true ) { $msgs[] = $msg; }else{ echo '<pre style="text-align: left; font-weight: bold; font-size: 10px; background-color: #ececec;"> DEBUG:'; foreach( $msgs as $msg ) { if( is_bool( $msg ) ) { $msg = 'BOOLEAN [' . ($msg ? 'T' : 'F' ) . ']'; }else if( is_null( $msg ) ) { $msg = '__NULL__'; }else if( is_string( $msg ) && !strlen( $msg ) ) { $msg = '__EMPTY_STRING__'; }else if( is_array( $msg ) || is_object( $msg ) ) { $msg = print_r( $msg, true ); } echo $msg . "\n\n"; } echo '</pre>'; } } ?>
  3. Search for PRIMARY KEY within the document to see how it's used. You only create one PRIMARY KEY `CarNum` column and it goes in the `Cars` table.
  4. http://www.w3schools.com/jsref/jsref_obj_string.asp Look at the split() function. After that it should be trivial to grab the second array index.
  5. TEXT fields are used for storing very large text fields. You should not be using TEXT for items like DriverName or DriverAddress. CarNum exists in both tables, so I assume that you want to use it as a key field. However it is declared as INT in one table and TEXT in the other. It should probably be INT in both. We need to clean up your table structure before we waste any time writing code to work with them.
  6. Make sure the JSON you're receiving from the server is valid.
  7. When you generate the page from PHP, include this in the output: <?php echo sprintf( '<input type="hidden" name="hdnTest" id="hdnTest" value="%s" />', htmlentities( $test, ENT_QUOTES ) ); ?> If $test has 'Hello World' in it, then that should output: <input type="hidden" name="hdnTest" id="hdnTest" value="Hello World" /> Then in JavaScript you can: alert( document.getElementById( 'hdnTest' ).value );
  8. How about showing us the create table statements for each of those tables?
  9. You fix ambiguous column errors by assigning an alias to each table in the query and then refer to the columns by: table_alias.column_name. For example: select a.*, b.* from table1 a inner join table2 b on a.id=b.table1_fk where a.column1='somevalue' and b.column1='someothervalue'; Take note of how I've used a and b to identify the tables throughout the query.
  10. I do JavaScript posts all the time with Dojo; I'm sure other JavaScript libraries make it very easy to do. JavaScript: dojo.addOnLoad( function() { var error_cb = function( obj, args ) { alert( 'Error with XHR call.' ); }, load_cb = function( obj, args ) { if( obj.success === true ) { alert( 'success!' ); console.log( obj ); } }, xhr = { handleAs : 'json', sync : false, url : '/your_script.php', error : error_cb, load : load_cb } content = { }; content.api_key = 'afowi@kfwfja'; xhr.content = content; dojo.xhrPost( xhr ); } ); Although if you are calling this from JavaScript then the API keys will be in plain sight anyways, so not much sense in trying to hide them.
  11. And what is this? include ("./mailtext.inc.php");
  12. I don't have it handy, can you paste the source code of file: class.phpmailer.php as well?
  13. They're poorly coded. A registry (or singleton factory) accomplishes the same thing without the problems.
  14. I think you need to meet my family then.
  15. Bah! I have brain damage that's what the problem is. I put the empty player check in the wrong place. The following code should fix it. I've also made an attempt at fixing why your players are not appearing in the form after they're entered into the database. Try: <?php require('includes/application_top.php'); // if the customer is not logged on, redirect them to the login page if (!tep_session_is_registered('customer_id')) { $navigation->set_snapshot(); tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); } ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <?php require('includes/form_check_coach.js.php'); ?> </head> <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"> <!-- header //--> <?php require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <!-- body //--> <?php mydbg( 'POST: ' ); mydbg( $_POST );//%% if( !empty( $_POST ) ) { /** * If you print_r( $_POST ) you will find that you have an array named 'players'. * Each index into this array will be POSITIVE and the players database ID if they already exist in the database * The index will be NEGATIVE if the player is new and needs to be inserted. * * And then each player is an array where the associative names should match your column names, * so that you can easily generate your insert / update statements based on what I * showed you earlier. */ foreach( $_POST['player'] as $player_id => $player_info ) { // ADDED A CHECK FOR IF THE PLAYER IS EMPTY! $emptyplayer = $player_info; // Copy the array unset( $emptyplayer['customer_id'] ); // Remove customer_id from empty player $emptyplayer = trim( implode( " ", $emptyplayer ) ); mydbg( 'Empty Player:' );mydbg( $emptyplayer );//%% $emptyplayer = !strlen( $emptyplayer ); // true if empty, false otherwise mydbg( 'Empty Player:' );mydbg( $emptyplayer );//%% foreach( $player_info as $k => $v ) { $player_info[$k] = "'" . mysql_real_escape_string( $v ) . "'"; } if( $player_id < 0 ) { if( $emptyplayer ) { mydbg( 'Skipped player' );//%% continue; // SKIP TO NEXT PLAYER } // OOPS! SINCE 'player_id' IS AUTO-INCREMENTING, WE DO NOT HAVE TO INSERT IT. // THEREFORE THE FOLLOWING LINE IS COMMENTED OUT (i.e. you can remove it from your code). //$player_info['player_id'] = "'" . mysql_real_escape_string( $player_id ) . "'"; $stmt = "insert into `rosters` ( " . implode( ', ', array_keys( $player_info ) ) . " ) values ( " . implode( ', ', $player_info ) . " )"; mydbg( 'Insert player' );//%% }else if( !$emptyplayer ){ // player_id GREATER THAN ZERO, SO PLAYER EXISTS IN DATABASE. PLAYER IS NOT // EMPTY, SO WE UPDATE HIM! foreach( $player_info as $k => $v ) { // SLIGHTLY MORE READABLE $player_info[$k] = "`{$k}`={$v}"; } $stmt = "update `rosters` set " . implode( ', ', $player_info ) . " where " . "`player_id`='" . mysql_real_escape_string( $player_id ) . "'"; mydbg( 'Update player' );//%% }else{ // player_id GREATER THAN ZERO SO HE EXISTS IN DATABASE. PLAYER IS EMPTY // SO WE DELETE HIM! $stmt = "delete from `rosters` where `player_id`='" . mysql_real_escape_string( $player_id ) . "'"; mydbg( 'Delete player' );//%% } $r = mysql_query( $stmt ); // check for errors and success if( !$r ) { mydbg( $stmt );//%% mydbg( mysql_error() );//%% } } } echo "<form action=\"roster.php\" method=\"post\"><table>"; mydbg( 'Select players:' ); mydbg( $sqlplayers );//%% // The reason your players are not selected from the database and displayed in the form // is because $sqlplayers is NULL; you are not running any query. $sqlplayers = "select * from `rosters` where `customer_id`='" . mysql_real_escape_string( $customer_id ) . "'"; $result = mysql_query( $sqlplayers ); $maxrows = 15; $insid = -1; // create a blank player template $cols = array( 'fname' => 'size="10"', 'lname' => 'size="10"', 'address' => 'size="15"', 'city' => 'size="15"', 'state' => 'size="2"', 'zip' => 'size="10"', 'phone' => 'size="10"', 'email' => 'size="20"', 'number' => 'size="2"', 'gradyear' => 'size="4"', 'height_feet' => 'size="1"', 'height_inches' => 'size="4"' ); $blankplayer = array(); foreach( $cols as $c => $extra ) { $blankplayer['player_roster_' . $c] = ''; // MODIFIED TO ADD player_roster_ prefix } // we now have a blank player template for( $i = 1; $i <= $maxrows; $i++ ) { echo "<tr>"; if( $result ) { $player = mysql_fetch_assoc( $result ); mydbg( $player );//%% } if( !$player ) { // We've run out of players, so create a blank one to insert $result = null; // stop trying to access result $player = $blankplayer; $player['id'] = $insid--; // first blank player is id -1, second is -2, third is -3, etc. } // dump the fields $firstcol = true; foreach( $cols as $c => $extra ) { $c = 'player_roster_' . $c; // MODIFIED TO ADD player_roster_ prefix echo "<td>"; if( $firstcol === true ) { echo "<input type=\"hidden\" name=\"player[{$player['id']}][customer_id]\" value=\"{$customer_id}\" />"; } echo tep_draw_input_field( "player[{$player['id']}][{$c}]", $row[$c], $extra ) ."</td>"; } $player = null; // important! echo "</tr>"; } ?> </table><input type="submit" name="editplayers" value="Submit" /> </form> <?php mydbg( null, false ); /*%%REMOVE ME dump debugging */?> <!-- footer //--> <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> <?php /** * Simple debugging function. If $add is true, it adds debugging message. If $add is * is false, it dumps debugging messages that were added. * * @param mixed $msg * @param bool $add */ function mydbg( $msg, $add = true ) { static $msgs = array(); if( $add === true ) { $msgs[] = $msg; }else{ echo '<pre style="text-align: left; font-weight: bold; font-size: 10px; background-color: #ececec;"> DEBUG:'; foreach( $msgs as $msg ) { if( is_bool( $msg ) ) { $msg = 'BOOLEAN [' . ($msg ? 'T' : 'F' ) . ']'; }else if( is_null( $msg ) ) { $msg = '__NULL__'; }else if( is_string( $msg ) && !strlen( $msg ) ) { $msg = '__EMPTY_STRING__'; }else if( is_array( $msg ) || is_object( $msg ) ) { $msg = print_r( $msg, true ); } echo $msg . "\n\n"; } echo '</pre>'; } } If it produces any problems, then repeat this procedure:
  16. It's just complaining that you haven't assigned anything to $up_num before using it in the function. Before your very first call to the function put: $up_num = 0; We call that variable initialization. It goes back to early languages where you had to define variables before you used them. Like in the programming language C: int main( void ) { int up_num; up_num = up_num + 1; return 0; } See? I had to write int up_num; and declare up_num to hold integer values before I could use it! In older languages like that, variables weren't automatically set to default values. For example, in PHP if you use a variable without first setting a value in it, it will be initialized to an empty string or the number zero or a null. But the variable has to have something assigned before you can use it; PHP does this automatically but it issues warnings if you rely on it because it's bad programming behavior to use unititialized variables. Going back to my short C example, C does not (or did not) initialize variables. When I declared up_num, it was placed into memory and the value in the variable is whatever is in that memory. In my C code, up_num could be 0, 42,302, -42, or any integer value! Therefore I should have done: int main( void ) { int up_num = 0; /* ALWAYS initialize variables before using them! */ up_num = up_num + 1; return 0; } And if you really want to learn good programming practice, learn how to write programs without global variables. You don't need them!
  17. Could do it with mod_rewrite I suppose: RewriteEngine on RewriteRule /\\$RECYCLE.BIN.* - [F,L] You might have to play around with the regexp a little because of that dollar sign.
  18. Why don't you make double sure that $c['usr2'] has what you expect it to have in it? echo "***<br/>" . htmlentities( $c['usr2'], ENT_QUOTES ) . "<br />***<br />"; echo "***<br/>" . htmlentities( trim( $c['usr2'] ), ENT_QUOTES ) . "<br />***<br />";
  19. Or use a proven library like Dojo for XHR functionality.
  20. Ok. But has anyone written any code to actually access your XML? If not, then you can make a requirement that they must send the API key via post. I really don't see why you can't force them to POST the data.
  21. Drop an .htaccess file in the same folder as $RECYCLE.BIN #.htaccess file # place this in the same directory as the $RECYCLE.BIN folder <Directory ./$RECYCLE.BIN> Order allow,deny Deny from all </Directory> Going from memory there so I could be wrong.
  22. select `id`, count(*) as `count` from `users` having count(*) > (select count(*) from `users` where `id`=1)
  23. Don't use GET for this. GET information is logged in plain text files on the server. That's very bad for sensitive information like keys and passwords. Use POST instead.
  24. Are you trying to implement communication between two web sites where your site exposes an API or some sort? If that's the case: <?php define( 'AN_API_KEY', 'af292f2ok3j2o3jfo32j' ); session_start(); if( empty( $_POST ) ) { echo json_encode( false ); exit(); } if( $_POST['todo'] == 'establish' ) { // establish connection if( $_POST['key'] == AN_API_KEY ) { $_SESSION['established'] = true; } } if( $_SESSION['established'] !== true ) { echo json_encode( false ); exit(); } $o = new stdClass(); if( $_POST['todo'] == 'getcurdate' ) { $o->curdate = date( 'Y-m-d H:i:s' ); }else if( $_POST['todo'] == 'addnums' ) { $o->result = $_POST['n1'] + $_POST['n2']; } echo json_encode( $o ); ?> Have your friend communicate with your API using an HTTPRequest object, which can easily send POST information and hold a session just like a normal browser.
×
×
  • 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.