Advanced Search

Results 1 to 8 of 8

Thread: Insertion is not happening while using PDO codes along with plain php script

  1. #1
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Question Insertion is not happening while using PDO codes along with plain php script

    Hello everybody.

    Got a problem at inserting data to database. i.e when i m using the pdo script with
    a php script having session. the data is not inserted. but data insertion executes
    successfully while i use that PDO script individually.

    you may view the link http://www.codeofaninja.com/2013/05/...hp-jquery.html

    which i followed. Now my

    language.php contains :

    Code:
    <?php
    session_start();
    error_reporting(E_ALL | E_STRICT);
    /*****************************************************************************
    
    /*****************************************************************************/
    include_once('includes/queryfunctions.php');
    include_once('includes/functions.php');
    $conn=mysql_connect(HOST . ":" . PORT , USER, PASS);
    if (!$conn) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db(DB);
    
    //check if user is logged in
    SignedIn();
    
    //check if user has clicked on logout button
    if(isset($_POST["submit"]) && $_POST["submit"]=='Logout') LogOut();
    
    if(isset($_GET["search"]) && !empty($_GET["search"])){
    	//have this as a search function
    	$id=$_GET["search"];
    	$_POST["submit"]=$_GET["action"];
    }
    
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>language</title>
    	<link rel="stylesheet" type="text/css" href="css/internal.css"/><link href="css/main.css" rel="stylesheet" type="text/css">
    	<link rel="stylesheet" type="text/css" href="css/epoch_styles.css"/>
    <?php headericon(); ?>
    
    </head>
    <body bgcolor="#FFFFFF">
    <form action="language.php" method="post" name="language" id="language" enctype="multipart/form-data">
    <div align="center">
    <table width="92%">
     <tr>
       <td colspan="3" align="right"><?php mainheader(); ?></td>
     </tr>
      <tr align="center">
       <th colspan="3" align="right"><img src="images/head.png" width="100%" height="95px" /></th>
     </tr>
     <tr>
       <th><?php loginheader(); ?></th>
       <th colspan="2"><?php profileheader(); ?></th>
     </tr>
     <tr>
     <td width="20%" valign="top" align="left"><?php leftmenu(); ?></td>
     <td colspan="2" valign="top" align="left"><table border="0" width="100%">
        <tr>
          <th colspan="3" bgcolor="#CCCCCC"><strong>LANGUAGE</strong></th>
        </tr>
        <tr>
          <td colspan="2"><em>Currently no data exist! Please click on the following button to add language information.</em></td>
        </tr>
    <tr>
          <td colspan="3" bgcolor="#fff">	
    <div style='margin:0 0 .5em 0;'>
    	<!-- when clicked, it will load the add user form -->
    	<div id='addLanguage' class='customBtn'>Add New</div>
    
    	<!-- when clicked, it will show the user's list -->
    	<div id='viewLanguages' class='customBtn'>View Existing</div>
    
    
    	
    	<!-- this is the loader image, hidden at first -->
    	<div id='loaderImage'><img src='images/ajax-loader.gif' /></div>
    	
    	<div style='clear:both;'></div>
    </div>
    <!-- this is wher the contents will be shown. -->
    <div id='pageContent'></div>
    
    <script src='js/jquery-1.9.1.min.js'></script>
    
    <script type='text/javascript'>
    $(document).ready(function(){
    	
    	// VIEW USERS on load of the page
    	$('#loaderImage').show();
    	showUsers();
    	
    	// clicking the 'VIEW USERS' button
    	$('#viewLanguages').click(function(){
    		// show a loader img
    		$('#loaderImage').show();
    		
    		showUsers();
    	});
    	
    	// clicking the '+ NEW USER' button
    	$('#addLanguage').click(function(){
    		showCreateUserForm();
    	});
    
    	// clicking the EDIT button
    	$(document).on('click', '.editBtn', function(){ 
    	
    		var user_id = $(this).closest('td').find('.userId').text();
    		console.log(user_id);
    		
    		// show a loader image
    		$('#loaderImage').show();
    
    		setTimeout("$('#pageContent').load('update_form.php?user_id=" + user_id + "', function(){ $('#loaderImage').hide(); });",1000);
    		
    	});	
    	
    	
    	// when clicking the DELETE button
        $(document).on('click', '.deleteBtn', function(){ 
            if(confirm('Are you sure?')){
    		
                // get the id
    			var user_id = $(this).closest('td').find('.userId').text();
    			
    			// trigger the delete file
    			$.post("delete.php", { id: user_id })
    				.done(function(data) {
    					// you can see your console to verify if record was deleted
    					console.log(data);
    					
    					$('#loaderImage').show();
    					
    					// reload the list
    					showUsers();
    					
    				});
    
            }
        });
    	
    	
        // CREATE FORM IS SUBMITTED
         $(document).on('submit', '#addLanguageForm', function() {
    
    		// show a loader img
    		$('#loaderImage').show();
    		
    		// post the data from the form
    		$.post("create_lang.php", $(this).serialize())
    			.done(function(data) {
    				// 'data' is the text returned, you can do any conditions based on that
    				showUsers();
    			});
    	 			
            return false;
        });
    	
        // UPDATE FORM IS SUBMITTED
         $(document).on('submit', '#updateUserForm', function() {
    
    		// show a loader img
    		$('#loaderImage').show();
    		
    		// post the data from the form
    		$.post("update.php", $(this).serialize())
    			.done(function(data) {
    				// 'data' is the text returned, you can do any conditions based on that
    				showUsers();
    			});
    	 			
            return false;
        });
    	
    });
    
    // READ USERS
    function showUsers(){
    	setTimeout("$('#pageContent').load('read.php', function(){ $('#loaderImage').hide(); });", 1000);
    }
    
    // CREATE USER FORM
    function showCreateUserForm(){
    	// show a loader image
    	$('#loaderImage').show();
    	
    	setTimeout("$('#pageContent').load('create_form_lang.php', function(){ $('#loaderImage').hide(); });",1000);
    }
    </script>
    
     </td>
        </tr>
        </table></td>
     <tr><td height="26" colspan="3" align="center"><?php footer(); ?></td></tr>
    </table>
    </div>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default

    Please help.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,627
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by megha_3000 View Post
    Please help.
    Biggest problem I see here is that you're asking how to fix code using PDO, but you're showing us code that doesn't use PDO.

    Your question is unclear.
    Please provide more information, and be as specific as possible.
    • What do you want to accomplish?
    • What have you already tried?
    • What problems did you encounter?

    Please be sure that you have included all relevant code and/or a link to the page in question.
    You might also consider making a reduced test case.
    Last edited by traq; 06-20-2013 at 05:57 AM.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  4. #4
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default

    i m trying to make it clear to you. i.e a couple of days ago i wrote a forum content at javascript How do i process the list and option field form element in CRUD with jQuery and PHP. Their accomplished a CRUD operation using PDO.

    What do you want to accomplish?
    i want to use that code with this form language_new1.php which is using a session.
    What have you already tried?
    Now i m trying to use that code with a form which is using a session. i examined that when i use session at the begining of that code then insertion doesn't happend. like in this code. where session is used at first.
    What problems did you encounter?
    insertion is not happening. as well as edit and delete also not occuring.

    my sample codes are as folows:

    queryfunctions.php
    Code:
    <?php
    //session_start();
    require_once("config.php");
    error_reporting(E_ALL | E_STRICT);
    
    
    function db_connect($HOST,$USER,$PASS,$DB)
    {
    	$conn = mysql_connect($HOST, $USER, $PASS);
    	mysql_select_db($DB);
    	return $conn;
    }
    
    //close a connection
    function db_close($conn)
    {
    	mysql_close($conn);
    }
    
    function query($strsql,$conn)
    {
    	$rs = mysql_query($strsql,$conn);
    	return $rs;
    }
    
    function num_rows($rs)
    {
    	return @mysql_num_rows($rs); 
    }
    
    function fetch_array($rs)
    {
    	return mysql_fetch_array($rs);
    }
    
    function fetch_object($rs)
    {
    	return mysql_fetch_object($rs);
    }
    
    function free_result($rs)
    {
    	@mysql_free_result($rs);
    }
    
    function data_seek($rs,$cnt)
    {
    	@mysql_data_seek($rs, $cnt);
    }
    
    function error()
    {
    	return mysql_error();
    }
    ?>
    <?php
    	define("HOST", "hostname");
    	define("USER", "username");
    	define("PASS", "");
    	define("DB", "databasename");
    /*	define("smptserver",'smtpserver');
    	define("supportemail",'emailadress');
    	define("bcc",'emailaddress');		
    */?>

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,627
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    so, no changes to the records in your database. Is there an error? Are your SQL statements being sent? Is your form submission being processed successfully? Is your form submission being submitted successfully?

    When you say no data is being "inserted," are you talking about when you use this function to submit the form?
    Code:
    // CREATE FORM IS SUBMITTED
         $(document).on('submit', '#addLanguageForm', function() {
    
    		// show a loader img
    		$('#loaderImage').show();
    		
    		// post the data from the form
    		$.post("create_lang.php", $(this).serialize())
    			.done(function(data) {
    				// 'data' is the text returned, you can do any conditions based on that
    				showUsers();
    			});
    	 			
            return false;
        });
    In your .done() method, you can use the server's response to your form submission to debug: just add lots of messages about what the script is doing, and then echo them. It will come back to your script through the AJAX response.
    Code:
    // CREATE FORM IS SUBMITTED
         $(document).on('submit', '#addLanguageForm', function() {
    
    		// show a loader img
    		$('#loaderImage').show();
    		
    		// post the data from the form
    		$.post("create_lang.php", $(this).serialize())
    			.done(function(data) {
    
    				// change your PHP script to echo/print your debugging info
    				//  (e.g., "parsed SQL statement: $sql"
    				//   or "mysqli->query returned TRUE").
    				//  error messages should come back in the response as well.
    				console.log( data );
    				// chrome has the console.log method; I don't know what other browsers support.
    				// you could even use alert(), if you want.
    
    				// 'data' is the text returned, you can do any conditions based on that
    				showUsers();
    			});
    	 			
            return false;
        });
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  6. #6
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default

    Hello,
    In your .done() method, you can use the server's response to your form submission to debug
    yes i added that but didn't got any message. https://gist.github.com/megha3000/e9f6f98a5e7a57a08491
    have a look at this

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,627
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Right after you start your session, print "something" - that will let you know if you're even getting to the page:
    PHP Code:
    <?php
    //include database connection
    session_start();

    print 
    "hello";

    //include_once('includes/queryfunctions.php');
    include 'libs/db_connect.php';

    /* snip */
    You could add a fail method in your js, too:
    Code:
    // CREATE FORM IS SUBMITTED
         $(document).on('submit', '#addLanguageForm', function() {
    
    		// show a loader img
    		$('#loaderImage').show();
    		
    		// post the data from the form
    		$.post("create_lang.php", $(this).serialize())
    		.done(function(data) {
    			// 'data' is the text returned, you can do any conditions based on that
    			showUsers();
    		})
    		.fail(function(jqXHR, textStatus, errorThrown) {
    		    alert( errorThrown );
    		});
    	 			
            return false;
    });
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  8. #8
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default

    Right after you start your session, print "something" - that will let you know if you're even getting to the page:
    Tried as you stated but fails to print.
    You could add a fail method in your js, too:
    That also doesn't show anything.

Similar Threads

  1. insertion sort
    By ggalan in forum PHP
    Replies: 4
    Last Post: 10-05-2010, 03:24 AM
  2. why is this happening
    By silver163 in forum HTML
    Replies: 0
    Last Post: 10-24-2009, 10:07 PM
  3. Looking For A Script To Hide All Source Codes
    By Jixel in forum Looking for such a script or service
    Replies: 2
    Last Post: 08-27-2007, 02:36 AM
  4. Dynamic Textarea Insertion
    By Moranor in forum JavaScript
    Replies: 3
    Last Post: 01-31-2007, 05:35 PM
  5. Whats happening??
    By shachi in forum The lounge
    Replies: 4
    Last Post: 07-04-2006, 06:58 AM

Bookmarks

Posting Permissions

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