Search the Community
Showing results for tags 'pdo'.
-
What's up guys! Can somebody please explain the meaning of PDO::PARAM_INT in the following statement: $pdoStmt->bindValue(":num", $num, PDO::PARAM_INT); I have already created a PDO Statement object called $pdoStmt. This line will bind the value of $num to the placeholder called :num. I know that PDO::PARAM_INT is a Predefined Constant but what does it do in this case? Thanx
- 3 replies
-
- pdo::param_int
- pdo
-
(and 1 more)
Tagged with:
-
Hi I'm trying to post and validate a form but it doesn't seem to work and it doean't display any errors Here's the code <?php include("config.php"); session_start(); ?> <?php // define variables and initialize with empty values $rateErr = $comErr = ""; $rating = $comment = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_POST["rating"] == "") { $rateErr = "Rate the app"; } else { $rating= $_POST["rating"]; } if (empty($_POST["comment"])) { $comErr = "Missing"; } else { $comment = $_POST["comment"]; } if ($rateErr == "" && $comErr == "") { try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "INSERT INTO reviews (rating, content, appID, user) VALUES(:rating, :comment, :appID, :username)"; $stmt = $con->prepare( $sql ); $stmt->bindValue( ":rating", $rating); $stmt->bindValue( ":comment", $comment); $stmt->bindValue( ":appID", $_GET['id']); $stmt->bindValue( ":username", $_SESSION['username']); $stmt->execute(); return "Submitted successfully"; }catch( PDOException $e ) { return $e->getMessage(); } } } ?> <html> <head> </head> <body> <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <select name="rating"> <option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <span class="error"><?php echo $rateErr;?></span> <br /> <textarea rows="4" cols="50" name="comment" value="<?php echo htmlspecialchars($comment);?>"> Enter text here...</textarea> <span class="error"><?php echo $comErr;?></span> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
-
So I have this CMS that I have spent the last 5 years building and rebuilding and updating blah blah. It's a fairly extensive piece work and I am now looking at converting the entire system over to OOP. I am fairly new to OOP but understand the easy basics of it. I do fight with the concept of when to make a class and when to just make a normal function. I have many functions that I built specific to how my system works and some I suppose could be grouped into categories but then many others are just plain functions that only serve one purpose and may only be a few lines long. I will be using the spl_autoload_register() to load the classes as needed which is obviously much easier than including all the function pages that are needed. So for that reason I like the idea of making classes for everything but it just seems like more than is needed. So what I am looking for is some insight as to when and how to decide if a class should be made and whether to group functions by category to limit the amount of classes OR to just leave them as normal functions. Here is a example function for creating a thumbnail. I would guess that I could make a class called Thumb and put this in it, but what exactly would be the benefit of that based on the syntax of the function AND could you show me how you would convert this to OOP to make it worth while putting it in a class? // Creates a thumbnail function createThumb($img, $type, $dest = NULL, $xy = NULL) { if($type=="admin_product") { $thumb_width = $GLOBALS['admin_thumb_width']; $thumb_height = $GLOBALS['admin_thumb_height']; } elseif($type=="custom") { $thumb_width = ($dest !== NULL) ? $xy['x'] : (int)$_GET['width']; $thumb_height = ($dest !== NULL) ? $xy['y'] : (int)$_GET['height']; } $src_size = getimagesize($img); if($src_size['mime'] === 'image/jpg') {$src = imagecreatefromjpeg($img);} elseif($src_size['mime'] === 'image/jpeg') {$src = imagecreatefromjpeg($img);} elseif($src_size['mime'] === 'image/pjpeg') {$src = imagecreatefromjpeg($img);} elseif($src_size['mime'] === 'image/png') {$src = imagecreatefrompng($img);} elseif($src_size['mime'] === 'image/gif') {$src = imagecreatefromgif($img);} $src_aspect = round(($src_size[0] / $src_size[1]), 1); $thumb_aspect = round(($thumb_width / $thumb_height), 1); if($src_aspect < $thumb_aspect)//Higher { $new_size = array($thumb_width, ($thumb_width / $src_size[0]) * $src_size[1]); $src_pos = array(0, (($new_size[1] - $thumb_height) * ($src_size[1] / $new_size[1])) / 2); } elseif($src_aspect > $thumb_aspect)//Wider { $new_size = array(($thumb_height / $src_size[1]) * $src_size[0], $thumb_height); $src_pos = array((($new_size[0] - $thumb_width) * ($src_size[0] / $new_size[0])) / 2, 0); } else//Same Shape { $new_size = array($thumb_width, $thumb_height); $src_pos = array(0, 0); } if($new_size[0] < 1){$new_size[0] = 1;} if($new_size[1] < 1){$new_size[1] = 1;} $thumb = imagecreatetruecolor($new_size[0], $new_size[1]); imagealphablending($thumb, false); imagesavealpha($thumb, true); imagecopyresampled($thumb, $src, 0, 0, 0, 0, $new_size[0], $new_size[1], $src_size[0], $src_size[1]); //$src_pos[0], $src_pos[1] 3rd and 4th of zeros position on above line if($src_size['mime'] === 'image/jpg') { if($dest !== NULL) { imagejpeg($thumb, $dest, 95); } else { header('Content-Type: image/jpeg'); imagejpeg($thumb, NULL, 95); } } elseif($src_size['mime'] === 'image/jpeg') { if($dest !== NULL) { imagejpeg($thumb, $dest, 95); } else { header('Content-Type: image/jpeg'); imagejpeg($thumb, NULL, 95); } } elseif($src_size['mime'] === 'image/pjpeg') { if($dest !== NULL) { imagejpeg($thumb, $dest, 95); } else { header('Content-Type: image/jpeg'); imagejpeg($thumb, NULL, 95); } } elseif($src_size['mime'] === 'image/png') { if($dest !== NULL) { imagepng($thumb, $dest); } else { header('Content-Type: image/png'); imagepng($thumb); } } elseif($src_size['mime'] === 'image/gif') { if($dest !== NULL) { imagegif($thumb, $dest); } else { header('Content-Type: image/gif'); imagegif($thumb); } } imagedestroy($src); } Your insight is appreciated.
-
Hey. Just recently got into developing with PDO and OOP, instead of the old MySQL_*, so I'm pretty new, and have some dumb questions. Right now I'm taking the first steps into making a blog (Nope, not a blogger - just need something to work on), and i came across a tutorial to create a database class. I have spend a little time on making such a class, and though I got it working just fine, I'm not really sure how useful and necessary it really is. Yeah, of course it saves you a couple of lines, but at the cost of getting used to using the class, instead of just raw PDO. Here is the class i just quickly made: <?php class database { private $host = DB_HOST; private $user = DB_USER; private $pass = DB_PASS; private $dbname = DB_NAME; public function __construct() { // Try connection or die. try { $this->db = new PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->user,$this->pass); } catch(PDOException $e) { die($e); } } public function getColumn($sql, $params) { // Get value of a single row $query = $this->db->prepare($sql); $query->execute($params); return $query->fetchColumn(); } public function fetch($sql, $params) { // Return fetch $query = $this->db->prepare($sql); $query->execute($params); return $query->fetch(); } public function update($sql, $params) { // Update $query = $this->db->prepare($sql); $query->execute($params); } public function getRows($sql, $params) { // Return number of rows $query = $this->db->prepare($sql); $query->execute($params); return($query->rowCount()); } public function insert($sql, $params) { // Insert $query = $this->db->prepare($sql); $query->execute($params); } } ?> I know it can get way more optimized, advanced and usefull, but it's just a quick example. Is it just dumb to spend time on a database class, or is it worth the time? Any advice appriciated. Thanks in advande!
-
The idea is simple. A key you press (a letter) appears in updated page: keyj.php: <input id='k'></input> <script type="text/javascript"> document.getElementById('k').onkeypress=function() { <?php $db=new PDO('mysql:host=localhost;dbname=test;charset=utf8','$us','$ps'); $db->exec("UPDATE TXT SET texts=k.value"); $rl=$db->query("SELECT texts FROM TXT"); print_r($rl->fetchColumn()); ?> } </script> The intention is to have text on the screen via print_r. I successfully used it in another php to exchange information with MySQL and users screen (worked). Here - the more you type and the more k.value is the more text will be on screen (just from server). Unfortunately something went wrong.
- 2 replies
-
- javascript
- php
-
(and 3 more)
Tagged with:
-
I have this function for a search engine using pdo public function GetPageurlByPagecontent() { $db = Database::getDB(); $query = "SELECT * FROM searchengine where pageurl Like Pagecontent"; $searchengine =$db->query($query); return $searchengine; } in the data base pagecontent = keyword pageurl is the url to match that keyword this is my form , I want the pagecontent to match the pageurl only when i do a search by the pagecontent dont even think this query work any ideas? <form action="searchhome.php" method="post" id="search"> <b>Enter Search Term:</b> <input type="text" name="term" size="50"> <b>Results:</b> <select name="results"> <option>10</option> <option>20</option> <option>50</option> </select><br> <input type="submit" value="Search"> </form> <br /> <br /> <?php if(isset($_POST['pageurl'])){ $c_name = $_POST['pageurl']; $pdb2 = new SearchDB(); $search= $pdb2->GetPageurlByPagecontent($c_name); ?> <h1> Results <?php echo $c_name ?> </h1> <?php foreach($search as $list): ?> <br /> <br /> <table> <tr> <td> <p><em> url </em>: <?php echo $list['pageurl'] ?> </p> </td> </tr> </table> <?php endforeach; ?> <?php }?>
-
I’m moving my code from Procedural to OOP and am having an issue trying to run a basic query. Looks like the connection to the DB is made, but I must not be fully understanding Objects / scope of Objects yet.. I’m trying keep it simple so I can test this out and understand it before updating my code. My instal thoughts are: 1. Get OOP class set up for DB Connection. MySQL first as that’s what I’m using now. Then config MSSQL and Oracle classes for easy integration. 2. Get simple queries working using a basic function file with PDO (Like current code). 3. Convert my function files to classes. I’ve separated my code to 3 function files (categories) for some organization. The files aren’t huge, but they do range from 150 lines to just over 1000. Below is the code I’m testing with. Pretty simple and I hope straight forward. I’ve also tried sending in $dbConn as a variable versus have it as a global variable in the function.. I’ve read that’s the better way. But if anybody has thoughts on that too I would love to hear opinions / recommendations. thanx Index.php - testing page: /** * Start Includes sections */ require_once("../includes/db_conn/MYSQL_database.php"); require_once("../includes/functions.php"); /** * End Includes sections */ /** * Check DB Connection */ if (isset($config)){ echo"<pre>"; print_r($config); echo"<pre>"; }else{ echo'<script type="text/javascript">window.alert("config not set")</script>'; } echo"<hr>"; //if (isset($database)){echo "Database opened"; } else {echo "Database not opened";} /** * If connected to DB load page * Else echo not connected */ if (isset($database)){ //echo "Database opened"; /** * Run query to verify working. */ $customers = cust_list($dbConn); echo "<pre>"; print_r($customers); echo "</pre>"; } else { echo "Database not opened"; } MySQLDatabase Class: class MySQLDatabase { /** * MySql Connect to DB */ private $host; private $dbname; private $username; private $password; public $dbConn; function __construct($config){ $this->host = ($config['host']); $this->dbname = ($config['dbname']); $this->username = ($config['username']); $this->password = ($config['password']); } private function open_connection(){ try{ //$this->connection = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); $this->dbConn = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $username, $password); echo "<script type=\"text/javascript\">window.alert(\"Connection Made\")</script>"; }catch(PDOException $e){ echo 'ERROR Inside the open_connection funtion: ' . $e->getMessage(); } } } /** * Create object */ $database = new MySQLDatabase($config); Functions File (will be moved to a Class next): function cust_list($dbConn){ //global $dbConn; try{ /** * Prepare */ $cust_list = $dbConn->prepare("select * from customer"); /** * Bind */ /** * Execute */ $cust_list->execute(); /** * Fetch from array */ $cust_list_array = $cust_list->fetchall(PDO::FETCH_ASSOC); /** * Return */ return $cust_list_array; } catch(PDOException $e){ echo"Inside cust_list " . $e->getMessage(); } } When sending in $dbConn I get: Notice: Undefined variable: dbConn in /Users/aaronjk/localhost/base_sites/php_base/public/index.php on line 34 Fatal error: Call to a member function prepare() on a non-object in /Users/aaronjk/localhost/base_sites/php_base/includes/functions.php on line 12 When setting $dbConn as global inside the function I get: Fatal error: Call to a member function prepare() on a non-object in /Users/aaronjk/localhost/base_sites/php_base/includes/functions.php on line 12 From What I've read I "Call to member function prepare() on a non-object in.. " is because I need the global connection $dbConn set in the called function, but I thought I was doing that.
-
Hello, > Sorry for my English I use a translator frensh => english:) I have a problem for convertire my current code MySql in PDO, I want to keep the same structure. This is my MySql structure: <?php class Dbase{ private $_host = "localhost"; private $_user = "root"; private $_password = ""; private $_name = "dbase"; private $_conndb = FALSE; public $_last_query = NULL; public $_affected_rows = 0; public $_insert_keys = array(); public $_insert_values = array(); public $_update_sets = array(); public $_id; public function __construct(){ $this->connect(); } private function connect(){ $this->_conndb = mysql_connect($this->_host,$this->_user,$this->_password); if(!$this->_conndb){ die("Database connection failed:<br />".mysql_error()); }else{ $_select = mysql_select_db($this->_name,$this->_conndb); if(!$_select){ die("Database selection failed:<br />".mysql_error()); } } mysql_set_charset("UTF-8", $this->_conndb); } public function close(){ if(!mysql_close($this->_conndb)){ die("Closing connection failed."); } } public function escape($value){ if(function_exists("mysql_real_escape_string")){ if(get_magic_quotes_gpc()){ $value = stripslashes($value); } $value = mysql_real_escape_string($value); }else{ if(!get_magic_quotes_gpc()){ $value = addslashes($value); } } return $value; } public function query($sql){ $this->_last_query = $sql; $result = mysql_query($sql, $this->_conndb); $this->displayQuery($result); return $result; } public function displayQuery($result){ if(!$result){ $output = "Database query failed: ".mysql_error()."<br />"; $output .= "Last SQL query was: ".$this->_last_query; die($output); }else{ $this->_affected_rows = mysql_affected_rows($this->_conndb); } } public function fetchAll($sql){ $result = $this->query($sql); $out = array(); while($row = mysql_fetch_assoc($result)){ $out[] = $row; } mysql_free_result($result); return $out; } public function fetchOne($sql){ $out = $this->fetchAll($sql); return array_shift($out); } public function lastId(){ return mysql_insert_id($this->_conndb); } } I am trying to self resolve but and don't kan resolve, i try this but is not work: <?php class Dbase{ private $_pdo_host_dbname = "mysql:host=127.0.0.1;dbname=dbase"; private $_user = "root"; private $_password = ""; private $_conndb = FALSE; public $_last_query = NULL; public $_affected_rows = 0; public $_insert_keys = array(); public $_insert_values = array(); public $_update_sets = array(); public $_id; public function __construct(){ $this->connect(); } private function connect(){ try{ $this->_conndb = new PDO($this->_pdo_host_dbname,$this->_user,$this->_password); } catch { echo 'Connection failed'; } } public function escape($value){ if(get_magic_quotes_gpc()){ $value = stripslashes($value); } $value = $this->_conndb->quote($value); return $value; } public function query($sql){ $this->_last_query = $sql; $result = $this->_conndb->query($sql); $this->displayQuery($result); return $result; } public function displayQuery($result){ if(!$result){ $output = "Database query failed: ".$this->_conndb->errorInfo()."<br />"; $output .= "Last SQL query was: ".$this->_last_query; die($output); }else{ $this->_affected_rows = $this->_conndb->rowCount($this->_conndb); } } public function fetchAll($sql){ $result = $this->query($sql); $out = array(); while($row = $this->_conndb->fetch(PDO::FETCH_ASSOC)){ $out[] = $row; } return $out; } public function fetchOne($sql){ $out = $this->fetchAll($sql); return array_shift($out); } public function lastId(){ return $this->_conndb->lastInsertId($this->_conndb); } } Please help me
-
does anyone know a class that can generate a menu with category and subcategory that connects to mysql with pdo ? thank you
-
I have some code that I edited for importing csv into mysql using PDO to bind parameters. I thought it was working before, but tested it again and the issue I have is that only one line (the fourth line) of the csv file is getting imported. The first line is the header which are the table field names. The first method below is what's used to parse the csv files and bind the field names with the data. The second method, loops through. I need another pair of eyes, so if anyone can help me figure out my issue, I would greatly appreciated. public function getSQLinsertsArray($sqlTable) { $data = $this->getCSVarray(); $queries = []; $fieldsStr = ""; while(list($k, $field) = each($data)) { if(empty($fieldStr)) $fieldStr = implode(", ", array_keys($field)); //$valueStr = "'".implode("', '", $field)."'"; $placeholders = array_map(function($col) { return ":$col"; }, $field); $bind = array_combine($placeholders,$field); $queries[] = DB::inst()->query("INSERT INTO ".$sqlTable." (".$fieldStr.") VALUES (".implode(",", $placeholders).");",$bind); //error_log(var_export($queries,true)); } return $queries; } public function queryInto($sqlTable) { $queries = $this->getSQLinsertsArray($sqlTable); while(list($k, $query) = each($queries)) { $q = $query; } if($q > 0) { return true; } else { return false; } }
-
Hello! I found out that some 'SELECT' SQL queries are very slow with pdo_sqlite (PHP 5.3 or PHP 5.4). The same query entered in the sqlite3 binary is way faster. Here is my project : http://we.tl/59fGSVnAXh (password : "sqlite-php") - bench.php - chaines_centre.db - inc_func.php - info_job.php The info_job.php page performs 5 'SELECT' queries in 10 seconds with my Apache server. A same query is perform in less than 0.2 seconds in the sqlite3 binary (so theoretically 1 second for the whole page). I tried to modify the query a bit, and the results are strange : Benchmark (bench.php) on the « $bdd->query(...); » instruction : Query 2 : select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs where NomJob = 'NSAVBASE' and NomChaine like 'DCLC257%' limit 20; => 0.00099992752075195 seconde(s) Query 3 : select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs where NomJob = 'NSAVBASE' and NomChaine = 'DCLC25736' order by DateMonteeAuPlan DESC limit 20; => 0 seconde(s) Query 1 : select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs where NomJob = 'NSAVBASE' and NomChaine like 'DCLC257%' order by DateMonteeAuPlan DESC limit 20; => 1.8629999160767 seconde(s) Why is there so much differences between two query quasi-identical? How can I improve this situation to get results as fast as the sqlite3 binary? Thanks if you took the time to look out my project files.
-
[code] <html> <body> <?php include('connect.php'); $ud_NUMB=(int)$_POST["fNumb"]; $ud_PAID=$_POST["fPaid"]; echo $ud_NUMB; echo $ud_PAID; $sql = "UPDATE Teams SET Paid = :paid WHERE Numb = :numb"; $stmt = $db->prepare($sql); $stmt->bindParam(':paid', $_POST['fPaid'], PDO::PARAM_STR); $stmt->bindParam(':numb', $_POST['$fNumb'], PDO::PARAM_STR); $stmt->execute(); echo "\nPDO::errorCode(): "; print $stmt->errorCode(); ?> </br><p><a href='game.php'><H3>Back to main page</H3></a> </body> </html> [/code] My connect works fine, used in other scripts. $db is the connection. My echo of the two passed variables works fine. Example reply from echo is: 8Yes (didn't bother to put in spaces). The only reply on error is: PDO::errorCode(): 00000 I get the prompt to return to the website link at the end. No other error codes. But it does not update my record. It should change record with unique ID of 8 to show Yes in the Paid column. Can someone point me in the right direction here? Thanks
-
Hi Guys Any ideas why nothing is being stored in my database? I have echoed out all the variables and they appear fine, likewise I am not getting any PDO errors from the try/catch, just nothing is being stored! <?PHP //for ($x=0; $x <=9; $x++) //{ // print_r($url); // print_r(" "); // print_r(""); // print_r ($response); // print_r(""); //} $var = '@activePropertyCount'; foreach($response as $data) { $mycount = $data->HotelList->$var; } // while( $mycount > -1) // { $mycount = 1; foreach($response as $data) { try { $host = 'localhost'; $dbname = 'HotelWifi'; $user = 'removed'; $pass = 'removed'; # MySQL with PDO_MYSQL $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); } catch(PDOException $e) { echo $e->getMessage(); } //print_r($data->HotelList->HotelSummary[$mycount-1]->hotelId); //print_r($data->HotelList->HotelSummary[$mycount-1]); $STH = $DBH->prepare("INSERT INTO HotelData (HotelID, HotelName, HotelCity, HotelCountry, LowRate, Long, Lat) values (:id,:name,:city,:country,:low,:long,:lat)"); $HotelID = $data->HotelList->HotelSummary[$mycount-1]->hotelId; $HotelName = $data->HotelList->HotelSummary[$mycount-1]->name; $HotelCity = $data->HotelList->HotelSummary[$mycount-1]->city; $HotelCountry = $data->HotelList->HotelSummary[$mycount-1]->countryCode; $LowRate = $data->HotelList->HotelSummary[$mycount-1]->lowRate; $Long = $data->HotelList->HotelSummary[$mycount-1]->longitude; $Lat = $data->HotelList->HotelSummary[$mycount-1]->latitude; $STH->bindParam(":id", $HotelID); $STH->bindParam(":name", $HotelName); $STH->bindParam(":city", $HotelCity); $STH->bindParam(":country", $HotelCountry); $STH->bindParam(":low", $LowRate); $STH->bindParam(":long", $Long); $STH->bindParam(":lat", $Lat); echo $HotelID . " " . $HotelName . " " . $HotelCity . " " . $HotelCountry . " " . $LowRate . " " . $Long . " " . $Lat; try { $STH->execute(); print_r($STH); } catch(PDOException $e) { echo $e->getMessage(); } } // // // // // // print_r($data->HotelList); // // // $i = $i + 1; ?>
-
ok, im writing a simple CRUD application for my work and i am having trouble with the UPDATE statement in the following code, the insert statement works fine. frm_bpd_sv.php: <?php error_reporting(-1); $page['title'] = "BPD Save"; require_once('config.inc.php'); if(isset($_SESSION['jobDetailID'])){ $jobdetailid = $_SESSION['jobDetailID']; } else { header("location:index.php"); } try { $dbh = new PDO("mysql:host=$db_host;dbname=$db_name", $db_username, $db_password); } catch(PDOException $e){ echo $e->getMessage(); } if(isset($_GET['editID'])){$data['bpdID'] = $_GET['editID'];} $data['jobDetailID'] = $jobdetailid; if(isset($_POST['backflowID'])){$data['backflowID'] = $_POST['backflowID'];} else {$data['backflowID'] = null;} if(isset($_POST['bpdOnsite'])){$data['bpdOnsite'] = $_POST['bpdOnsite'];} else {$data['bpdOnsite'] = 0;} if(isset($_POST['bpdLocation'])){$data['bpdLocation'] = $_POST['bpdLocation'];} else {$data['bpdLocation'] = null;} if(isset($_POST['bpdMake'])){$data['bpdMake'] = $_POST['bpdMake'];} else {$data['bpdMake'] = null;} if(isset($_POST['bpdModel'])){$data['bpdModel'] = $_POST['bpdModel'];} else {$data['bpdModel'] = null;} if(isset($_POST['bpdSerial'])){$data['bpdSerial'] = $_POST['bpdSerial'];} else {$data['bpdSerial'] = null;} if(isset($_POST['bpdSize'])){$data['bpdSize'] = $_POST['bpdSize'];} else {$data['bpdSize'] = null;} if(isset($_POST['protectionType'])){$data['protectionType'] = $_POST['protectionType'];} else {$data['protectionType'] = null;} if(isset($_POST['bpdType'])){$data['bpdType'] = $_POST['bpdType'];} else {$data['bpdType'] = null;} if(isset($_POST['protectionLvl'])){$data['protectionLvl'] = $_POST['protectionLvl'];} else {$data['protectionLvl'] = null;} if(isset($_POST['wmNo'])){$data['wmNo'] = $_POST['wmNo'];} else {$data['wmNo'] = null;} if(isset($_POST['wmSize'])){$data['wmSize'] = $_POST['wmSize'];} else {$data['wmSize'] = null;} if(isset($_POST['wmLocation'])){$data['wmLocation'] = $_POST['wmLocation'];} else {$data['wmLocation'] = null;} if(isset($_POST['sprinklers'])){$data['sprinklers'] = $_POST['sprinklers'];} else {$data['sprinklers'] = null;} if(isset($_POST['drinkingTaps'])){$data['drinkingTaps'] = $_POST['drinkingTaps'];} else {$data['drinkingTaps'] = null;} if(isset($_POST['longitude'])){$data['longitude'] = $_POST['longitude'];} else {$data['longitude'] = null;} if(isset($_POST['latitude'])){$data['latitude'] = $_POST['latitude'];} else {$data['latitude'] = null;} if(isset($_POST['accuracy'])){$data['accuracy'] = $_POST['accuracy'];} else {$data['accuracy'] = null;} if(isset($_POST['activity'])){$data['activity'] = $_POST['activity'];} else {$data['activity'] = null;} if(isset($_POST['permisionTTOW'])){$data['permisionTTOW'] = $_POST['permisionTTOW'];} else {$data['permisionTTOW'] = null;} if(isset($_POST['comments'])){$data['comments'] = $_POST['comments'];} else {$data['comments'] = null;} if(isset($_POST['pass'])){$data['pass'] = $_POST['pass'];} else {$data['pass'] = null;} print_r($data); echo '<hr>'.$_GET['editID']; if(isset($_GET['editID'])){ $editID = $_GET['editID']; $temp = "UPDATE frm_bpd SET `backflowID` = :backflowID, `jobDetailID` = :jobDetailID, `bpdOnsite` = :bpdOnsite, `bpdLocation` = :bpdLocation, `bpdMake` = :bpdMake, `bpdModel` = :bpdModel, `bpdSerial` = :bpdSerial, `bpdSize` = :bpdSize, `protectionType` = :protectionType, `bpdType` = :bpdType, `protectionLvl` = :protectionLvl, `wmNo` = :wmNo, `wmSize` = :wmSize, `wmLocation` = :wmLocation, `sprinklers` = :sprinklers, `drinkingTaps` = :drinkingTaps, `longitude` = :longitude, `latitude` = :latitude, `accuracy` = :accuracy, `activity` = :activity, `permisionTTOW` = :permisionTTOW, `comments` = :comments, `pass` = :pass` WHERE `bpdID` = :bpdID"; } else { $editID = false; $temp = "INSERT INTO frm_bpd (`backflowID`, `jobDetailID`, `bpdOnsite`, `bpdLocation`, `bpdMake`, `bpdModel`, `bpdSerial`, `bpdSize`, `protectionType`, `bpdType`, `protectionLvl`, `wmNo`, `wmSize`, `wmLocation`, `sprinklers`, `drinkingTaps`, `longitude`, `latitude`, `accuracy`, `activity`, `permisionTTOW`, `comments`, `pass`) VALUES (:backflowID, :jobDetailID, :bpdOnsite, :bpdLocation, :bpdMake, :bpdModel, :bpdSerial, :bpdSize, :protectionType, :bpdType, :protectionLvl, :wmNo, :wmSize, :wmLocation, :sprinklers, :drinkingTaps, :longitude, :latitude, :accuracy, :activity, :permisionTTOW, :comments, :pass);"; } try { $sql = $dbh->prepare($temp); $sql->execute($data); $succsess = 1; } catch(PDOException $e) { header("location:frm_bpd.php?id=".$editID."&message=".$e->getMessage()); $succsess = 0; } if($editID == false){ $editID = $dbh->lastInsertId(); } /*if($succsess == 1){ header("location:frm_bpd.php?id=".$editID."&message=BPD%20Saved"); } else { header("location:frm_bpd.php?id=".$editID."&message=An%20Error%20Occured"); }*/ ?> frm_bpd Table: -- phpMyAdmin SQL Dump -- version 4.1.4 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Feb 10, 2014 at 01:36 AM -- Server version: 5.6.15-log -- PHP Version: 5.4.24 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; -- -- Database: `omni` -- -- -------------------------------------------------------- -- -- Table structure for table `frm_bpd` -- CREATE TABLE IF NOT EXISTS `frm_bpd` ( `bpdID` int(11) NOT NULL AUTO_INCREMENT, `backflowID` varchar(255) DEFAULT NULL, `jobDetailID` int(11) DEFAULT NULL, `bpdOnsite` tinyint(11) DEFAULT '0', `bpdLocation` varchar(255) DEFAULT NULL, `bpdMake` varchar(255) DEFAULT NULL, `bpdModel` varchar(255) DEFAULT NULL, `bpdSerial` varchar(255) DEFAULT NULL, `bpdSize` int(11) DEFAULT NULL, `protectionType` tinyint(11) DEFAULT NULL, `bpdType` tinyint(4) DEFAULT NULL, `protectionLvl` tinyint(4) DEFAULT NULL, `wmNo` varchar(255) DEFAULT NULL, `wmSize` int(11) DEFAULT NULL, `wmLocation` varchar(255) DEFAULT NULL, `sprinklers` tinyint(11) DEFAULT NULL, `drinkingTaps` tinyint(11) DEFAULT NULL, `longitude` varchar(255) DEFAULT NULL, `latitude` varchar(255) DEFAULT NULL, `accuracy` int(11) DEFAULT NULL, `activity` tinyint(11) DEFAULT NULL, `permisionTTOW` tinyint(11) DEFAULT NULL, `comments` varchar(255) DEFAULT NULL, `pass` tinyint(11) DEFAULT NULL, UNIQUE KEY `bpdID` (`bpdID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `frm_bpd` -- INSERT INTO `frm_bpd` (`bpdID`, `backflowID`, `jobDetailID`, `bpdOnsite`, `bpdLocation`, `bpdMake`, `bpdModel`, `bpdSerial`, `bpdSize`, `protectionType`, `bpdType`, `protectionLvl`, `wmNo`, `wmSize`, `wmLocation`, `sprinklers`, `drinkingTaps`, `longitude`, `latitude`, `accuracy`, `activity`, `permisionTTOW`, `comments`, `pass`) VALUES (1, NULL, 1328449, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL), (2, NULL, 1328449, -1, '2', '3', '4', '5', 6, 1, 2, NULL, '7', 8, '9', -1, -1, NULL, '', 0, 2, -1, 'bla', -1); output of $data with print_r(); Array ( [bpdID] => 1 [jobDetailID] => 1328449 [backflowID] => [bpdOnsite] => -1 [bpdLocation] => some [bpdMake] => [bpdModel] => [bpdSerial] => [bpdSize] => [protectionType] => 0 [bpdType] => 0 [protectionLvl] => [wmNo] => [wmSize] => [wmLocation] => [sprinklers] => [drinkingTaps] => [longitude] => [latitude] => [accuracy] => [activity] => 0 [permisionTTOW] => [comments] => [pass] => ) i know it must be a typo somewhere but i just cant spot it, as i said the insert statement works fine, and no errors are being thrown. am i just not using the UPDATE statement correctly? any help would be greatly appreciated.
-
Hi, Although I have been programming for a long time now I have been asked to help a friend out with some PHP and MySql (never touched either of them before this week) I find some tasks which should be obvious to me are a little alien. My problem is that I want to read a record from a user file using the 'id' and then using data from that record to read 1 or 2 records from a contact/address file. I do not know whether it will be 1 or 2 records as this data is entered by the user. The sample code here shows the user file "valid_user" and the contact/address file called "carer", not having used this form of syntax before I am not 100% sure that the SELECT statement is correct except that it does produce the correct data when run (well the first contact details). $myid = $_SESSION['id']; try { $query="SELECT * FROM carer INNER JOIN valid_users ON valid_users.id = carer.valid_users_id WHERE valid_users.id='$myid'"; $stmt = $dbh->prepare($query); $stmt->execute(); $count = $stmt->rowCount(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $myfirstname = $row['firstname']; $mysurname = $row['surname']; $myaddress1 = $row['address1']; $myaddress2 = $row['address2']; $mytown = $row['town']; $mycounty = $row['county']; $mypostcode = $row['postcode']; $myhome = $row['landline']; $mymobile = $row['mobile']; $myemail = $row['email']; $myecontact = $row['econtact']; $myephone = $row['ephone']; This gets me details for the first contact, which is displayed quite happily but I do not understand how I go about fetching the 2nd contact record (if there is one). I understand I could use fetchAll but I cant then work out how i populate the variables for both the first contact and the second contact when the variables are not the same i.e. the firstname field in "contact" record 1 will populate $myfirstname whereas the firstname field in "contact" record 2 will populate $myfirstname2. It is done this way because I am displaying both sets of contact details on the screen. In my past experience I would just do a Read Next to get the second contact record but obviously no such syntax is available. I also use the record count later on in the program. I know this probably has an easy answer but all the documentation I have read want to talk about apples and pears and whether they are red or yellow and then shows you how to print the array without explaining how you get the separate elements of the array in to variables. Any help would be appreciated
-
Hi guys. I have following code to delete particular row from a table based on the title. But how can I delete all data from the table? <?php require 'connpdo.php'; $naslov = $_POST['naslov']; #DELETE DATA //delete some data $sqlInsert = 'DELETE FROM bloging WHERE title=:title'; $preparedStatement = $conn->prepare($sqlInsert); $preparedStatement->execute(array(':title' => $naslov)); //REDIRECT TO HOME PAGE header('Location: http://localhost/ITAPHP/index.php'); ?> So I would need something which would say DELETE * FROM bloging...Basically I have this table bloging with 3 fields id, title and text, and above code will identify specific post based on the title and delete that particular post. But I need button to delete all posts, to empty table. Thank you in advance!
-
Hi guys! I have a slight problem. When I pass values as variables to a sql statement it doesnt work. This is the example: THIS WORKS: <?php require 'DB/dbinc.php'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $usernm, $dbpass); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // changes data in "text" and "text" where title = some title $sql = "UPDATE bloging SET title='Novi Title', tekst='Novi tekst' WHERE title='Update post'"; $count = $conn->exec($sql); $conn = null; // Disconnect } catch(PDOException $e) { echo $e->getMessage(); } // If data added ($count not false) displays the number of rows added if($count !== false) echo 'Number of rows added: '. $count; ?> THIS DOES NOT WORK <?php require 'DB/dbinc.php'; $oldTitle = 'Stari naslov'; $nTitle = 'novinaslov'; $nText = 'novitekst'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $usernm, $dbpass); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // changes data in "text" and "text" where title = some title $sql = "UPDATE bloging SET title=$nTitle, tekst=$nText WHERE title=$oldTitle"; $count = $conn->exec($sql); $conn = null; // Disconnect } catch(PDOException $e) { echo $e->getMessage(); } // If data added ($count not false) displays the number of rows added if($count !== false) echo 'Number of rows added: '. $count; ?> I don't get it why it wont accept variable instead of string text as a value? Thanx in advance!
-
Sorry about any formatting inconsistencies here. This question was originally posted on stackoverflow, but none of the suggestions there solved my issue so I thought I'd bring it up here. Some of the information may be extraneous, but was asked for on SO, so I thought it might be helpful. I'm getting this error when I try to start PHP via command line on Fedora 20: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_odbc.so' - /usr/lib64/php/modules/pdo_odbc.so: undefined symbol: pdo_parse_params in Unknown on line 0 Here are the PHP packages I have installed: php.x86_64 5.5.7-1.fc20 @updates php-ZendFramework.noarch 1.12.3-3.fc20 @updates php-bcmath.x86_64 5.5.7-1.fc20 @updates php-cli.x86_64 5.5.7-1.fc20 @updates php-common.x86_64 5.5.7-1.fc20 @updates php-devel.x86_64 5.5.7-1.fc20 @updates php-gd.x86_64 5.5.7-1.fc20 @updates php-mcrypt.x86_64 5.5.7-1.fc20 @updates php-mssql.x86_64 5.5.7-1.fc20 @updates php-odbc.x86_64 5.5.7-1.fc20 @updates php-pdo.x86_64 5.5.7-1.fc20 @updates php-pear.noarch 1:1.9.4-23.fc20 @fedora php-pecl-jsonc.x86_64 1.3.3-1.fc20 @updates php-pecl-jsonc-devel.x86_64 1.3.3-1.fc20 @updates php-process.x86_64 5.5.7-1.fc20 @updates php-xml.x86_64 5.5.7-1.fc20 @updates I have `extension=pdo_odbc.so` and `extension=oci8.so` as the only extensions defined in my `/etc/php.ini` file. There are also a lot of .ini files in the `/etc/php.d` directory that loads most of the other extensions. The following .so files are in the `/usr/lib64/php/modules` directory: -rwxr-xr-x. 1 root root 32560 Dec 10 23:51 bcmath.so -rwxr-xr-x. 1 root root 24696 Dec 10 23:51 bz2.so -rwxr-xr-x. 1 root root 33752 Dec 10 23:51 calendar.so -rwxr-xr-x. 1 root root 15568 Dec 10 23:51 ctype.so -rwxr-xr-x. 1 root root 86912 Dec 10 23:51 curl.so -rwxr-xr-x. 1 root root 180608 Dec 10 23:51 dom.so -rwxr-xr-x. 1 root root 65496 Dec 10 23:51 exif.so -rwxr-xr-x. 1 root root 2713328 Dec 10 23:51 fileinfo.so -rwxr-xr-x. 1 root root 53624 Dec 10 23:51 ftp.so -rwxr-xr-x. 1 root root 120904 Dec 10 23:51 gd.so -rwxr-xr-x. 1 root root 15640 Dec 10 23:51 gettext.so -rwxr-xr-x. 1 root root 45080 Dec 10 23:51 iconv.so -rwxr-xr-x. 1 root root 40840 Dec 12 09:13 json.so -rwxr-xr-x. 1 root root 45256 Dec 10 23:51 mcrypt.so -rwxr-xr-x. 1 root root 53816 Dec 10 23:51 mssql.so -rwxr-xr-x. 1 root root 560751 Jan 10 10:20 oci8.so -rwxr-xr-x. 1 root root 70312 Dec 10 23:51 odbc.so -rwxr-xr-x. 1 root root 25008 Dec 10 23:51 pdo_dblib.so -rwxr-xr-x. 1 root root 28856 Dec 10 23:51 pdo_odbc.so -rwxr-xr-x. 1 root root 116240 Dec 10 23:51 pdo.so -rwxr-xr-x. 1 root root 29168 Dec 10 23:51 pdo_sqlite.so -rwxr-xr-x. 1 root root 272000 Dec 10 23:51 phar.so -rwxr-xr-x. 1 root root 32880 Dec 10 23:51 posix.so -rwxr-xr-x. 1 root root 15624 Dec 10 23:51 shmop.so -rwxr-xr-x. 1 root root 54176 Dec 10 23:51 simplexml.so -rwxr-xr-x. 1 root root 91368 Dec 10 23:51 sockets.so -rwxr-xr-x. 1 root root 51336 Dec 10 23:51 sqlite3.so -rwxr-xr-x. 1 root root 19880 Dec 10 23:51 sysvmsg.so -rwxr-xr-x. 1 root root 11496 Dec 10 23:51 sysvsem.so -rwxr-xr-x. 1 root root 15720 Dec 10 23:51 sysvshm.so -rwxr-xr-x. 1 root root 19712 Dec 10 23:51 tokenizer.so -rwxr-xr-x. 1 root root 36720 Dec 10 23:51 wddx.so -rwxr-xr-x. 1 root root 32888 Dec 10 23:51 xmlreader.so -rwxr-xr-x. 1 root root 54072 Dec 10 23:51 xml.so -rwxr-xr-x. 1 root root 49152 Dec 10 23:51 xmlwriter.so -rwxr-xr-x. 1 root root 37104 Dec 10 23:51 xsl.so The output of when I run phpinfo() can be found here. Contents of `pdo_odbc.ini` at /etc/php.d: ; Enable pdo_odbc extension module extension=pdo_odbc.so Output of `readelf -Ws pdo_odbc.so`: Symbol table '.dynsym' contains 83 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000001ac0 0 SECTION LOCAL DEFAULT 9 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND convert_to_long 3: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND pdo_parse_params 4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_pdo_unregister_driver 5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND free@GLIBC_2.2.5 (2) 6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strcasecmp@GLIBC_2.2.5 (2) 7: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable 8: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLParamData 9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND cfg_get_string 10: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLRowCount 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _estrdup 12: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strlen@GLIBC_2.2.5 (2) 13: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLFreeHandle 14: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLFetchScroll 15: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail@GLIBC_2.4 (3) 16: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _zval_dtor_func 17: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLDriverConnect 18: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLPutData 19: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND zend_fetch_resource 20: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strchr@GLIBC_2.2.5 (2) 21: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_info_print_table_row 22: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _php_stream_stat 23: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLGetDiagRec 24: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLDescribeCol 25: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _erealloc 26: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_pdo_get_exception 27: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND zend_hash_index_find 28: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND zend_declare_class_constant_long 29: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 30: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLCloseCursor 31: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLSetEnvAttr 32: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_error_docref0 33: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_info_print_table_end 34: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _safe_malloc 35: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memcpy@GLIBC_2.14 (4) 36: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLConnect 37: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND zend_throw_exception_ex 38: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_file_le_stream 39: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLDescribeParam 40: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_info_print_table_header 41: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_pdo_register_driver 42: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLColAttribute 43: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_pdo_get_dbh_ce 44: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLPrepare 45: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _ecalloc 46: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLSetConnectAttr 47: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __strcpy_chk@GLIBC_2.3.4 (5) 48: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _convert_to_string 49: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLExecute 50: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _efree 51: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLExecDirect 52: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND zval_is_true 53: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLSetCursorName 54: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLDisconnect 55: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 56: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _php_stream_read 57: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND add_next_index_string 58: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _estrndup 59: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLEndTran 60: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _emalloc 61: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLNumResultCols 62: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLGetData 63: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_file_le_pstream 64: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _zval_copy_ctor_func 65: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 66: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLBindParameter 67: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLGetCursorName 68: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND add_next_index_long 69: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLSetStmtAttr 70: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLAllocHandle 71: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND php_info_print_table_start 72: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLBindCol 73: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5 (2) 74: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND spprintf 75: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strstr@GLIBC_2.2.5 (2) 76: 0000000000000000 0 FUNC GLOBAL DEFAULT UND SQLMoreResults 77: 0000000000206438 0 NOTYPE GLOBAL DEFAULT 23 _edata 78: 0000000000206440 0 NOTYPE GLOBAL DEFAULT 24 _end 79: 0000000000002310 8 FUNC GLOBAL DEFAULT 11 get_module 80: 0000000000206438 0 NOTYPE GLOBAL DEFAULT 24 __bss_start 81: 0000000000001ac0 0 FUNC GLOBAL DEFAULT 9 _init 82: 00000000000045a4 0 FUNC GLOBAL DEFAULT 12 _fini
-
Hello. I am new. I have simple two step process I want to be done. When it does work the webpage keeps going (im guessing it's an endless loop)... I can't seem to get it to work: I know there's something I'm missing about this PDO array stuff. <?php include("database.php"); $time_ago = strtotime("-1 minute"); /*find subscribers over a month old with the thirtydaysubs table*/ $checker = "SELECT emailaddress FROM aa_thirtydaysubs WHERE subscribedate < $time_ago"; $sthandler = $database->prepare($checker); $sthandler->execute(); /*then move it to main list and remove from 30 day list*/ $data = array(); $data = $sthandler->fetch(); if ($sthandler->columnCount()){ while($sthandler->fetchAll(PDO::FETCH_ASSOC) !== 0){ $email2 = $data->fetchColumn(0); $newlist= "2"; $updatelistid = "UPDATE zzemail_list_subscribers set listid = :newlist WHERE emailaddress = :email"; $sthandler3 = $database->prepare($updatelistid); $sthandler3->execute(array(':email' => $email2, ':newlist' => $newlist )); $clearars = "DELETE FROM aa_thirtydaysubs WHERE emailaddress= :email"; $sthandler6 = $database->prepare($clearars); $sthandler6->execute(array(':email' => $email2)); } } ?>
-
0down votefavorite I just converted a query that displays "bread crumbs" style navigation links to PDO: function get_path($dbh,$node,$TopnavTable, $TopnavName) { $stmt = $dbh->prepare("SELECT name FROM $TopnavTable WHERE $TopnavName = ?"); $stmt->bindValue(1,$node); $stmt->execute(); $stmt->setFetchMode(PDO::FETCH_ASSOC); $row = $stmt->fetch(); $path = array_merge(get_path($pdo,$row['Parent'], $TopnavTable, $TopnavName), $path); return $path ; } I also figured out a way to display the results: $Path2 = explode("/", $path); $Path2[1] = '<a href="/Topics">'.$Path2[1].'</a>'; $Path2[2] = '<a href="/Topics/'.$Path2[2].'">'.$Path2[2].'</a>'; $Path2[3] = '<span class="navHere"><b>'.$Path2[3].'</b></span>'; echo join( $Path2, ' > ' ); However, it only works only if I'm working with an array consisting of three segments. For example, I'm viewing the URL MySite/Topics/Washington/Governor, which displays the following bread crumbs trail: Topics > Washington > Governor If I view MySite/Washington, it should display... Topics > Washington But I get an error message: Undefined offset: 3, plus there's a trailing arrow (>) after Washington. So I'm trying to figure out how to make this work with any number of segments - 2, 3, 6, etc. Regardless of the number of segments, I'd like the last segment to be unlinked. (I'm going to further put it inside a span.) Does anyone have any tips? (If there's a completely different way of doing it that's better, I'd love to hear about it.)
-
Wow I have to say its been a long time since I posted here but I do need alittle help so here we go: I got this script or created most of it (I dont remember) for me to connect mysql using PDO. The script works fine exept when i try to update a column in my db. now i get no errors but it does not update. $superglobals = array($_POST); foreach ($superglobals as $value){ foreach ($value as $k => $v){ $post[$k]=$v; } } $sql = "UPDATE ".DB_PREFIX."_dbase SET value = :value WHERE key = :key"; foreach ($post as $key => $value) { $bind = array("value"=> $value, "key"=>$key); $db->execute($sql, $bind) or die($db->error()); } I have upload the db class and gave you what im trying to do please help Here is the database CREATE TABLE db_dbase ( key text, value text ) database.php
-
I am trying to get all the "posts" from a users friends list on their news feed. I'm trying to do so by getting all those posts where the user is the initiator_user_id and get all the posts from the friend_user_id then I want to get all the posts from initiator_user_id where the user's id is the friend_user_id. This is what I have that's messing up: $wallsql= $conn->prepare('SELECT * FROM activity f INNER JOIN wp_bp_friends n1 ON (n1.initiator_user_id=f.user_id) INNER JOIN wp_bp_friends n2 ON (n2.friend_user_id=f.user_id) WHERE (n1.friend_user_id=:userid) OR (n2.initiator_user_id=:userid) ORDER BY datetime DESC LIMIT 8'); $wallsql->bindParam(':userid', $_SESSION['uid']); $wallsql->execute(); Previously this works but it only gets the posts where the user is the initiator_user_id: $wallsql= $conn->prepare('SELECT * FROM activity f INNER JOIN wp_bp_friends n2 ON n2.friend_user_id=f.user_id WHERE n2.initiator_user_id=:userid ORDER BY datetime DESC LIMIT 8'); Any help would be much appreciated!
-
How can i add total of user's following me? The code I currently have displays ALL the user's following me, instead of saying *numbers of user's following me* <?php $friends = Friends::getFriendsForUser($data->id); if (count($friends) > 0) { $db = DB::getInstance(); foreach($friends as $friend_id) { $friend = $db->query('SELECT name, username FROM users WHERE id = ?', array($friend_id)); if ($friend->count() == 1) { echo '<table> <tr> <td><img src="images/avatar.png"></td> <td><a href="profile.php?user='.escape($friend->first()->username).'">'.$friend->first()->name.'</a></td> </tr> </table>'; } } } else { echo 'Not following anyone.'; } ?>
-
I've been looking at this for a bit and can't seem to figure what's going on? I have used this code before and never had this issue.... I'm tryig to populate a dropdown menu from a MySql DB. The dropdown menu seems to skip the first array... I attached a screenshot that hopefully show's what I'm talking about.. any thoughts?
- 3 replies
-
- php
- drop down menu
-
(and 2 more)
Tagged with:
-
I'm having a problem with PHP and a stored procedure in SQL Server 2005. I haven't really touched stored procedures before and haven't used them with php. I can't retrieve a value from a table that I know is definitely there. I have a simple login table, what I want the stored procedure to do is to take a username as an input and then output that user's password salt. I want the stored procedure to use parameterised values to avoid SQL injection. What happens at the moment is when the php page is run, nothing is returned and the SQL Profiler displays the following error: User Error Message: Incorrect Syntax near '@Username' While this error message should tell me something is wrong, I can't for the life of me see where the incorrect syntax is. Copy of the Php: $user = "usercm"; $password ="cmuserpassword"; try{$conn = new PDO("odbc:DRIVER={SQL Server Native Client 10.0};SERVER=TestingServer;DATABASE=TestingDatebase;",$user,$password);} catch(PDOException $e){echo "oh no";} $username = "sdct"; $prepusp = $conn->prepare("EXEC uspReturnSalt(?,?)"); $prepusp->bindParam(1, $username, PDO::PARAM_STR); $prepusp->bindParam(2, $usersalt, PDO::PARAM_STR, 450); $prepusp->execute(); Copy of the Stored Procedure: ALTER PROCEDURE [dbo].[uspReturnSalt] @Username NVARCHAR(100), @Usersalt NVARCHAR(450) OUTPUT AS BEGIN DECLARE @sqlcmd NVARCHAR(MAX); DECLARE @params NVARCHAR(MAX); SET @sqlcmd = N'SELECT @Usersaltone = salt FROM CMUsers WHERE username = @Usernameone'; SET @params = N'@Usernameone NVARCHAR(100), @Usersaltone NVARCHAR(450) OUTPUT'; EXECUTE sp_executesql @sqlcmd, @params, @Usernameone = @Username, @Usersaltone = @Usersalt OUTPUT; END To clarify, the server this is on runs Windows 2003 so I cannot use the sqlsrv drivers as they require SQL Server Native Client 2012 which is incompatible. It is impossible to upgrade the operating system (server isn't mine) so I can't use any php drivers that require SQL Server Native Client 2012. If anyone could help I would be eternally grateful. Here is the sql profiler messages before and after that error: RPC:Completed | exec [sys].sp_sproc_columns_90 N'uspReturnSalt' ,@ODBCVer=3 RPC:Starting | declare @p1 int set @p1 =NULL exec sp_prepare @p1 output,N'@Username nvarchar(100),@P2 text OUTPUT' ,N'EXEC uspReturnSalt(@Username,@P2 OUTPUT)' ,1 select @p1 Exception | Error: 102, Severity: 15, State: 1 User Error Message | Incorrect syntax near '@Username'. SP:CacheMiss | (@Username nvarchar(100),@P2 text OUTPUT)EXEC uspReturnSalt(@Username,@P2 OUTPUT) Exception | Error: 8180, Severity: 16, State: 1 User Error Message | Statement(s) could not be prepared RPC:Completed | declare @p1 int set @p1=NULL exec sp_prepare @p1 output, N'@Username nvarchar(100),@P2 text OUTPUT' ,N'EXEC uspReturnSalt(@Username,@P2 OUTPUT)',1 select @p1