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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Post Why record is not inserted in the DB

    Dears
    I am new to OOP Php. for now i am entangled at very initial level i.e. data insertion into db. I simply passed the insert query to a variable in simple php file, which i further get in class function executeQuery(). Although, on echoing $query variable shows right output yet, i cannot find out why data is not going to database. The class code is as under:

    Code:
    <?php
    class DBCon
    {
    	var $con;
    	function getCon()
    	{
    		$hostname = 'localhost';
    		$dbuser = 'root';
    		$dbpassword = '';
    		
    		$con=mysql_connect($hostname,$dbuser,$dbpassword);
    		if(!$con)
    		{
    			die('cannot connect db'.mysql_error());
    		}
    		mysql_select_db("studyco",$con);
    		return $con;
    	}
    
            //Queries
    	function executeQuery($query)
    	{
    		if($query!= null)
    		{
    			mysql_query($query);
    			echo 'record added'.$query;
    		} 
    			else 
    			{
    				echo 'not added';
    			}
    	}	
    	function destruct()
    	{
    		mysql_close();
    	}
    }
    ?>
    i would be extremely obliged for anyone's help in this regard.

    Thanks
    Qaiser

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    		if($query!= null)
    		{
    			mysql_query($query) or exit(mysql_error());
    			echo 'record added'.$query;
    		}

  • Users who have thanked MattF for this post:

    qaiser_nazir (12-24-2010)


  •  

    Tags for this Thread

    Posting Permissions

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