Jump to content

DLR

Members
  • Posts

    66
  • Joined

  • Last visited

About DLR

  • Birthday 11/11/1948

Profile Information

  • Gender
    Male
  • Location
    Johannesburg, South Africa

DLR's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi. Firstly I am a member of long standing so I am now at the opposite end of the age scale to most of you - I only started programming in my middle fifties! - so I may be way out on this suggestion. I have been searching to find a good tutorial to change from MySql to MySqli. Most of what I find on the net seems to focus on the actual connection. Making the change to the connection is easy - but from there on everything seems to go haywire. My site make use of the "get_include_contents(X)" style instead of require(X) that was covered in the php Manual. Now this does not seem to work (for me anyway). I favour the procedural style, mostly as I believe I can avoid learning the OOP method (too old to get my head around it now) and that may be the problem. However, there may perhaps be many others who are starting to face the necessity of changing to MySqli fairly soon - and your expertise will be welcomed I'm sure. I certainly have benefited from your collective input over the years - for which I give you all my heartfelt thanks. Thank you for reading this suggestion.
  2. Thank you. It is as if a light has gone on! I am researching Select, but it would seem that your suggestion of left join will be more elegant. Thanks again!
  3. Hi, There must be a simple way of doing this, but I seem to have missed it and I cannot get my own method to work I have a list of emails and names (subscribers) and another list of unsubscribed emails with names (unsubscribed). (This is a legacy from a previous emailing programme - Mailloop6). I want to create one table (final_list) where the unsubscribed names have been removed. My methodology is to create an array from "subscribers", create an array from "unsubscribed" , then loop through "subscribers" and save the names that are not found in "unsubscribed", into a new table "final_list". I have checked, the "sucribers" and "unsubscribed" arrays hold 4700 and 666 records each - so the creating array part works. My problem is in inserting into "final_list". Each table and array has 3 fields :email, first_name, last_name foreach ($subscribed as $key => $value) { if(in_array($value,$unsubscribed)) { //do nothing as we do not want this information to be stored } else { $sql = "INSERT INTO final_list (email,first_name,last_name) VALUES ('" . $value[$key]['email'] . " ', '" . $value[$key]['first_name'] . " ', '" . $value[$key]['last_name'] . " ') "; $res = mysql_query($sql); if(! $res) { echo '<br>..no record inserted into final list ' . $key. '<br>'; } } } Thanks for reading this - any help will be appreciated
  4. Is this possible with mysql 5.1? I want to join a table MENU from database A to table PERMISSIONS from database B (and then if I can get this to work, extend this to further databases C, D etc). I have tried creating a temporary table in database A and trying to LEFT JOIN to the table in database B - but which connection do I use? So far I have not got this to work. If it is possible to join two databases, I would appreciate you pointing me to the manual section (or other reference) where I can solve the problem. Many thanks.
  5. Hi, this simple function does not work when ob_end_clean() is included. function get_header($path,$file) { ob_start(); include ($path.$file); $var = ob_get_contents(); //file contents are stored in $var so now we try to clean output buffer ob_end_clean(); // this stops the script from working - why? // and if I leave it out and add it at the very end of the script it also stops the whole script from working! why? // and if I leave it out alltogether the script seems to work fine!!!! (but the buffer will keep building up with succesive calls to this function - and must surely create a problem somewhere) return $var; } get_header("../client_info/",$_SESSION['header']);
  6. Thanks for the suggestion - but it does not work either. The file - $_SESSION['header'] - just contains html code - see below - does the problem somehow lie with this file? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>SignForce job management area</title> <link rel="stylesheet" type="text/css" href="../client_info/signforce.css"> </head> <body> <table width="100%" border="0" class="header"> <tr> <td><img src="../client_info/SignForce-70.jpg" width="175" height="38" alt="SignForce logo"> <br> Custom made, world-class signs & signage, delivered & installed anywhere in Southern Africa</td> <td class="logout"> <a href="../index.php"><img src="../logout.jpg" width="91" height="33" alt="logout" border="0"></a> </td> </tr> </table>
  7. I'm trying to code using includes for efficiency - but also need to be mindful of the "headers already sent" problem. So I'm using the model suggested in the php manual - function "get_include_contents()". It works fine for some calls to the function - but not others. Here is the function function get_include_contents($pathname,$filename) { $allowed = array("CEL150.php","celcius_conn.php",$_SESSION['header'],$_SESSION['conn-read'] ); if(! in_array($filename,$allowed)) { $_SESSION['error_msg'] = "Failed access to file Error 201-0"; $_SESSION['error_code'] = 1; header("Location: ../apps/error.php"); } else { if (is_file($pathname.$filename)) { ob_start(); include $pathname.$filename; $contents = ob_get_contents(); ob_end_clean(); chdir(dirname($_SERVER['SCRIPT_FILENAME'])); return $contents; } else { $_SESSION['error_msg'] = "Failed access to file Error 201-1"; $_SESSION['error_code'] = 1; header("Location : ../apps/../apps/error.php"); exit(); } } } Now this call works fine get_include_contents("","CEL150.php"); and so does this get_include_contents("../connect/",$_SESSION['conn-read']); but this does not get_include_contents("../client_info/",$_SESSION['header']); But if I use include("../client_info/" . $_SESSION['header']); instead of the function it works fine (but obviously I get header already sent messages). The whole idea of using the function is to avoid the problems of "headers already sent". But why oh why does it not work? This call for help after countless ours of problem solving - actually no soloutions, just innumerable options. Any suggestions? Thanks David
  8. Hi, I have had no problem putting cookies in the "middle" of a script. Just watch out for the "headers already sent" type message if you output before a header. There's quite a lot on this sort of problem in the tutorials. In particular read the tutorial on security (by DanielO) - to avoid giving away the house as well. Simply put, I think you can create your cookies wherever - but be mindful of security - it may be that Sessions is a better way to do the job. A little longer, but probably more secure.
  9. I've read the sticky on headers and the php manual - and am using my version of the recommended way to overcome the "headers already sent" problem. Clearly I'm missing something (obvious?) The following function (based on the example in the php manual) works fine for file includes but not with file connection to database. Why? function get_include_contents($filename,$path) { $allowed = array("CEL150.php","signforce_conn-read.php" ); if(! in_array($filename,$allowed)) { $_SESSION['error_msg'] = "Failed access to file Error 102-0"; $_SESSION['error_code'] = 1; header("refresh:0;url = ' http://www.celcius-system.com/apps/error.php'"); } else { if (is_file($filename)) { ob_start(); if($path) { set_include_path($path); } include $filename; $contents = ob_get_contents(); ob_end_clean(); chdir(dirname($_SERVER['SCRIPT_FILENAME'])); return $contents; } else { $_SESSION['error_msg'] = "Failed access to file Error 102-1"; $_SESSION['error_code'] = 1; header("refresh:0;url = ' http://www.celcius-system.com/apps/error.php'"); } } } get_include_contents("CEL150.php",""); this include works fine but this does not get_include_contents("signforce_conn-read.php","../connect/"); The contents of "signforce_conn-read.php" is $conn = mysql_connect("host", "user", "password") ; $db = mysql_select_db("SignForce"); If I use the abve code in place of the file "signforce_conn-read.php", it all works fine. Why does the function not work for a connection?
  10. Thanks guys. Today has been a learning curve. I appreciate the time all of you have shared with me. The problem was that somehow I had filed this file in utf-8 - and you were correct it was the BOM(Byte order Mark - yes I did look it up aread quite a lot on it!) In passing I note you (PFMaBiSmAd) reccomend coding in ASCII - but I read that WW3 recommends and encourages utf-8 for HTML5. Would you share your motivation for recommending ASCII? Many thanks
  11. Thanks for the pointers, but 1. Have ready sticky, 2. Have searched forum before posting 3. Am developing with error reporting on (Not sure if it is set to "high" will check that 4. No white space - the code is only 3 lines including php tags! The code works in other files on same web address. So I must be doing something different here. I'm searching for my error - like "permissions". Any other pointrs would be appreciated. The main question is how can there be output if there is only "<?php" before the header? (and definately no whitespace either) And the offending line is line 1 - the php tag! Also why does the ob-start() not make a difference? I conclude that the environment must be different - but I cannot see what setting, or possibly ini setting I need to look at.
  12. I have developed a small programme on my laptop (Windows XP) and am running WAMP on it. My programmes run fine on the laptop but simply dont work on the shared server - a linux platform also running Apache. This simple programme outputs this error "Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/celciu/apps/test.php:1) in /usr/www/users/celciu/apps/test.php on line 2" <?php header("Location: CEL100.php"); ?> I have tried using ob_start(); but get the same error -just now says line 3 <?php ob_start(); header("Location: CEL100.php"); ob_end_flush(); ?> I am thoughrly confused. Any assistance would be appreciated.
  13. Hi, I'm not an expert, so hope this helps I see that you are using a variable name RequiredContent[] in the middle of your HTML. If " RequiredContent[]" is to be elements of an array, then I would assume you would need to switch into <?php echo $RequiredContent[]; ?> to make the variable work - else you would be overwriting the name/value pair and you would only get the last name/value pair posted.
  14. Hi, I have spend a number of frustrated hours trying to see where my error is. I have copied this from the security tutorial (by DanielO), but cannot see where I am making my mistake. Any pointers will be appreciated. The error I get is Warning: mysql_real_escape_string() expects parameter 2 to be resource, string given in C:\wamp\www\sfwebsite\admin\SF201.php on line 93 The code for connection to database sfwebsite works elesewhere in the same programme if(!$conn) { die('connection error'); } $db_selected = mysql_select_db("sfwebsite",$conn); // this is line 93 if(! $db_selected) { die('connection error'); } $name = mysql_real_escape_string($_SESSION['username'],'$conn'); $sql = "SELECT level FROM sf_admin WHERE username = '$name' "; $res = mysql_query($sql) or die('Failed to find Admin records');
×
×
  • 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.