Jump to content

Sql query printing to page as appose to executing. please help


deansaddigh

Recommended Posts

Heres the code

 

[/* Header.php holds db object string*/
	include('lib/includes/header.php');

	/* sql query to find if email address exists for client*/
	$emailquery = "SELECT id FROM clients WHERE email = '$email'";
	$db->execute($emailquery);

	/*get client id from query*/

	$clientid = $emailquery;
	echo $clientid;


	/*If statment to find if email exists in client table*/

	if($emailquery !='')
		{
			echo "there is a record";
		}
		else 
		{

			$today = date("d.m.y");  
			$brochureSQL = "INSERT INTO brochure VALUES ('', '$today', 'Unread', '1234')";
			$db->execute($brochureSQL);
		}

 

any ideas it prints this to the page

SELECT id FROM clients WHERE email = 'dfgdf'there is a record

I dont know someone wrote this code before me, but i know that works, i belive it executes the sql statment because this works.

 

$today = date("d.m.y");  
			$brochureSQL = "INSERT INTO brochure VALUES ('', '$today', 'Unread', '1234')";
			$db->execute($brochureSQL);

Thanks soooo much i spent ages trying to figure that out.

 

With this code

 

/* sql query to find if email address exists for client*/
	$emailquery = "SELECT id FROM clients WHERE email = $email";
	$db->execute($emailquery);

	/*get client id from query*/

	$clientid = $emailquery;

 

Hopefully that should bring back an idea if one exists, how do i print what it returns, to see if its working correctly

Found it

 

	// Performs a SQL statement and return the number of rows effected. Used for updates and inserts.
        public function execute($SQL)
        {
                $result = mysql_query($SQL, $this->Conn);

                if ($result)
	{
                	return mysql_affected_rows($this->Conn);
	}
	else
	{
		$this->err = mysql_error($this->Conn);
		return -1;
	}

        }

i found this as well

 

// Perform a SQL statement and retrieve a resultset. Return this result set as an multidimensional array
        public function query($SQL)
        {
                $resultSet = array();

                $result = mysql_query($SQL, $this->Conn);

                if ($result)
                {
                        if (mysql_num_rows($result) > 0)
                        {
                                while ($row = mysql_fetch_assoc($result))
                                {
                                        $resultSet[] = $row;
                                }
                        }

                        return $resultSet;
                }
                else
                {
                     $this->err = mysql_error($this->Conn);
                     return null;
                }
        }

Archived

This topic is now archived and is closed to further replies.

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