PHP - Sessiona Variable Problem..
hi,
i try to following codes from mysql "id" value to "aitlik" session variable but giving following error .
Notice: Undefined variable: row_kategori_cek in /Library/WebServer/Documents/test/cat_menu.php on line 5
<?php // this sets variables in the session $_SESSION['aitlik'] = $row_kategori_cek['id']; echo $_SESSION['aitlik']; ?> Similar TutorialsI'm coding a google map script in php/javascript, and I'm having a hell of a time with the address. It seems to not like any spaces for what I can tell (and I'm no php programmer). Code: [Select] /* Create an array of address values */ addresses = [ <?php for($i=0; $i < count($dataArray); $i++) { $p = $dataArray[$i]; $p = explode(":", $p); $addr = $p[4]; echo "$addr,\n"; } ?> ]; Here is data file (just one line for testing): 1315414069:41.100908:-81.442699:33:150 North Ave Tallmadge OH:1 Here is "view source" from browser: /* Create an array of address values */ addresses = [ 150 North Ave Tallmadge OH, ]; I'm stumped The map will not display with this. If I change the $addr to another variable in the array, it works fine. Trying to put the address in an info window on the map. TIA, Roots So. I wrote this class that redirects a user to a new url: Code: [Select] <?php class PotentGate{ private $endURL, $sourceURL = 'http'; private function Gate_setURL(){ //THE BLOCK BELOW WIL ULTIMATELY REFERECE A DATABASE BACKEND FOR DESTINATION URLS. if ($this->sourceURL=="http://blah.com/blah/misc.php"){$this->endURL="http://blah.com/blah/misc2.php?r=" . $this->Gate_sourceURL;} else {} } public function Gate_getURL(){ $this->Gate_sourceURL(); echo $this->sourceURL . "<br />"; $this->Gate_setURL(); //set our destination URL based on source echo $this->endURL . "<br />"; return header('Location:' . $this->endURL); //redirect } private function Gate_sourceURL() { //TODO: Fix the $_SERVER['HTTPS'] below for https:// support. //if ($_SERVER['HTTPS'] == "on") {$this->sourceURL .= "s";} $this->sourceURL .= "://"; if ($_SERVER['SERVER_PORT'] != "80") { $this->sourceURL .= $_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; } else { $this->sourceURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; } return $this->sourceURL; } }//end It is implemented as such: Code: [Select] <?php include("PotentGate.php"); $gate = new PotentGate(); $gate->Gate_getURL(); //IGNORE //function below will acquire get variable //echo "You came from:" . $gate->Gate_getReferrer(); ?> This works all well and good, as far as redirection goes, but refuses to add the $Gate_sourceURL to the end url. I am left with a url like: http://blah.com/blah/misc2.php?r= and what I am trying to achieve is that it assign $Gate_sourceURL to r (so I can use the source url as a value later on), as opposed to be being blank. ex. http://blah.com/blah/misc2.php?r=http://blah.com/blah/misc1.php Any Ideas? Hi guys, I have a bit of a problem, Im using php and mysql and have succeded in storing variables inside of a URL: echo "<a href='report.php?id=$varmemberid&colour=$varcolour'>test</a> "; i retrieve varmemberid and colour from the mysql database: $tbl_name = "members"; mysql_select_db($db_name) or die (mysql_error()); $query="SELECT * FROM $db_name ORDER BY `members`.`the_members` ASC"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $varmemberid=mysql_result($result,$i,"member_id"); $varcolour=mysql_result($result,$i,"colour"); that works all fine and dandy for numbers eg: "123" however if i go to insert a member id of "123t" i get this error: Code: [Select] Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 12 in /home/flashx/public_html/login/report-header.php on line 47 im guessing it has something to do with the 'int' in this line: $memberid = (int) $_GET['memberid']; how do i fix this? Cheers I'm not sure what is going on in this code, but for some reason it is not echoing my variable. I'm probably just having a total brain fart right now. Code: [Select] <?php <?php $opponent_check = isset($_POST['player_username']); $session = isset($_SESSION['user']); if($opponent_check){ include_once('connect.php'); $find_player = "SELECT * FROM stats WHERE Username = '$session'"; $s = mysql_fetch_array(mysql_query($find_player)) or trigger_error(mysql_error()); $player = $s['Username']; $player_HBS = $s['HBS']; $player_level = $s['Level']; $player_level_image = $s['Level_Image']; $player_skill = $s['Skill']; $player_attack = $s['Attack']; $player_defense = $s['Defense']; $player_strength = $s['Strength']; $player_speed = $s['Speed']; $player_accuracy = $s['Accuracy']; $player_range = $s['Range']; echo $player; }else{ echo " You didn't start a battle.<br/><br/> <a href='index.php'>Back to Matchmaking</a> <br/><br/> "; } ?> ?> My error is: Notice: in C:\xampp\htdocs\halobattles\headtohead.php on line 277 which is the fetch array line. Firstly, here's the code i'm having trouble with: 'products.php': Code: [Select] <?php class product{ public $id,$brand,$partnumber,$price,$per; public function dump(){ echo "dump"; echo "<table><tr><td>$id</td><td>$brand</td><td>$partnumber</td><td>$price</td><td>$per</td></tr></table>"; } public function search($strSearch){ include ("db.php"); $query = "SELECT * FROM products WHERE partnumber=\"$strSearch\";"; $db_conn = mysql_connect($dbserver,$user,$pass); @mysql_select_db($database) or die("unable to connect to database"); $result = mysql_query($query); $num_rows = mysql_num_rows($result); if($num_rows==1){ while ($row = mysql_fetch_assoc($result)) { $id = $row["id"]; $brand = $row["brand"]; $partnumber = $row["partnumber"]; $price = $row["price"]; $per = $row["per"]; //DEBUG #1: echo "<table><tr><td>$id</td><td>$brand</td><td>$partnumber</td><td>$price</td><td>$per</td></tr></table>"; } } if($num_rows>1){ // code selection (disambiguation) here } if($num_rows<1){ // code secondary searchs here } } } ?> findprod.php: Code: [Select] <body> <form action="findprod.php" method="GET"> <input type="text" name="searchstr"> <input type="submit" value="Search"> </form> </body> <?php if(isset($_GET['searchstr'])){ $searchStr = $_GET['searchstr']; include ("products.php"); $np = new product(); $np->search($searchStr); $np->dump(); echo $np->brand; } ?> Here's my problem: after typing in a part-number to search for, I'm initializing a new 'product' class, and searching for that partnumber. I know that the query is returning 1 record just like it should. The 'DEBUG#1' line that echo's the table works just fine. The problem is, when I try to call the 'dump' method (from 'findprod.php') the variables are empty. Same thing if I try to access the variables directly. Am I doing something wrong? Perhaps I don't understand classes in PHP correctly, but it's almost as if the methods in the 'product' class aren't sharing the variables between each other. Can anyone show me what I can do to make this work? BTW: I have google'd everything I could think of for the past few days, but I just can't seem to find anything to solve this problem on my own. I've thought of possibly using SESSION variables to accomplish this task, but I'd rather not. I'm also just really curious to know why this isn't working. I set up e-commence system for our company, there is a problem in this project. When I try to add the product in the cart, it can not do the Extended Price over one thousand dollars. If the Extended Price is lower than one thousand dollars, it is working. I do not know how to fix this problem . Please tell me , thank you very much The link is http://www.ptiimaging.ca/po.php?wd=1551 This is the code. <?php include("connection.php"); $sessid=session_id(); $select="select * from carttemp where sess= '$sessid'"; $result2=mysql_query($select, $connection) or die (mysql_error()); $rows=mysql_num_rows($result2); ?> <p align="center"> You currently have <?php echo "$rows "; ?>product(s) in your cart.</p> <br> <div class="tabbanner"><strong>View the Shopping cart </strong></div> <table class="tableinsert"> <tr> <th>Quantity</th> <th>Item Name</th> <th>Price Each</th> <th>Extended Price</th> <th></th> <th></th> <th></th> </tr> <?php while ($row=mysql_fetch_array($result2)) { extract($row); $price; $quan; $extprice=number_format($price*$quan,2); ?> <tr> <td> <form action="change1.php" method="post"> <input type="hidden" name="prodnum" value="<?php echo $row['prodnum']; ?>"/> <input type="hidden" name="sessid" value="<?php echo $row['sess']; ?>" /> <input type="hidden" name="hidden" value="<?php echo $row['hidden']; ?>"/> <input type="text" name="qty" size="5" value="<?php echo $row['quan']; ?>"/> </td> <td><?php echo $row['prodnum']; ?></td> <td><?php echo $row['price']; ?></td> <td><?php echo $extprice ; ?></td> <td> <input type="submit" name="submit" value="change Qty" /> </form> </td> <td> <form action="xid.php" method="post"> <input type="hidden" name="prodnum" value="<?php echo $row['prodnum']; ?>"/> <input type="hidden" name="sessid" value="<?php echo $row['sess']; ?>" /> <input type="hidden" name="hidden" value="<?php echo $row['hidden']; ?>" <input type="hidden" name="qty" size="2" value="<?php echo $row['quan']; ?>" /> <input type="submit" value="Delete Item" name="submit" /> </form> </td> </tr> <?php $total=$extprice+$total; }; ?> Hi Guys,
Here is the code, once logged in using known credentials it should display the content "welcome..." but it doesn't, instead it is showing "you are not authorized..." as if the session['username']); isn't being taken?
<?php ini_set('display_errors',1); error_reporting(E_ALL); include_once 'includes/db_connect.php'; include_once 'includes/functions.php'; sec_session_start(); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Secure Login: Protected Page</title> <link rel="stylesheet" href="styles/main.css" /> </head> <body> <?php if (login_check($mysqli) == true) : ?> <p>Welcome <?php echo htmlentities($_SESSION['username']); ?>!</p> <p> This is an example protected page. To access this page, users must be logged in. At some stage, we'll also check the role of the user, so pages will be able to determine the type of user authorised to access the page. </p> <p>Return to <a href="index.php">login page</a></p> <?php else : ?> <p> <span class="error">You are not authorized to access this page.</span> Please <a href="index.php">login or register</a>. </p> <?php endif; ?> </body> </html>I am using WAMP and have made sure the username and password is in the database correctly, how do i debug this? the error reporting has been switched on but it doesn't help me is the problem with: <?php if (login_check($mysqli) == true) : ?>I am trying to follow this guide: http://www.wikihow.c...n-PHP-and-MySQL Please could i get some help on how to make the login "detect" the username from my MySQL database and display the username Thanks Attached Files login_success.php.jpg 14.31KB 0 downloads What im trying to do is have the webpage forward the user to another page after they fill out something for a certain element in the database. But the once I put the variable into a header for forwarding, the variable is thought to be a string instead of outputting its value it holds. Heres my code.... $variable = "nextPage"; header('Location:webpage.php?id=$variable'); But whats its doing is sending the user to the url "webpage.php?id=$variable" instead of "webpage.php?id=nextPage" What can I do to get the header to read the variable value and not the variable name? All help is greatly appreciated!!! I can't get the value of $edit_proj_name and $edit_content fromn the below code. Code: [Select] <?php if(isset($id)) { $edit_proj_id = $_GET['id']; $edit_query = "Select proj_name, content from rec_proj where proj_id = {$edit_proj_id}"; $edit_result = mysql_query($edit_query, $connection); $edit_proj_name = mysql_result($edit_result,$i,"proj_name"); $edit_content = mysql_result($edit_result,$i,"content"); } ?> I wonder what the problem is.. page.php <a href="cart.php?action=add&id=38"> cart.php session_start(); $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) $cart =$cart. ','.$_GET['id']; else $cart = $_GET['id']; } $_SESSION['cart'] = $cart; echo $cart; output: Insted of one time it adds the id two times. It prints : 38,38. can pls suggest me what's problem in the code. Thank's in advance. I'm using Session variables for the first time on a site I'm developing. I had it working fine while I was doing some admin and testing in subfolders. But the problem is I'm losing the session variables when I load the page from www.example.com, but it works from www.example.com/index.php. I would be happy to post some code if needed. I need to see if someone can point out something that I have missed or maybe even point me in the right direction on something. I have a PHP script that I have run into a problem on. The basic idea of the script is that it will send out HTML formatted emails to users of my web site. The problem I am running into is storing the HTML content in memory so I can do a str_replace() looking for certain markers in the HTML and replace them with lets say the users name and custom links that pertain to the particular user that the email is going to. Currently the HTML is being stored in a MySQL database, but I have already tried reading it from a flat file. Each time I only get the first 1024 characters returned. The problem seems to be that I am running into a PHP STRING limitation. From the reading that I have done on the subject, the limit should be 1024 characters PER LINE with the variable able to hold somewhere around 8MB worth of data. I can tell you that it does not matter how many \n I put into the HTML I still only get the first 1024 characters. Is there a way I can get the entire HTML file (about 12k characters) in memory so I can work with it and hand it off to the mail function? Thanks, whit3fir3 I'm more or less a noob. I have used the below code on another webpage, but on a new site that I am working on I attempted to trim the variable and now the page won't load. Can someone show me what I did wrong or a better way to accomplish this? Code: [Select] <?php # GRAB THE VARIABLES FROM THE URL $x = $_GET['x']; $valid = array('cat:1', 'cat:2', 'cat:3', 'cat:4', 'cat:5', 'cat:6', 'cat:7', 'cat:8', 'cat:9', 'cat:10', 'cat:11'); if(in_array($x, $valid)) $trimmed = trim($x, "cat:"); include_once $trimmed . '.inc'; else include '1.inc'; ?> When I used this before my variables did not have a colon in them, so I did not have to trim the variable, thus the last part of the script was: Code: [Select] if(in_array($x, $valid)) include_once $x . '.inc'; else include('1.inc'); ?> OK, I think I have confused this code and it is not calculating correctly. $ckifdue = mysql_query("SELECT * FROM accounting WHERE ClientID = '$clientid'") or die(mysql_error()); while($ckdue =mysql_fetch_array($ckifdue)){ if($ckdue['AmountDue'] == "0"){ $_SESSION['MONEYOWED'] = "0.00"; } else { $_SESSION['MONEYOWED'] = $_SESSION['MONEYOWED'] + $ckdue['AmountDue']; } if($ckdue['Amount1RS'] == "Balance Due"){ $totcol = $ckdue['TotalCollected']; echo " total collected:" . $totcol; $monpaid = $_SESSION['MONEYPAID']; echo "money paid in:" . $monpaid; $_SESSION['MONEYPAID'] = $totcol + $monpaid; echo "session money paid:" . $_SESSION['MONEYPAID']; } } $moneypaid = $_SESSION['MONEYPAID']; $moneyowed = $_SESSION['MONEYOWED']; echo "money paid:" . $moneypaid; echo " money owed:" . $moneyowed; $moneyowed = $moneyowed - $moneypaid; unset($_SESSION['MONEYOWED']); unset($_SESSION['MONEYPAID']); The echos look like: total collected:100.00money paid in:200session money paid:300 total collected:100.00money paid in:300session money paid:400money paid:400 money owed:0.00 There should be $100 due, $200 paid, so a balance of -100. There is 2 balance due reciepts, this is just not calclating right in the sessions. Why doesn't this code work... Code: [Select] // Initialize variables. $form_value = ''; $form_value = $_POST['form_value']; I get this error... Quote Notice: Undefined index: form_value Thanks, Debbie I wonder whether someone can help me please. I've put together the script below, which allows users to view their saved images in the original folder structure that they were saved in. Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['locationid']=$_POST['locationid']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php $galleryPath = 'UploadedFiles/' . $_SESSION['username'] . '/' . $_SESSION['locationid'] . '/'; $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; $descriptions = new DOMDocument('1.0'); $descriptions->load($absGalleryPath . 'files.xml'); $items = array(); for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) { $xmlFile = $descriptions->documentElement->childNodes->item($i); $path = $xmlFile->getAttribute('name'); $path = explode('/', $path); $t = &$items; for ($j = 0; $j < count($path); $j++) { if (empty($t[$path[$j]])) { $t[$path[$j]] = array(); } $t = &$t[$path[$j]]; } $t['/src/'] = $xmlFile->getAttribute('source'); $t['description'] = $xmlFile->getAttribute('description'); $t['size'] = $xmlFile->getAttribute('size'); } $basePath = empty($_GET['path']) ? '' : $_GET['path']; if ($basePath) { $basePath = explode('/', $basePath); for ($j = 0; $j < count($basePath); $j++) { $items = &$items[$basePath[$j]]; } } $files = array(); $dirs = array(); function urlpartencode(&$item, $index) { $item = rawurlencode($item); } foreach ($items as $key => $value) { if (isset($value['/src/'])) { $value['/src/'] = explode('/', $value['/src/']); array_walk($value['/src/'], 'urlpartencode'); $value['/src/'] = implode('/', $value['/src/']); $files[] = array( 'name' => $key, 'src' => $value['/src/'], 'description' => htmlentities($value['description'], ENT_COMPAT, 'UTF-8'), 'size' => htmlentities($value['size'], ENT_COMPAT, 'UTF-8') ); } else { $dirs[] = $key; } } $basePath = empty($_GET['path']) ? '' : $_GET['path']; $up = dirname($basePath); if ($up == '.') { $up = ''; } sort($files); sort($dirs); ?> <head> <title>View Image Folders</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="Styles/style.css" rel="stylesheet" type="text/css" /> <script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script> <style type="text/css"> <!-- .style1 { font-size: 14px; margin-top: 5px; margin-right: -50px; } --> </style> <body style="font-family: Calibri; color: #505050; margin-right: 160px; margin-left: -180px;"> <div align="right" class="style1"> <a href = "index.php" /> Add Images <a/> → <a href = "javascript:document.imagefolders.submit()"> View All Images </a> </div> <form id="imagefolders" name="imagefolders" class="page" action="gallery.php" method="post"> <div id="container"> </div> <div id="center"> <div class="aB"> <div class="aB-B"> <?php if ('Uploaded files' != $current['title']) :?> <?php endif;?> <div class="demo"> <input name="username" type="hidden" id="username" value="IRHM73" /> <input name="locationid" type="hidden" id="locationid" value="1" /> <div class="inner"> <div class="container"> <div class="gallery"> <table class="gallery-link-table" cellpadding="0" cellspacing="0"> <thead> <tr class="head"> <th class="col-name"> Name </th> <th class="col-size"> Size </th> <th class="col-description"> Description </th> </tr> </thead> <tbody> <tr class="directory odd"> <td class="col-name"> <a href="?path=<?php echo rawurlencode($up); ?>">..</a> </td> <td class="col-size"> </td> <td class="col-description"> </td> </tr> <?php $i = 1; ?> <?php foreach ($dirs as $dir) : ?> <tr class="directory <?php $i++; echo ($i % 2 == 0 ? 'even' : 'odd'); ?>"> <td><a href="?path=<?php echo rawurlencode(($basePath ? $basePath . '/' : '') . $dir); ?>"><?php echo htmlentities($dir, ENT_COMPAT, 'UTF-8'); ?></a></td> <td>Folder</td> <td></td> </tr> <?php endforeach; ?> <?php foreach ($files as $file) : ?> <tr class="<?php $i++; echo ($i % 2 == 0 ? 'even' : 'odd'); ?>"> <td><a target="_blank" href="<?php echo $galleryPath . $file['src']; ?>"><?php echo htmlentities($file['name'], ENT_COMPAT, 'UTF-8'); ?></a></td> <td><?php echo htmlentities($file['size'], ENT_COMPAT, 'UTF-8'); ?></td> <td><?php echo htmlentities($file['description'], ENT_COMPAT, 'UTF-8'); ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> </form> </body> </html> I can create the list of correct folders for the user and location, but when I click the folder name to drill down to the indvidual images I receive the following error: Quote Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml" in /homepages/2/d333603417/htdocs/development/imagefolders.php on line 17 Warning: Invalid argument supplied for foreach() in /homepages/2/d333603417/htdocs/development/imagefolders.php on line 54 Line 17 is this line: Quote $descriptions->load($absGalleryPath . 'files.xml') and line 54 is: Quote foreach ($items as $key => $value) { I know that in their own right, the piece of code which loads 'files.xml' and the code which loads the folders and images work, but it's combining them that creates the issue. I've done some research online, and I think the issue is to do with 'Session' variables and the 'foreach' array, but I'm not sure how to solve the problem. I just wondered whether someone could perhaps have a look at this please and let me know where I'm going wrong. Many thanks and regards First, apologies if this is in the wrong section, basically I am not sure what language my problem lies! Here is the general over view. I have a jquery script that automatically selects a group of sub categorys and pus them in a select list depending on the input of a first select list, so you can choose you main cat and then the sub cats for this cat appear in the next list, this all works fine, the basic code is below: Code: [Select] <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.get("scripts/func.php", { func: "drop_1", drop_var: $('#drop_1').val() }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } </script> <form action='do.php' method='post'> <select name="drop_1" id="drop_1"> <option value="" selected="selected" disabled="disabled">Select a Category</option> <?php getTierOne(); ?> </select> <span id="wait_1" style="display: none;"> <img alt="Please Wait" src="images/ajax-loader.gif"/> </span> <span id="result_1" style="display: none;"></span> This calls scripts/func.php Code: [Select] <?php //************************************** // Page load dropdown results // //************************************** function getTierOne() { $result = mysql_query("SELECT * FROM blog_cats") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['cat_id'].'">'.$tier['cat_name'].'</option>'; } } //************************************** // First selection results // //************************************** if($_GET['func'] == "drop_1" && isset($_GET['func'])) { drop_1($_GET['drop_var']); } function drop_1($drop_var) { include_once('../connect.php'); $result = mysql_query("SELECT * FROM blog_subs WHERE cat_id='$drop_var'") or die(mysql_error()); echo '<select name="tier_two" id="tier_two"> <option value=" " disabled="disabled" selected="selected">Select Sub Catergory</option>'; while($drop_2 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_2['sub_id'].'">'.$drop_2['sub_name'].'</option>'; } echo '</select> '; } ?> The problem I am having is getting the second select (tier_two) to pass to my form processing page. I just get an undefined variable error Many Thanks If I hard code the To address such as a@acme.com into my email function, no problems. But if I try using a variable I get an error. The error doesn't give me any valuable information and is generated from some old code that I never wrote. If I place the same variable such as "a@acme.com" into any other field such as content, subject I get the value for the variable so I know that it isn't null. I have tried all the methods of converting to a string and nothing changes. Any ideas? I am experimenting around with PDO, I have a DB handle class and instancing it in a function. The problem is when I want to bind elements in a query, for example I bind a parameter but I can only do it using a varible outside of the object. Code: [Select] <?php $database = new Database("localhost", "fry", "root", ""); $database->set_table("usertest"); $database->set_query("SELECT * FROM usertest WHERE user_name = :user_name"); $value = "matt"; $database->prepare_query(); $database->bind("parameter", ":user_name", $value ,PDO::PARAM_STR, 5); $database->execute(); while($result = $database->fetch()) { echo $result['user_name'].'<br />'; } ?> Is this bad OOP practice? I wanted to put $value = "matt"; into the Database class somehow here is the Database class Code: [Select] <?php class Database{ public $hostname; public $database; public $username; public $password; public $connection; public $prepare; public $query; public $table; public $fetch; public $bind_var; public $bind_val; function __construct($hostname, $database, $username, $password) { $this->hostname = $hostname; $this->database = $database; $this->username = $username; $this->password = $password; $this->Database_connection(); } public function Database_connection() { try { $this->connection = new PDO('mysql:host='.$this->hostname.';dbname='.$this->database, $this->username, $this->password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } } public function set_query($query) { $this->query = $query; } public function get_query() { return $this->query; } public function set_table($table) { $this->table = $table; } public function get_table() { return $this->table; } public function set_bind_var($var) { $bind_var = $var; } public function set_bind_val($val) { $bind_val = $val; } public function get_bind_var() { return $this->bind_var; } public function get_bind_val() { return $this->bind_val; } public function bind($bindtype, $val, $var, $pdo, $num) { if ($bindtype == "parameter") { $result = $this->prepare->bindParam($val,$var,$pdo); } return $result; } public function prepare_query() { $this->prepare = $this->connection->prepare($this->get_query()); } public function execute() { $this->prepare->execute(); } public function fetch() { return $this->prepare->fetch(); } } ?> Yet agian sorry for the sloppy code, this is mainly an experiment, would be very appriciated if someone could help me out with this problem. |