Jump to content

DLR

Members
  • Posts

    66
  • Joined

  • Last visited

Posts posted by DLR

  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. 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

  3. 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.

  4. 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']);

  5. 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>
    

  6. 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

  7. 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.

  8. 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?

     

  9. 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

  10. 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.

  11. 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.

  12. 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.

     

  13. 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');

  14. Please see if you can see the mistake I must be making. I keep getting the error

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@signforce.co.za AND client_dbase = signforce AND worker_status = 1' at line 2

     

    $a = $_SESSION['worker_name'];
    $b = $_SESSION['worker_email'];
    $c = $_SESSION['client_database'];
    
    $query = "SELECT * FROM staff 
    WHERE worker_name = $a AND worker_email = $b AND client_dbase = $c AND worker_status = 1 ";
    
    $result = mysql_query($query) or die(mysql_error());
    

    This should be sooooooo simple!

     

    Thanks

  15. Thanks,

     

    herewith the basic structure.

    <input type="text" name="width">  // this variable MUST have a value
    <input type="text" name="depth">  // this variable may be null
    
    //now validate inputs
    foreach($_POST as $name => $value) {
         $errors[]  = validate_dimension($value,$name);	
    }
    
    function validate_dimension($value,$name) {
    
    if(! isset($_POST[$name]) OR $_POST[$name] == "" OR $_POST[$name] == 0) {
    return "<span style='color:red;'>Dimension for " .$name . " required</span>";
    
    } else {
    		  			  
    $_SESSION[$name] = htmlentities($value);
    }
    

    Is there a way to "flag" or "switch" the validation so that some variables may have a nul value and not show an error message?

  16. Thank you. I really appreciate your assistance. I have learnt a lot.

     

    Perhaps you could assist me further?

     

    Some of the $_POST variables are permitted to be nul. But the validate function will mark any nul input as an error.

    So the fixed error message becomes inappropriate.

     

    I have tried to add a "flag" to the variable so I can permit a nul input, but cannot see a way to do this.

    Is there perhaps another elegant way to solve this?

     

    Many thanks for your time.

  17. I have created a function to validate input.

     

    function validate_dimension($value,$name) {

     

    global $errors;

    $errors = array();

     

    ......validation actions here - this all works fine - if I get an error it is captured like this  . . .

     

    $errors[] = "Dimension value missing";

     

    This is all fine and the $error is returned correctly.

     

    So that I can keep the error, I save it as a Session variable

     

    $_SESSION['errors'] = $errors;

     

    HOWEVER the next time I run the function (with the next dimension to be checked) , $_SESSION['errors'] is overwritten and the first error is lost.

     

    I have solved the problem by creating a new array - $all_errors - and adding $errors to $all_errors each time the function is run - but this seems clumsy - I do not need the function as I could just as easily wite a separate line of code for each dimension to be checked.

     

    Can anyone suggest a better way of doing this?

    Please?

     

     

  18. my understanding is that the time is stored as an epoch timestamp in the format 0000-00-00 00:00:00 (year-month-day hours:minutes:seconds).

     

    So you need to convert this each time you want to show a date.

     

    What I do is get the date in MYSQL using SELECT like:

     

    $sql = "SELECT * FROM your_table";

    $res = mysql_query($sql);

     

    $row = mysql_fetch_array($res);

     

    $show = $row['time_in_mysql_table'];

     

    //convert to time format

    $show = strtotime($show)

     

    //format to time you want

    echo strftime('%d %b %Y,$show)  // use different formatting symbols depending on your needs

     

  19. HI,

    I want to creat a new table using partial dat from an existing table, but I cannot get my code to work.

     

    Existing table = company_list

    I have created the new table 'newlist' with a autoincrement column

     

    I want to end up with a new table that holds a unique list of names (taken from company_list) and have a unique number assisgned to it (by auto increment).

     

    $sql = "INSERT INTO newlist.co_name

    SELECT company_list.company_name

    FROM company_list ";

     

    $res = mysql_query($sql) or die;

     

    I get no records added to table  newlist

    Thanks for the assistance.  :'(

  20. HI thanks for the comment.

     

    I want to identify if there are any characters that should not be there - like < ' " !@#$%^& etc.

     

    If the $_POST['branch '] has any of these, I'll assume that someone is messing with the input and exclude the post.

     

    So I assumed that [^a-zA-Z0-9] would match any thing that is NOT a letter or a number.

     

     

     

  21. HI, thanks. I've tested your suggestion and it seems to make no difference.

     

    Also I understand that the "^" needs to be inside like this [^a-zA-Z0-9] , as opposed to ^[a-zA-Z0-9] . . is this correct?

     

    Also, my understanding of the "$" sign is to have the pattern matched at the end of a string . . . is this also correct?

     

    ??? David

     

     

×
×
  • 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.