Jump to content

premiso

Members
  • Posts

    6,951
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by premiso

  1. Post the full code of the page you are working with. As stated I doubt you are including the class file, which would be the exact reason why. Without the class definition the page has no clue what you are talking about.
  2. session_start(); $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['passsword']; I failed to see where $username and $password were given a variable. You said this comes from a form, so this should give them a valid value.
  3. I may be jumping the gun, but I do not think php can do this... Javascript is done on the POST side, PHP is all PRE. Without a page refresh it cannot be done. Javascript is your best bet. I could be wrong, but given your definition that is the only way I see it without refreshing all the iframe pages. Stick to JS it will make it easier.
  4. You arent assigning meallist any value. If you are posting to the page this adding this back in: $meallist = array(); foreach ($_REQUEST as $k=>$v) { if ($k=="meal") { $meallist[] = $v; } } That way you will get your data once again =)
  5. Post the code where you are defining $meallist. It is hard to help without code =)
  6. break; may work but I do not think so. I think the only way is to re-do your if statements. if (isset($_POST['save'])) { if(($_POST['password']!='' && $_POST['con_password']!='') && $_POST['password']==$_POST['con_password']) { $values[]="'md5($_POST[password])'"; $member_id=$_SESSION['member_id']; if($_POST['firstname']!='') { $values[]="mem_firstname='$_POST[firstname]'";} if($_POST['lastname']!='') { $values[]="mem_lastname='$_POST[lastname]'";} if($_POST['email']!='') { $values[]="mem_email='mysql_real_escape_string($_POST[email])'";} foreach($values as $value) { $updatedata="UPDATE $pagedb SET $value WHERE member_id=$member_id"; mysql_query($updatedata) or die($updatedata . '<br >'.mysql_error()); } echo "Changes have been saved! Click <a href='res_accmaint.php'>here</a> to reload your profile."; }else { echo "Bad Password!"; } } I believe that will get you your desired effect.
  7. number_format $_SESSION['authen'] = strtolower(trim($_POST["user"]));
  8. The error that was given indicates that the class was not included in the page via include('class.php'); because it is saying that there is no function called addMultipleItems(). Make sure you saved the class as a separate file and included that file.
  9. Where are you trying to initiate the connection? <?php include ("constants.php"); class DB_connect_select{ private $connection; public function _construct(){ if($this->connection=mysql_connect(host, user, password)) echo "Connection to DB successful! </BR>"; else die(mysql_error()); if(mysql_select_db(database, $this->connection)) echo "DB selection successful!"; else die(mysql_error()); } } ?> I think your if statements were just wrongly done, try the above and see if that works out. EDIT: Well then I would use protected. The connection string does not necessarily need to be private, but we also do not want to be easily changed. Oh and selection does not need to be tied to a string, like connection string does.
  10. What code are you using to get that error? The code should run fine as long as it is included and copied like it should be...
  11. <? if (is_array($_POST)) { foreach ($_POST as $key => $value) { if ($is_array($value)) { foreach ($value as $subkey => $subvalue) { ?> <input type="hidden" name="<?php echo $subkey; ?>" value="<?php echo $subval; ?>"> <? } } else { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <? } } } Check to make sure that post is an array before looping through it. Also make sure that your display_errors is turned on because I bet that is why it is stopping. This is just a blind guess though without any error information.
  12. http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Topic that is stickied explains about everything. Basically you are outputting the HTML to the browser before calling the header function. That is not allowed, either move the processing to before the include(html) portion or use a javascript redirect: $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/thanks.php'; echo '<script type="text/javascript>window.location = \'' . $url . '\';</script>'; exit();
  13. So $dbh houses your connection string. Make sure that is not the same for both databases. <?php $dbh=mysql_connect ("localhost", "dcompany_XXXXX","XXXXXX") or die('Cannot connect to the database because: ' . mysql_error()); mysql_select_db ("dcompany_store", $dbh); // this part is just an example of what I am talking about. $dbh2=mysql_connect ("localhost", "dcompany_XXXXX","XXXXXX") or die('Cannot connect to the database because: ' . mysql_error()); mysql_select_db ("dcompany_orders", $dbh2); ?> <?php //Get this book price include('../CMS/global.inc.php'); $result = mysql_query("SELECT * FROM `books` WHERE `ncode` = '$id' AND `show` ='Y' ", $dbh); $row = mysql_fetch_array($result); $theprice = $row[pricelist]; if ($_SESSION['item']) {//the user is trying to add an item to his cart //echo "It is Entering this scope "; //check if the user has a pending order or not include('../CMS/operations.inc.php'); $result = mysql_query("SELECT * FROM `ordersmaster` WHERE `member` = '$user' AND `status` ='P' ", $dbh2); // this assumes you assigned the other reference to $dbh2 $row = mysql_fetch_array($result); if (mysql_num_rows($result) > 0 ) { // and some code lines go here } } ?> I hope that helps you out.
  14. MySQL database would be my preference.
  15. Whoops here it is corrected: <?php include ("constants.php"); class DB_connect_select{ private $connection; public function __construct(){ $this->connection=mysql_connect(host, user, password); if($this->connection) echo "Connection successful! </BR>"; } } ?> Should be just construct, not constructor. Sorry about that.
  16. You stated you need to connect to 2 different databases. Right? In order to do this, where the mysql_connect statement is needs to modified to assign the resource for the connection to an ID. However, if you are saying databases as tables, as I can see one table is books and the other is ordermaster, than my reply is null and void. Let me know which we are dealing with and I will gladly try to provide some more insight.
  17. You need a constructor, I am assuming you are not using PHP 5 for this: <?php include ("constants.php"); class DB_connect_select{ var $connection; function DB_connect_select(){ // name of the class denotes constructor in php < 5. $this->connection=mysql_connect(host, user, password); if($this->connection) echo "Connection successful! </BR>"; } } ?> For PHP 5 it would be: <?php include ("constants.php"); class DB_connect_select{ private $connection; public function __constructor(){ $this->connection=mysql_connect(host, user, password); if($this->connection) echo "Connection successful! </BR>"; } } ?>
  18. Without code hard to help. I bet you are not using the link_id feature for your mysql_query. The function mysql_connect returns a valid resource ID to use strictly for that connection. I would look into that.
  19. Honestly, with that code you are defeating the purpose of classes and objects. Here is a revised version of your code with examples: usage.php: <?php session_start(); include('order.php'); // include the order class. if (isset($_SESSION['order'])) { $order = unserialize($_SESSION['order']); }else { $order = new Order(); } // incase we want to reset our test data. if ($_REQUEST['reset'] == "ok") { $order = new Order(); } $meallist = array(0 => array(1, 2, 3, 4)); $order->addMultipleItems($meallist[0]); $items = $order->getItems(); foreach ($items as $item) { echo $item->getID() . "<br />"; } // now use $order as you wish $order->addItem(5); $item = $order->getItemByIndex(0); echo "Item ID of " . $item->getID() . " is at index of 0<br />"; echo "We currently have " . $order->getItemCount() . " items in your order.<br />"; $_SESSION['order'] = serialize($order); // add at the end incase of any changes they all get caught. ?> order.php <?php class Item { private $id; public function __construct($id) { $this->id = $id; } public function setID($id) { $this->id = $id; } public function getID() { return $this->id; } } class Items { private $itemArray = array(); // optional parameter to take in an array of ids or a single ID public function __construct($ids = "") { if ($ids != "" && is_array($ids)) { $this->addMultipleItems($ids); }elseif ($ids != "") { $this->addItem($ids); } } // adds an item. public function addItem($itemID) { // use the count to set the index for the item. $this->itemArray[count($this->itemArray)] = new Item($itemID); return true; } // returns all items public function getItems() { return $this->itemArray; } // returns an item object -1 = no item in the array at the index public function getItemByIndex($index) { return (isset($this->itemArray[$index]))?$this->itemArray[$index]:-1; } // returns the item requested by id. public function getItemByID($id) { if (is_array($this->itemArray)) { foreach ($this->itemArray as $item) { if ($item->getID() == $id) return $item; } } return -1; } public function getIndexOfItemByID($id) { if (is_array($this->itemArray)) { foreach ($this->itemArray as $key => $item) { if ($item->getID() == $id) return $key; } } return -1; } public function getItemCount() { return count($this->itemArray); } // takes in an array of IDs and creates each item. public function addMultipleItems($ids) { foreach ($ids as $val) { $this->itemArray[$this->getItemCount()] = new Item($val); } } public function setItemIDByIndex($index, $newID) { return $this->itemArray[$index]->setID($newID); } public function setItemIDByIID($oldID, $newID) { $index = getIndexOfItemByID($oldID); if ($index != -1) return $this->itemArray[$index]->setID($newID); return false; } } class Order { private $items; // takes in a set of ids or a single id, either way our // items constructor will handle it. function __construct($ids="") { $this->items = new Items($ids); } public function addItem($id) { $this->items->addItem($id); } public function addMultipleItems($ids) { $this->items->addMultipleItems($ids); } // returns an item for the given index, ie 0, 1, 2, 3, 4 public function getItemByIndex($index) { return $this->items->getItemByIndex($index); } public function getItemCount() { return $this->items->getItemCount(); } public function setItemIDByIndex($index, $newID) { return $this->items->setItemIDByIndex($index, $newID); } public function setItemIDByID($oldID, $newID) { return $this->items->setItemIDByID($oldID, $newID); } public function getItemByID($id) { return $this->items->getItemByID($id); } function getItems() { return $this->items->getItems(); } } ?> Now the class is not fully tested, but with the examples given it has been tested and seems to work. If you need help explaining that let me know. Using this concept you should be able to have as many items as you want and should be able to loop through each item with ease. Anyhow I was just really bored so yea.
  20. I knew I was missing something from that. lol I could not put my finger on it, now I have to go and re-do my code to take in an unknown and solve it lol. =)
  21. Even if there were a 1,000 logos, it shouldnt crash the server at all. It would probably only had a second or two onto the processing time if that... And if only 1 logo is active at a time, this will find the 1 row and just update that one row. SQL is very very efficient.
  22. Sounds like an html issue, not php. I fail to see where this involves PHP?
  23. One way to do it, and probably not the best way but it should work is: <?php //convert all the posts to variables: $id = $_POST['id']; mysql_query("UPDATE logos SET active = '0' WHERE active = '1'"); // set all active logos to inactive mysql_query("UPDATE logos SET active = '1' WHERE id = '$id' "); // set logo with id $id to active. $result = mysql_query($sql) or die("ERROR: " . mysql_error() . "<Br>SQL: " . $sql); ?> That should do the trick.
  24. In that case, do I need to worry about stripslashes or mysql_real_escape_string with what I am doing? premiso states above that you should escape the post or get data. Thanks again! You escape data going into a Database. Any data potentially used for pulling out a query that is coming from an outside source, such as GET or POST, you escape it to avoid SQL Injection.
  25. I wouldn't know how to do that. I can do it in hand, but I wouldn't know how to put it into code. I tried it last night, not fully tested but for my simple tests it worked. Right now it is just a function, but yea. <?php function solve_quadratic($a, $b, $c) { if ((2 * $a) == 0) { $x[0] = "Cannot divide by 0, this is impossible to do."; return $x; } $x[0] = ((($b * -1) + sqrt((pow($b, 2) - (4 * $a * $c)))) / (2 * $a)); $x[1] = ((($b * -1) - sqrt((pow($b, 2) - (4 * $a * $c)))) / (2 * $a)); if ($x[0] == "NAN" || $x[1] == "NAN") { $x[0] = "This quadratic is not solveable."; unset($x[1]); return $x; }else { $x[2] = ($b * -1) . " +/- SquareRoot (" . $b . "^2 - 4*$a*$c) / 2 * $a"; $x[3] = ($b * -1) . " +/- SquareRoot (" . pow($b, 2) . " + " . (4 * $a * $c) . ") / " . (2 * $a); $x[4] = ($b * -1) . " +/- SquareRoot (" . (pow($b, 2) + (4 * $a * $c)) . ") / " . (2 * $a); $x[5] = ($b * -1) . " +/- " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a); $x[6] = ($b * -1) . " + " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a); $x[7] = ($b * -1) . " - " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a); $x[8] = ($b * -1) + sqrt(pow($b, 2) - (4 * $a * $c)) . " / 2 = " . (($b * -1) + sqrt(pow($b, 2) - (4 * $a * $c))) / 2; $x[9] = ($b * -1) - sqrt(pow($b, 2) - (4 * $a * $c)) . " / 2 = " . (($b * -1) - sqrt(pow($b, 2) - (4 * $a * $c))) / 2; } return $x; } echo "<pre>"; print_r(solve_quadratic(1, 3, -4)); echo "<br />"; ?> lol I was pretty bored yestarday, day off for Veterans Day.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.