PHP - Uncaught Error: Call To A Member Function Fetch_assoc
Hi everyone, Happy New Year in advance! I have the following error occurring :- while ($row = $query_result->fetch_assoc()) { $result[] = $row; } Which is in this query :- public function DbGetAll($queryString) { $query_result = $this->db->query($queryString); $result = array(); while ($row = $query_result->fetch_assoc()) { $result[] = $row; } return $result; }
I'm guessing it's a problem with the sql query but I'm not sure how to fix? The error log also references this file :- Similar TutorialsHi all, I'm getting the following error, but I cannot see why: ERROR: Fatal error: Call to a member function fetch_assoc() on a non-object in {filepath} on line 36 CODE: Code: [Select] <?php ini_set('display_errors',1); error_reporting(E_ALL); require_once("aconfig.php"); $eid = $_GET["event"]; echo '<html> <head> <title>Admin Control Panel :: PRINT TICKETS</title> <style type="text/css"> body { font-family: Helvetica, Arial; } </style> </head> <body>'; //start classes $db = new db(); //connect to DB //attempt it $sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']); //check for ERR if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // if($eid == "edit"){ echo '<h1>SELECT EVENT</h1> <p>Select an event to print tickets for</p> <p>'; $query = 'SELECT * from `tickets` ORDER by id'; $query = $sql->real_escape_string($query); // Perform Query $result = $sql->query($query); // Loop Through Result while ($row = $result->fetch_assoc()) { echo '− <a href="ptickets.php?event='.$row[id].'">'.$row[event_name].'</a> <br />'; } echo '</p>'; }else { $query2 = 'SELECT * from `orders` WHERE `id` = '.$eid.', paid = "1"'; $query2 = $sql->real_escape_string($query2); // Perform Query $result2 = $sql->query($query2); // Loop Through Result while ($row2 = $result2->fetch_assoc()) { echo '<table cellspacing="1" cellpadding="1" border="1" width="400"> <tbody> <tr> <td colspan="2"><strong>Online Ticket</strong></td> </tr> <tr> <td width="300"> <p>Event: <strong>'.$row2[eventname].'</strong></p> <p>Holder Name: <strong>'.$row2[name].'</strong></p> <p>No. Adult tickets: <strong>'.$row2[adult_tix].'</strong><br /> No. Concession tickets: <strong>'.$row2[concess_tix].'</strong></p> </td> <td> <p><u>STAFF</u></p> <p><em>Rip this side off once ticket holder has entered.</em></p> </td> </tr> </tbody> </table> <p> </p>'; } } echo '</body></html>'; ?> What the script does: if the page is ?event=edit, it lists all the available events. If not, it checks what event id is at ?event and lists that ID from the DB. What's wrong with it? Thanks
Hello everyone Random Error that im getting on my webhost, not localhost. Fatal error: Call to a member function fetch_assoc() on a non-object in /home/*****/index.php on line 127 Line 127: while ($premium = $row->fetch_assoc()) { Code: <div class="toplist-content"> <table cellspacing="0"> <tbody> <?php $row = $home->getList(1); while ($premium = $row->fetch_assoc()) { ?> <tr class="table"> <td class="name"><a href="server.html"> <h3> <?php echo ucfirst($premium['servername']); ?> </a> <font size='1.5'><?php echo ucfirst(substr($premium['serverdesc'],0,25)). "..."; ?> </h3> </font> </td> <td class="revision"><h3> <?php echo ucFirst($premium['revision']); ?> </h3></td> <td class="votes"><h3> <?php echo $premium['vote']; ?> </h3></td> <td class="status"><?php if($home->getStatus($premium['host'], $premium['port']) == true) { echo "<span class='ticket open'>Online</span>"; } else { echo "<span class='ticket closed'>Offline</span>"; } ?> </td> </tr> <?php } ?> </tbody> </table> </div> The getList() function : function getList($premium) { $query = $this->con->query("SELECT * FROM `".$this->prefix."servers` WHERE `premium` = '".$premium."' && `ban` = '0' ORDER BY (SELECT COUNT(*) FROM `".$this->prefix."votes` WHERE `serverId` = '".$this->prefix."servers.id') DESC") or die(mysqli_error()); return $query; } This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 Can anyone help me with this error? Fatal error: Call to a member function require_login() on a non-object in /home/wallls/public_html/index.php on line 27 Lines 26-33 below: <?php $smilek = $_GET['id']; $ppalout = $_GET['payout']; $healthy = array("%", "!", "=", "'", ",", "OR", "?", "<", "&", ";"); $yummy = array("", "", "", "", "" ,"", "", "", "", ""); $peee = str_replace($healthy, $yummy, $smilek); $chnpay = str_replace($healthy, $yummy, $ppalout); require_once 'appinclude.php'; require_once 'mystyle.php'; echo '<div align="center"><img src="'.$appcallbackurl.'main.png" width="300" height="150"></div>'; require_once 'ads/topads.php'; ?> <fb:tabs> <fb:tab-item href='<? echo $appCanvasUrl; ?>' title='Lottery' selected='true' /> <fb:tab-item href='<? echo $appCanvasUrl; ?>earn.php' title='Get Tickets' /> <fb:tab-item href='<? echo $appCanvasUrl; ?>payment.php' title='Payment Info' /> <fb:tab-item href='<? echo $appCanvasUrl; ?>history.php' title='Lottery History' /> <fb:tab-item href='<? echo $appCanvasUrl; ?>forum.php' title='Forum' /> <fb:tab-item href='<? echo $appCanvasUrl; ?>invite.php' title='Invite Friends' /> </fb:tabs> <div align="center"> <? $fbid = $facebook->require_login(); $theirip = $_SERVER['REMOTE_ADDR']; if ($fbid == "") { ?> I am trying to create a class and I ran into a problem. The connect function is returning a fatal error on the line below and I can't figure out the issue. $result = $this->conn->query("SELECT unit FROM address");
class database { private $server = "localhost"; private $db_user = "my user"; private $db_pass = "my pass"; private $db_name = "my database"; private $conn; private $result = array(); function connect(){ // Create connection $this->conn = new mysqli($this->server, $this->db_user, $this->db_pass, $this->db_name); if ($this->conn->connect_error) { echo "Not connected, error: " . $mysqli_connection->connect_error; } else { //echo "Connected."; return $this->conn; } public function displayHeader(){ $result = $this->conn->query("SELECT unit FROM address"); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo '<li>' . $row["unit"] . '</li>'; } } else { echo "0 results"; } $conn->close(); } } }
Hi guys, I am trying to install a script and I am getting this error when loading for the first time kindly assist anyone.
Hi guys. I need some help, because i'm stuck I'm getting this error and cand figure out what im doin wrong. Fatal error: Call to a member function fetch_array() on a non-object in C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php on line 16. The Code around it: Code: [Select] include "../config/config.php"; $host = htmlspecialchars($_SERVER["HTTP_HOST"]); $uri = rtrim(dirname(htmlspecialchars($_SERVER["PHP_SELF"])), "/\\"); $extra = "show_content.php"; if (empty($_POST["titel"])) { $id = (isset($_GET["id"])) ? (int)$_GET["id"] : false; $result = $db->query("SELECT * FROM `content` WHERE `id` = ".$db->real_escape_string($id).""); $row = $result->fetch_array(MYSQLI_ASSOC); $db->free_result; unset($result); } $ide = (isset($_GET["id"])) ? (int)$_GET["id"] : false; $result = $db->query("SELECT `id_position` FROM `content` WHERE `id` = ".$db->real_escape_string($ide).""); $zeile = $result->fetch_array(MYSQLI_ASSOC); ---->This is line 16 $db->free_result; unset($result); $id_position_real = $zeile['id_position']; if ($id_position_real == 1) { $id_position_real = 1; }else{ $id_position_real= 0; } if ($id_position_real == 1) { $id_position_real_none = 0; }else{ $id_position_real_none = 1; } ?> thanks ThatMSG Fatal error: Call to a member function qstr() on a non-object in C:\xampp\htdocs\ipod\functions.php on line 14 <?php require_once('config.php'); function checkwork() { header("location: underwork.php"); echo 'Sorry we are under going work :('; } function get_username ( $id ) { global $db; $query = "SELECT `login` FROM `" . DBPREFIX . "members` WHERE `member_id` = " . $db->qstr ( $id ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); return $row->login; } else { return FALSE; } } ?> this being line 14 $query = "SELECT `login` FROM `" . DBPREFIX . "members` WHERE `member_id` = " . $db->qstr ( $id ); i've tried whit a lot of solutions from other posts but nothing seems to be working
this part is where im having trouble but i dont know how to get it to work
namespace App\Controllers;
class Home extends BaseController
//Set form validation
//Run form validation
//Get the form data
//Web master email
//Mail settings $this->email->initialize($config);
//Send mail with data
redirect('contact');
}
<div class="header">
<a href="javascript:void(0);" class="mobi-toggler"><i class="fa fa-bars"></i></a>
<!-- BEGIN NAVIGATION --> Code: [Select] <?php class OnlineStore { private $DBConnect = NULL; private $storeID = ""; private $inventory = array(); private $shoppingCart = array(); function __construct() { include("inc_OnlineStoreDB.php"); $this->DBConnect = $DBConnect; } function __destruct() { if (!$this->DBConnect->connect_error) $this->DBConnect->close(); } public function setStoreID($storeID) { if ($this->storeID != $storeID) { $this->storeID = $storeID; $SQLstring = "SELECT * FROM inventory " . " where storeID = 'jw" . $this->storeID . "'"; $QueryResult = $this->DBConnect->query($SQLstring); if ($QueryResult === FALSE) { $this->storeID = ""; } else { $this->inventory = array(); $this->shoppingCart = array(); while (($Row = $QueryResult->fetch_assoc()) !== NULL) { $this->inventory[$Row['productID']] = array(); $this->inventory[$Row['productID']]['name'] = $Row['name']; $this->inventory[$Row['productID']]['description'] = $Row['description']; $this->inventory[$Row['productID']]['price'] = $Row['price']; $this->shoppingCart[$Row['productID']] = 0; } } } } public function getStoreInformation() { $retval = FALSE; if ($this->storeID != "") { $SQLstring = "SELECT * FROM store_info " . " WHERE storeID = '" . $this->storeID . "'"; $QueryResult = @$this->DBConnect->query($SQLstring); if ($QueryResult !== FALSE) { $retval = $QueryResult->fetch_assoc(); } } return($retval); } public function getProductList() { $retval = FALSE; $subtotal = 0; if (count($this->inventory) > 0) { echo "<table width='100%'>\n"; echo "<tr><th>Product</th><th>Description</th>" . "<th>Price Each</th><th># in Cart</th>" . "<th>Total Price</th><th> </th></tr>\n"; foreach ($this->inventory as $ID => $Info) { echo "<tr><td>" . htmlentities($Info['name']) . "</td>\n"; echo "<td>" . htmlentities($Info['description']) . "</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $Info['price']); echo "<td class='currency'>" . $this->shoppingCart[$ID] . "</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $Info['price'] * $this->shoppingCart[$ID]); echo "<td><a href='" . $_SERVER['SCRIPT_NAME'] . "?PHPSESSID=" . session_id() . "&ItemToAdd=$ID'>Add " . " Item</a></td>\n"; $subtotal += ($Info['price'] * $this->shoppingCart[$ID]); } echo "<tr><td colspan='4'>Subtotal</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $subtotal); echo "<td>$nbsp;</td></tr>\n"; echo "</table>"; $retval = TRUE; } return($retval); } public function addItem() { $ProdID = $_GET['ItemToAdd']; if (array_key_exists($ProdID, $this->shoppingCart)) $this->shoppingCart[$ProdID] += 1; } } ?> having an issue to where nothing is appearing on the page and getting the Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\PHP\Chapter.10\class_OnlineStore.php on line 24 HERE IS THE MAIN PAGE Code: [Select] <?php session_start(); require_once("class_OnlineStore.php"); $storeID = "COFFEE"; $storeInfo = array(); if (class_exists("OnlineStore")) { if (isset($_SESSION['currentStore'])) $Store = unserialize($_SESSION['currentStore']); else { $Store = new OnlineStore(); } $Store->setStoreID($storeID); $storeInfo = $Store->getStoreInformation(); } else { $ErrorMsgs[] = "The OnlineStore class is not available!"; $Store = NULL; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $storeInfo['name']; ?></title> <link rel="stylesheet" type="text/css" href="<?php echo $storeInfo['css_file']; ?>" /> </head> <body> <h1><?php echo htmlentities($storeInfo['name']); ?></h1> <h2><?php echo htmlentities($storeInfo['description']); ?></h2> <p><?php echo htmlentities($storeInfo['welcome']); ?></p> <?php $Store->getProductList(); $_SESSION['currentStore'] = serialize($Store); ?> </body> </html> I HAVE REVIEWED IT OVER AND OVER AGAIN AND I CANT SEE THE PROBLEM. MAYBE SOMEONE FROM THE OUTSIDE CAN HELP OUT. I'm new to coding and prepared statements.
I'm getting: For this: <?php include "db_connect.php"; if(isset($_POST['UserID'])){ $stmt = $con -> prepare('UPDATE UserList SET Status = ?, FirstName = ?, LastName = ?, Username = ?, Email = ?, Department = ?, Manager = ?, WHERE UserID = ?'); $stmt -> bind_param('isssssss', /* Line 17 */ $_POST['Status'], $_POST['FirstName'], $_POST['LastName'], $_POST['Username'], $_POST['Email'], $_POST['Department'], $_POST['Manager'], $_POST['UserID']); $stmt->execute(); } Thank you in advance for helping. can anyone tell me why im getting this error? Fatal error: Call to a member function fetchrow() on a non-object code being used..... Code: [Select] $comment_query = mysql_query("SELECT * FROM `comments` where video_id='$video[0]' ORDER BY='desc' LIMIT='30'"); while($comments = $comment_query->fetchrow()) { here is my php code. i want to remove the attribute of a tag and then add a new attribure to the tag. simply i want attribute validation. but this code gives me the following error. "Fatal error: Call to a member function getAttributeNode() on a non-object in D:\wamp\www\ReadXml\new.php on line 35" <?php $xml = new DOMDocument(); $doc->recover = true; $xml->load('test.xml'); $node = $xml->getElementsByTagName('*'); $nodename = ""; $node_name = array(); $att = ""; $attr_name = ""; $attr_value = ""; foreach($node as $value) { echo "<HTML><Head>"; echo "<title> Getting Attribute Example</title>"; echo "</Head><body><B>"; echo "Node Name is :".$value->nodeName; echo "<br /><br /></B></body></HTML>"; $nodename = $value->nodeName; $node_name = $xml->getElementsByTagName('$nodename')->item(0); echo $nodename; $att = $node_name->getAttributeNode('name'); //Line No 35 echo "<HTML><Head>"; echo "<title> Getting Attribute Example</title>"; echo "</Head><body><B>"; echo "Node Name is :".$att->name; echo "<BR>Attribute Value is :".$att->value; echo "<br /><br /></B></body></HTML>"; $attr_name = $att->name; $attr_value = '"' . $att->value . '"'; $nodename->removeAttributeNode('$attr_name'); $nodename->setAttributeNode(new DOMAttr('$attr_name', 'hello')); $nodename->setAttribute(new DOMAttr('$attr_name', '$attr_name')); $xml->save('temp2.xml'); } ?> 2 9 0 1 Fatal error: Call to a member function bind_param() on boolean.
It fails on the BIND_PARAM line.
I have looked at this all day, struggling with Mysqli as my normal MySql works fine with assoc and fetch.
I have verified in PhpInfo that mysqli is enabled. I have verified its loaded using <?php print_r(get_loaded_extensions()); Added utf8 just to make sure.
If I manually use the Wrong Password, I get a connection refused error, so I know its connected.
Verified my $_POST variables are there using Print in the 2 9 0 1 above.
All Table and Field Names are correct. Manual Insert works fine in myPhpAdmin. Tried Field Names and ? marks with and without single quotes. All fields are Integers in the table.
Could it be related to an Auto_Increment Field in the table for a record ID that I am not providing?? A normal insert in myPhpAdmin doesn't need it.
$QuestionID = $_POST['qID']; print $QuestionID . " ";
Thanks, CadJoe Edited August 26, 2017 by CadJoeHey all. I am trying to make a mod for our fantasy football site but keep getting an error. Fatal error: Call to a member function Execute() on a non-object in C:\Inetpub\wwwroot\phpffl\program_files\autorun\general\top_team.php on line 8. Here is the code. <?php global $PHP_SELF, $DB; $leagues_ID='1'; $week='2'; $week_ID=$week -1; $game_ID=$week_ID; $sql="select ID, team_name from teams where leagues_ID='$leagues_ID';"; [b] $teams_rs=$DB->Execute($sql);[/b] while (!$teams_rs->EOF) { $top_team_ID=$teams_rs->fields('ID'); $top_team_name=$teams_rs->fields('team_name'); $top_team_points=get_total_points_game($top_team_ID, $week_ID, $week_ID, $leagues_ID); //echo $top_team_points." "; $top_team_points_array[$top_team_name]=$top_team_points; $teams_rs->MoveNext(); } $top_scoring_team_ID=""; $top_scoring_team_name=""; $top_scoring_points=""; foreach(array_keys($top_team_points_array) as $key) { if ($top_team_points_array[$key] > $top_scoring_points) { $top_scoring_points=$top_team_points_array[$key]; //$top_scoring_team_ID=$top_team_ID; $top_scoring_team_name=$key; } } $sql="insert into total_scores (team_ID, teams_name, week_id, total_score, leagues_ID) values('$top_team_ID', '$top_scoring_team_name', '$week_ID', '$top_scoring_points', '$leagues_ID');"; $rs=$DB->Execute($sql); echo "<br>"; echo "<br>"; echo "Weekly Top Scoring Team for Week $week_ID is: $top_scoring_team_name with a score of $top_scoring_points points!"; echo "<br>"; echo "<br>"; //print_r ($top_team_points_array); echo "<br>"; echo "<br>"; $weekly_top_score=max($top_team_points_array); ?> I have a function in the global file looks like this. /************** BEGIN ADDITIONAL FUNCTIONS **************************/ function get_top_scoring_teams() { global $PHP_SELF, $DB, $PHPFFL_IMAGE_PATH; $sql="select * from total_scores order by week_ID DESC limit 1;"; $teams_rs=$DB->Execute($sql); while (!$teams_rs->EOF) { $team_ID=$teams_rs->fields('team_ID'); $team_name=$teams_rs->fields('teams_name'); $team_points=$teams_rs->fields('total_score'); $week_ID=$teams_rs->fields('week_ID'); echo "The Top Scoring Team for <strong>Week $week_ID</strong> was <br><img src='{$PHPFFL_IMAGE_PATH}team_logos_standings/$team_ID.gif'><br> <strong>$team_name</strong> with a score of <strong>$team_points</strong> points. <hr>"; $teams_rs->MoveNext(); } } /************** BEGIN ADDITIONAL FUNCTIONS**************************/ Any one see what the issue might be? I am running this on a windows 2003 server with iis 6 php 5.3 and mysql 5.1.5 Any help would be appreciated. Thanks Hitster4 Hello guys I'm pulling out my last remaining hairs with this PHP problem. I'm not really good at PHP but I'm trying to do some changes to a script as instructed by the developer, but apparently I got some wrong instructions. The error I get is: Fatal error: Call to a member function postage_country_display() on a non-object in file.php on line 34 I've been searching the web high and low and can't seem to find a solution. Does anyone have a hint at what might be wrong? Here is the code that's causing the problem and the class. Code: Code: [Select] $template->set('items_id', intval($_REQUEST['items_id'])); $item_details = $db->get_sql_row("SELECT * FROM " . DB_PREFIX . "items WHERE items_id='" . intval($_REQUEST['items_id']) . "'"); $unCountryPrice = unserialize(stripslashes($db->add_special_chars($item_details['country_postage']))); // print_r($unCountryPrice); $postageCountry = $item->postage_country_display($unCountryPrice,$item_details['currency']); $template->set('postageCountry', $postageCountry); $template->set('item_details', $item_details); And here is the class: Code: [Select] function postage_country_display($unCountryPrice,$currency) { if (is_array($unCountryPrice)) { $postageCountry = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> "; $fees = new fees(); while (list($k,$v)= each($unCountryPrice)){ $cQueyr = $this->query("SELECT a.name as name1,b.name as name2 FROM " . DB_PREFIX . "countries a LEFT JOIN " . DB_PREFIX . "countries b ON (a.parent_id = b.id) WHERE a.id = '". $k ."'"); $cRow = $this->fetch_array($cQueyr); $postageCountry.="<tr><td>". ($cRow['name2']==""?$cRow['name1']:$cRow['name2'].' > '.$cRow['name1']) ."</td><td> ".$currency.' '.number_format($v,2)."</td></tr>"; } $postageCountry.="</table>"; } return $postageCountry; Hey guys, I have spent the last 36 hours trying to figure this out. I keep getting the following error: Fatal error: Call to a member function format() on a non-object in /var/www/vhosts/xxxxx.com/httpdocs/admin/defaults.php on line 51 The reason I am not using the standard date and strtotime functions is because some of my dates exceed 2038. What I have done is created an array with price and days from today within the array. You can see below where I am trying to get the timestamp for 14000 days from today. I then turn that into a date using the newdate function. I can see that this actually works on other pages on my server, I just can't figure out why it won't work here. BTW, I am using php 5.2.3. $csv .= "Payment,".newdate("m/d/Y",newstrtotime("+".$periodic[0][0]." days")).",".$row['amount'].",".count($periodic).",".$row['frequency'].",".newdate("m/d/Y",newstrtotime("+".$periodic[$perCt][0]." days"))."\n"; function newstrtotime($strtotime){ $datetime = date_create($strtotime); return $datetime->format("U"); } function newdate($format,$timestamp){ $datetime = date_create("@$timestamp"); return $datetime->format($format); } Let me know what you think. I can call the following function successfully as a single php program // Acknowledge and clear the orders function ack($client, $merchant, $id) { $docs = array('string' => $id); $params = array('merchant' => $merchant, 'documentIdentifierArray' => $docs); $result = $client->call('postDocumentDownloadAck', $params); return $result; } with $result = ack($t, $merchant,'2779540483'); successful output [documentDownloadAckProcessingStatus] => _SUCCESSFUL_ [documentID] => 2779540483 I'm trying to figure out how to call this function as an object from another program. Trying the following gives error ***Call to a member function call() on a non-object*** function postDocumentDownloadAck($t, $merchant, $id) { $this->error = null; $docs = array('string' => $this->id); $params = array('merchant' => $this->merchant, 'documentIdentifierArray' => $docs); ** I've tried the following which does nothing $result = $this->soap->call('postDocumentDownloadAck', $params); ** I've tried the following - which gives error "Call to a member function call() on a non-object" $result = $this->t->soap->call('postDocumentDownloadAck', $params); if($this->soap->fault) { $this->error = $result; return false; } return $result; } *** calling program snippet for above function $merchant= array( "merchant"=> $merchantid, "merchantName" => $merchantname, "email"=> $login, "password"=> $password); $t = new AmazonMerchantAPI($merchantid, $merchantname, $login, $password); $documentlist= $t->GetAllPendingDocumentInfo('_GET_ORDERS_DATA_'); $docid = $documentlist['MerchantDocumentInfo'][$i]['documentID']; $docs = array('string' => $docid); $ackorders = $t->postDocumentDownloadAck($t, $merchant,$docs); Any ideas of what I'm doing wrong are greatly appreciated. I get this error when I run my login system. Call to a member function bind_param() on a non-object in /models/class.newuser.php on line 131This is the modified code (Line 131 is on the top line): $stmt->bind_param("ssssi", $this->username, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active); $stmt->execute(); $inserted_id = $mysqli->insert_id;$stmt->close(); //Insert default permission into matches table $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."user_permission_matches ( user_id, permission_id ) VALUES ( ?, '1' )") ; $stmt->bind_param("s", $inserted_id); $stmt->execute(); $stmt->close();This is the whole code... <?php /* . . */ class User { public $user_active = 0; private $clean_email; public $status = false; private $clean_password; private $username; public $sql_failure = false; public $mail_failure = false; public $email_taken = false; public $username_taken = false; public $activation_token = 0; public $success = NULL; function __construct($user,$pass,$email) { //Sanitize $this->clean_email = sanitize($email); $this->clean_password = trim($pass); $this->username = sanitize($user); if(usernameExists($this->username)) { $this->username_taken = true; } else if(emailExists($this->clean_email)) { $this->email_taken = true; } else { //No problems have been found. $this->status = true; } } public function userCakeAddUser() { global $mysqli,$emailActivation,$websiteUrl,$db_table_prefix; //Prevent this function being called if there were construction errors if($this->status) { //Construct a secure hash for the plain text password $secure_pass = generateHash($this->clean_password); //Construct a unique activation token $this->activation_token = generateActivationToken(); //Do we need to send out an activation email? if($emailActivation == "true") { //User must activate their account first $this->user_active = 0; $mail = new userCakeMail(); //Build the activation message $activation_message = lang("ACCOUNT_ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token)); //Define more if you want to build larger structures $hooks = array( "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"), "subjectStrs" => array($activation_message,$this->activation_token,$this->username) ); /* Build the template - Optional, you can just use the sendMail function Instead to pass a message. */ if(!$mail->newTemplateMsg("new-registration.txt",$hooks)) { $this->mail_failure = true; } else { //Send the mail. Specify users email here and subject. //SendMail can have a third parementer for message if you do not wish to build a template. if(!$mail->sendMail($this->clean_email,"New User")) { $this->mail_failure = true; } } $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2"); } else { //Instant account activation $this->user_active = 1; $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1"); } if(!$this->mail_failure) { //Insert the user into the database providing no errors have been found. $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users ( user_name, password, email, activation_token, last_activation_request, lost_password_request, active, title, sign_up_stamp, last_sign_in_stamp ) VALUES ( ?, ?, ?, ?, ?, '".time()."', '0', ?, 'New Member', '".time()."', '0' )"); $stmt->bind_param("ssssi", $this->username, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active); $stmt->execute(); $inserted_id = $mysqli->insert_id; $stmt->close(); //Insert default permission into matches table $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."user_permission_matches ( user_id, permission_id ) VALUES ( ?, '1' )") ; $stmt->bind_param("s", $inserted_id); $stmt->execute(); $stmt->close(); } } } } ?> |