Jump to content

jakebur01

Members
  • Posts

    885
  • Joined

  • Last visited

Everything posted by jakebur01

  1. This may be the longer way around than using Count in the query, but doing something like this always works for me. $result = mysql_query("SELECT * FROM iptablename WHERE ip = '{$_SERVER['REMOTE_ADDR']}'", $link); $num_rows = mysql_num_rows($result); if($num_rows>"0") { // do not let them sign up } else { // display signup code }
  2. How do you use a double quote in str_replace? $queryline = str_replace(""","'""",$line);
  3. It would not return data, but it would keep my script from hanging up.
  4. Cool! What about if it contained a double quote? How would you escape that?
  5. As an alternative, could I do something like this so it will skip the query all together? Like: if($line contains ' OR $line contains " OR $line contains ,) { //do nothing } else { ... process query }
  6. Mmmnn. There's gotta be a way to do this.
  7. But, this is an odbc query? Can I still generate a MySQL connection, store mysql_real_escape_string() into a variable, and then use that value with my odbc query?
  8. I am doing an odbc query. And one of the e-mails has a ' in it. Example: woody'squote@example.net Warning: odbc_exec() [function.odbc-exec]: SQL error: [ProvideX][ODBC Driver]Unexpected extra token: woody'squote@example.net, SQL state 37000 in SQLExecDirect in C:\Inetpub\wwwroot\smithsadvantage\failed_messages.php on line 40 Error in SQL However, I still want to be able to select info from the database based on the email address above. How can I still query the data using a value that has quotes and other weird characters? if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT CUSTOMER_NUM, CUSTOMER_NAME, PHONE_1 FROM AR_CUST_MAST WHERE EMAIL_1 = '$line'"; //print $sql; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} while (odbc_fetch_row($rs)) { $acct=odbc_result($rs,"CUSTOMER_NUM"); $name=odbc_result($rs,"CUSTOMER_NAME"); $phone=odbc_result($rs,"PHONE_1"); }
  9. Cool. Thanks. Here is the full code: <?php set_time_limit(900); ini_set('max_execution_time', '999'); include_once('inc/data.inc'); $file = file_get_contents('failed_messages/failed_messages.txt'); $lines = explode("\n",$file); // now you have an array with all the lines in it. You can loop through it and do whatever you want. foreach($lines as $line){ $line=trim($line); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT CUSTOMER_NUM, CUSTOMER_NAME, PHONE_1 FROM AR_CUST_MAST WHERE EMAIL_1 = '$line'"; //print $sql; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} while (odbc_fetch_row($rs)) { $acct=odbc_result($rs,"CUSTOMER_NUM"); $name=odbc_result($rs,"CUSTOMER_NAME"); $phone=odbc_result($rs,"PHONE_1"); } $acct =mysql_real_escape_string($acct); $name =mysql_real_escape_string($name); $phone =mysql_real_escape_string($phone); $query = "insert into failed_messages values ('0','$acct', '$name', '$phone', '$line')"; mysql_query($query, $db); } //$myFile = "failed_messages/failed_messages.txt"; //$fh = fopen($myFile, 'w'); //fclose($fh); // erase file: file_put_contents('failed_messages/failed_messages.txt',''); ?>
  10. What about something like this? $myFile = "failed_messages/failed_messages.txt"; $fh = fopen($myFile, 'w'); fclose($fh);
  11. Thanks. It works good all except for trunicating the file. Fatal error: Call to undefined function get_put_contents() in C:\Inetpub\wwwroot\smithsadvantage\failed_messages.php on line 39
  12. I am going to use odbc to look at the inventory file and grab the Name, Account #, and Telephone number associated with the returned address. Then, insert it all into a MySQL database. Then, every evening I am going to schedule a php script that will run and look at the table every night. If there is any data in it, I will have it e-mail one of the ladies in the office then trunicate the table. If there is not any data in the table, it will do nothing.
  13. I found this: $myFile = "testFile.txt"; $fh = fopen($myFile, 'r'); $theData = fgets($fh); fclose($fh); echo $theData; But, I am not sure that this will loop through each line??
  14. I have a program that is storing failed, returned messages into a text file. I would like PHP to look at each address and handle it, then trunicate the text file, in other words wipe it clean. Here is an example of how it is storing the addresses into the text file: test1d8@thisistheemailtest.com test23@thissithemailte.com test2@testduck.com test3@testduck.com
  15. This is really what I am looking to do. Get the failed address, query the customer database to get the customers info based on the failed address, then store this line into the MySQL failed_messages table. Then, ever so often I can send this list to someone in the office who can correct these wrong addresses. <?php include_once('inc/data.inc'); $failedaddress= $popmonger->FailedAddress; if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT CUSTOMER_NUM, CUSTOMER_NAME, PHONE_1 FROM AR_CUST_MAST WHERE EMAIL_1 = '$failedaddress'"; //print $sql; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} setlocale(LC_MONETARY, 'en_US'); while (odbc_fetch_row($rs)) { $acct=odbc_result($rs,"CUSTOMER_NUM"); $name=odbc_result($rs,"CUSTOMER_NAME"); $phone=odbc_result($rs,"PHONE_1"); } $acct =mysql_real_escape_string($acct); $name =mysql_real_escape_string($name); $phone =mysql_real_escape_string($phone); $query = "insert into failed_messages values ('0','$acct', '$name', '$phone', '$failedaddress')"; mysql_query($query, $db); ?>
  16. I changed it, but I still get the same error in the log file. And the data does not insert. <?php include_once('inc/data.inc'); $query = "insert into failed_messages values ('0','0', '0', '0', '0')"; mysql_query($query, $db) or die('could not query'); ?> [attachment deleted by admin]
  17. I know this is not an error that php generates. But, I am using a program called popmonger that handles failed messages and it will run a php script to handle the message. I have it pointed to my php script. And in the log file it is throwing this error: Name cannot begin with the '' character, hexadecimal value 0x20. Line 1, position 12. Code I am using for testing: <?php include_once('inc/data.inc'); $query = "insert into failed_messages values ('0','0', '0', '0', '0')" or die('Could not insert'); mysql_query($query, $db) or die('could not query'); ?>
  18. Thanks. I will change it to your update and test it out. So, far this code below is working great. I wound up changing $prevEnd to 15 since it will always be SALES_PD_15. $curEnd = 27; // 27 $curStart = 27 - abs(11-date('m')); // 27 - 6 = 21 $prevEnd = 15; // 15 $prevStart = $prevEnd - abs(11-date('m'));//15-6=9 $McurTotal = 0; $MprevTotal = 0; while (odbc_fetch_row($rs)) { for ($col = $curStart; $col <= $curEnd; $col++) { if ($col == 1) $colName = 'SALES_OLDEST_PD1'; elseif($col == 26) $colName = 'SALES_LAST_PD_26'; elseif($col == 27) $colName = 'SALES_CURR_PD_27'; else $colName = 'SALES_PD_' . $col; $McurTotal += odbc_result($rs,$colName); } for ($col = $prevStart; $col <= $prevEnd; $col++) { if ($col == 1) $colName = 'SALES_OLDEST_PD1'; elseif($col == 26) $colName = 'SALES_LAST_PD_26'; elseif($col == 27) $colName = 'SALES_CURR_PD_27'; else $colName = 'SALES_PD_' . $col; $MprevTotal += odbc_result($rs,$colName); } $M27 += odbc_result($rs,"SALES_CURR_PD_27"); $M15 += odbc_result($rs,"SALES_PD_15"); } /* $MyearDiff= 100-($MprevTotal*100/$McurTotal); $MmonthDiff= 100-($M15*100/$M27); $MyearDiff = number_format($MyearDiff, 2, '.', ','); $MmonthDiff = number_format($MmonthDiff, 2, '.', ','); */ $McurTotal = number_format($McurTotal, 2, '.', ','); $MprevTotal = number_format($MprevTotal, 2, '.', ','); $M27 = number_format($M27, 2, '.', ','); $M15 = number_format($M15, 2, '.', ',');
  19. Thank you. That is exactly was I was looking for. I changed $prevEnd to equal 15. $curEnd = 27; // 27 $curStart = 27 - abs(11-date('m')); // 27 - 6 = 21 $prevEnd = 15;// 15 $prevStart = $prevEnd - 11; // 20 - 11 = 9 I have a question. Looking to the future... Like when the date becomes November of this year, will "abs(11-date('m'))" equal zero? October of this year would equal 13.... And December of this year would equal 1?
  20. In a round about way, this is what I'm trying to do. Append the numbers between the $start and $end variables to the "$M". Loop incrementing and totaling those odbc variables. while(loop $backtoNovember"7 times") { $MCYTD += append $M to numbers $MCYTDstart through $MCYTDend in order to total up the variables; } So, this would output something like. $MCYTD = $M21 + $MCYTD; $MCYTD = $M22 + $MCYTD; $MCYTD = $M23 + $MCYTD; $MCYTD = $M24 + $MCYTD; $MCYTD = $M25 + $MCYTD; $MCYTD = $M26 + $MCYTD; $MCYTD = $M27 + $MCYTD; _________________ Giving me the total Current Year to Date Sales. Which is stored in $MCYTD.
  21. Just to clarify. In the example of today's date. $MCYTD would equal the sum of $M21 - $M27. $MLYTD would equal the sum of $M9 - $M15.
  22. Ok, I think I'm getting somewhere now. Now I need to total the columns that are between $MLYTDstart and $MLYTDend, store it at variable $MLYTD. And total the columns between $MCYTDstart and $MCYTDend, store it at variable $MCYTD. I am not sure how to do this. I have the columns in variables $M1 - $M27. Do I need to do some kind of for loop or while loop and append the numbers to $M to total up the range? while (odbc_fetch_row($rs)) { $M1 += odbc_result($rs,"SALES_OLDEST_PD1"); $M2 += odbc_result($rs,"SALES_PD_2"); $M3 += odbc_result($rs,"SALES_PD_3"); $M4 += odbc_result($rs,"SALES_PD_4"); $M5 += odbc_result($rs,"SALES_PD_5"); $M6 += odbc_result($rs,"SALES_PD_6"); $M7 += odbc_result($rs,"SALES_PD_7"); $mate += odbc_result($rs,"SALES_PD_8"); $M9 += odbc_result($rs,"SALES_PD_9"); $M10 += odbc_result($rs,"SALES_PD_10"); $M11 += odbc_result($rs,"SALES_PD_11"); $M12 += odbc_result($rs,"SALES_PD_12"); $M13 += odbc_result($rs,"SALES_PD_13"); $M14 += odbc_result($rs,"SALES_PD_14"); $M15 += odbc_result($rs,"SALES_PD_15"); $M16 += odbc_result($rs,"SALES_PD_16"); $M17 += odbc_result($rs,"SALES_PD_17"); $M18 += odbc_result($rs,"SALES_PD_18"); $M19 += odbc_result($rs,"SALES_PD_19"); $M20 += odbc_result($rs,"SALES_PD_20"); $M21 += odbc_result($rs,"SALES_PD_21"); $M22 += odbc_result($rs,"SALES_PD_22"); $M23 += odbc_result($rs,"SALES_PD_23"); $M24 += odbc_result($rs,"SALES_PD_24"); $M25 += odbc_result($rs,"SALES_PD_25"); $M26 += odbc_result($rs,"SALES_LAST_PD_26"); $M27 += odbc_result($rs,"SALES_CURR_PD_27"); } $MCYTDstart=27-$backtoNovember; $MCYTDend=27; $MLYTDstart=$MCYTDstart - 12; $MLYTDend=$MLYTDstart + $backtoNovember;
  23. No, it will always stay the same. November is the beginning of fiscal year for a business. I'm just trying to count back to November.
  24. What about this? $start = date("m"); if($start<"11") { $backtoNovember= $start + 1; } elseif($start=="11") { $backtoNovember="0"; } else { $backtoNovember="1"; }
  25. Just to make things a lot simpler, I decided to start a new topic. My question is, how can I count how many months it is back to the past November? Example: May 2011 back to November would return 6. Example: Dec 2011 back to November would return 1. Example: October 2011 back to November would return 11. Jake
×
×
  • 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.