Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Ajax Problem w/ PHP

    I am having a problem with this code - it works normally if i run it as a php script although as soon as i run it through ajax it does nothing - runs all the other code except for this section.

    PHP Code:
    $file_input 'php_template.php';
    $file_output '69696969696969.php';
    $file_open fopen($file_output'w');
    $file_input_read file_get_contents($file_inputtrue);
    fwrite($file_open$file_input_read);        
    fclose($file_open); 

  • #2
    New Coder
    Join Date
    Apr 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts
    No type of file control seems to work... even unlink('pagename.php');
    doesnt work.

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,211
    Thanks
    23
    Thanked 605 Times in 604 Posts
    If it runs great by it's self I would think the problem lies in how it's called via ajax.
    I really don't see anything in this file that needs ajax anyway.
    Why not just make it a function in the page?

    If you insist on using ajax then post the code that calls the ajax and the ajax itself.

    P.S. You just posted.
    What does even unlink('pagename.php') have to do with anything?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    New Coder
    Join Date
    Apr 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    If it runs great by it's self I would think the problem lies in how it's called via ajax.
    I really don't see anything in this file that needs ajax anyway.
    Why not just make it a function in the page?

    If you insist on using ajax then post the code that calls the ajax and the ajax itself.

    P.S. You just posted.
    What does even unlink('pagename.php') have to do with anything?

    Unlink function removes a page - the thing is it needs to be called via ajax - as we want it to automatically update - without the need for the page refreshing - is there any way of working around this? Here is my ajax call:

    Code:
    $(".ajax_form_submission").submit(function(event) {
    	event.preventDefault();
    	
    	var form 		= $(this);
        var formUrl 	= form.attr('action');
        var form_id 	= $('[name=typeid]', form).val();
    	var datasubmit 	= "typeid=" + form_id;
    	
    	// REMOVE PAGE
    	if(form_id == 1){
    		var remove_id = $('[name=remove_id]', form).val();
    		
    		datasubmit += "&remove_id=" + remove_id;
    	}
    	
    	// CALL LIST
    	if(form_id == 2){ 
    	
    	}
    	// ADD PAGE
    	if(form_id == 3){ 
    		var page_name_input = $('[name=page_name_input]', form).val();
    		var find_position = $('[name=find_position]',form).val();
    		
    		datasubmit += "&page_name_input=" + page_name_input + "&find_position=" + find_position;
    	}
    	
    	$.ajax({ 
    	  type: "POST",
    	  url: "plus_cms/connection/process_sql.php",  
    	  data: datasubmit,
    	  success: function(data){
    			alert('yes');
    	  }
    	});  
    	return false;
    	
    });
    The thing is - it executes all the code - although just doesn't work with the file handling of it... its strange.

  • #5
    New Coder
    Join Date
    Apr 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Oh it does remove the pages - just not until you refresh the page you notice the change.

  • #6
    New Coder
    Join Date
    Apr 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Nope i was wrong.. its creating files that dont work not removing them...
    Code:
    	$typeid = protect_my_string($_POST['typeid']);
    			
    		$page_name_input = protect_my_email($_POST['page_name_input']);
    		$find_position = protect_my_email($_POST['find_position']);
    		$find_position2 = $find_position + 1;
    	
    			$url1 = strtolower($page_name_input);
    			$url1_5 = str_replace('  ',' ',$url1);
    			$url2 = str_replace(' ', '_', $url1_5);
    					
    				$file_input = '../php_template.master';
    				$file_output = '69696969696969.php';
    				$file_open = fopen($file_output, 'w');
    				$file_input_read = 'awdaaaaaaaa';//file_get_contents($file_input, true);
    				
    					fwrite($file_open, $file_input_read);		
    					fclose($file_open);
    				
    						$update_queries = mysql_query("SELECT * FROM cms_pages WHERE page_order > $find_position");
    						while($update_row = mysql_fetch_array($update_queries)){
    							$update_order = $update_row['page_order'] + 1;
    							$id = $update_row['page_id'];
    							mysql_query('UPDATE cms_pages SET page_order = "'.$update_order.'" WHERE page_id = "'.$id.'"');
    						}
    			
    							mysql_query("INSERT INTO cms_pages (
    								page_name,
    								page_url,
    								page_order
    							) VALUES (
    								'$page_name_input',
    								'$url2',
    								'$find_position2'
    							)") or die(mysql_error());

  • #7
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,211
    Thanks
    23
    Thanked 605 Times in 604 Posts
    Since I don't know how the file your removing relates to the page your looking at I can't give you exect instructions but I do know where the problem is:
    Code:
    $.ajax({ 
    	type: "POST",
    	url: "plus_cms/connection/process_sql.php",  
    	data: datasubmit,
    	success: function(data){
    		alert('yes');   // This is where you change the HTML and your not.
    	}
    });
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,542
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    He doesn't really care about changing the HTML. He just wants acknowledgement that something has happened, I think.

    Lewis: Permissions problem, perhaps? You *are* aware you are trying write into the same directory where the PHP page is running, no? Normally, web servers disallow that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •