deansaddigh Posted January 5, 2010 Share Posted January 5, 2010 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 Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/ Share on other sites More sharing options...
Mchl Posted January 5, 2010 Share Posted January 5, 2010 What is $db? Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988803 Share on other sites More sharing options...
deansaddigh Posted January 5, 2010 Author Share Posted January 5, 2010 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); Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988804 Share on other sites More sharing options...
Mchl Posted January 5, 2010 Share Posted January 5, 2010 Nevermind. Just look at your code: $emailquery = "SELECT id FROM clients WHERE email = '$email'"; $clientid = $emailquery; echo $clientid; you ask it to echo the query string so that's what it does. Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988807 Share on other sites More sharing options...
deansaddigh Posted January 5, 2010 Author Share Posted January 5, 2010 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 Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988813 Share on other sites More sharing options...
Mchl Posted January 5, 2010 Share Posted January 5, 2010 Can you possibly find and post code for execute() method? Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988814 Share on other sites More sharing options...
deansaddigh Posted January 5, 2010 Author Share Posted January 5, 2010 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; } } Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988818 Share on other sites More sharing options...
deansaddigh Posted January 5, 2010 Author Share Posted January 5, 2010 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; } } Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988822 Share on other sites More sharing options...
deansaddigh Posted January 5, 2010 Author Share Posted January 5, 2010 Its ok i have this working now. Link to comment https://forums.phpfreaks.com/topic/187243-sql-query-printing-to-page-as-appose-to-executing-please-help/#findComment-988874 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.