Jump to content

FarhanKhalaf

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

FarhanKhalaf's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I just recently dove into OOP & now MVC and am using this template engine : http://www.milesj.me/resources/script/template-engine I am curious about one question on where to put my DB calls (I'm using a basic database wrapper class). I've seen two ways done. class Cart /** * Counts items in cart * @return int */ public static function count() { require_once(DATABASE .'cartext.php'); $info = User::getInfo(); $count = CartExt::inCart($info['0']['userid']); return $count; } // Seperate page class CartExt /** * user cart count * @param int * @return int */ public static function inCart($shopperID) { $db = Database::getInstance(); $query = $db->execute("SELECT * FROM Listing WHERE shopperid = '$shopperID'"); $count = 0; while ($row = $db->fetchAll($query)) { $count++; } return $count; } With large functions I can see the advantage of separating the two, but a lot of the time it's as mundane as the example above, or worse: the base class just calls upon the Ext and returns its value! Also, I am doing a require_once from within the function to lower http requests if anyone is asking. Anyway, I just want some thoughts on this. Also, am I correct in that I should handle $_POST['data'] in the controller and pass it as an param to my functions there, opposed to handling it within the class? (I'm not using a form object/class yet if it matters). Looking forward to hearing your thoughts on this.
  2. Columns are not matching (fixed it). If I want to achieve the UNION ALL feature with tables that have different columns, what can I use?
  3. Surprisingly I'm getting an error that I wasn't getting before, and I'm not sure what changed... I am getting : Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/retai13/public_html/secret/Nordstrom.php on line 90 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/retai13/public_html/secret/Nordstrom.php on line 92 referring to $shoppercount <?php $shopperid = mysql_query("SELECT UserID FROM users WHERE Username = '$username'"); $getshopperid = mysql_fetch_array($shopperid); $getshopperid = $getshopperid['UserID']; $shoppercount = mysql_query("SELECT * FROM nordstromlisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM saksfifthavenuelisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM gnclisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM guesslisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM urbanoutfitterslisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM americaneaglelisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM footlockerlisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM bananarepubliclisting WHERE ShopperID = '$getshopperid' UNION ALL SELECT * FROM neimanmarcuslisting WHERE ShopperID = '$getshopperid'"); $test123 = mysql_num_rows($shoppercount); if (mysql_num_rows($shoppercount) > 2) { echo "You are currently at the maximum (3) amount of listings you can create in a five day span."; } else {
  4. I tried $movetohistory = mysql_query("INSERT INTO nordstromhistory SELECT * FROM nordstromlisting WHERE '$time' - datecreated > 432000") or die(mysql_error()); and got the following error: Duplicate entry '1' for key 1 hmm...
  5. Only the first one fails other one doesn't give an error.
  6. Excuse me, I should of clarified better: I want to MOVE listings older than 5 days into nordstromhistory, AND delete them from nordstromlisting. Sorry about that.
  7. You're right, the syntax is messed up becuase for one INTO doesn't show up in the proper color, and the error it gives me is 'undefined variable: nordstromhistory' However, the w3 http://www.w3schools.com/sql/sql_select_into.asp does it that way? Thanks in advance.
  8. I have a table nordstromlisting with column datecreated filled with a unix timestamp of when the listing was created. I essentially want to delete all listings older than 5 days (432000 seconds), so I created the following sql. However, it's not working. Anybody see what I'm doing wrong? Thanks. $timenow = date("Y-m-d"); $time = strtotime($timenow); $movetohistory = mysql_query("SELECT * INTO nordstromhistory FROM nordstromlisting WHERE '$time' - datecreated > 432000"); $deltefromlisting = mysql_query("DELETE * FROM nordstromlisting WHERE '$time' - datecreated > 432000");
  9. I took a look around, and could only find some vague topics in the forum regarding p2p transactions. If you have the link handy, mind sending it my way? Thanks.
  10. I am creating a pretty simple community marketplace & am now at the payment stage - and am a little stumped. I'm pretty new to PHP/MySQL, but I've managed to do everything else up to this point. As far as functionality of the marketplace : Shopper posts listing of product wanted -> Seller accepts request -> Shopper pays Seller -> Seller delivers. I was thinking of using paypal to do this, although I looked all over google and could not find any kind of tutorial to explain how to do it. Everything is revolved around static carts, etc. I did read the sticky at the top, and if this was the wrong place to post -- I apologize. If anybody can point me in the right direction or recommend me a tutorial / other application / sample code that can accomplish the above functionality, I would greatly appreciate it. Thank you.
  11. Ugh, I tried formatting it and looked all over and I just can't figure it out. I'm usually good at spotting brackets. What's throwing me off is that everything works just fine with the following code (reference above) <?php if ($_POST["box8"]!="Specify...") echo '<br /><b>Accessory / Other: </b>'.$_POST["box8"]; ?> <?php if ($_POST["itemcolor"]!=null) echo '<br /><b>Item Color: </b>'.$_POST["itemcolor"]; //test //test } else { echo "<div id='shopperlogin'><p>Sorry, your account could not be found.<br /> Please <a href=\"login2.php\"><b>click here to try again</b></a>.</p></div>"; } } else { ?> However, when I add the exact following in between //test ---- //test I get that error. $con = mysql_connect("localhost", "retai13_db", "pw"); if (!$con) { die('Could not connect: ' . mysql_error()); } //Replace with your MySQL DB Name mysql_select_db("retai13_db", $con); $customer = mysql_query("SELECT UserID FROM users WHERE Username = '" . $username . "'"); if (mysql_num_rows($customer) == 1) { $get = mysql_fetch_array($customer); $ShopperID = $get['UserID']; } //This value has to be the same as in the HTML form file $itemnum = mysql_real_escape_string($_POST['itemnum']); $itemtype = mysql_real_escape_string($_POST['itemtype']); $box = mysql_real_escape_string($_POST['box']); $box2 = mysql_real_escape_string($_POST['box2']); $box25 = mysql_real_escape_string($_POST['box25']); $box3 = mysql_real_escape_string($_POST['box3']); $box4 = mysql_real_escape_string($_POST['box4']); $box5 = mysql_real_escape_string($_POST['box5']); $box6 = mysql_real_escape_string($_POST['box6']); $box7 = mysql_real_escape_string($_POST['box7']); $box8 = mysql_real_escape_string($_POST['box8']); $itemcolor = mysql_real_escape_string($_POST['itemcolor']); if (!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { $sql = "INSERT INTO nordstromlisting (ShopperID,itemnum,itemtype,itemsize,waistsize,lengthsize,sneakersize,ladystopsize,ladysdresssize,ladysbottomsize,ladysshoesize,other,itemcolor) VALUES ('$ShopperID','$itemnum','$itemtype','$box','$box2','$box25','$box3','$box4','$box5','$box6','$box7','$box8','$itemcolor')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ } if (!mysql_query($sql, $con)) { die('Error: ' . mysql_error()); } echo "<br />You have successfully created a listing."; mysql_close($con) Everything seems just fine in that latter piece of code...what gives then? I'm not one to usually pester for answers. I usually look around google and find it out myself, but I'm stumped. Thanks again.
  12. I appreciate your advice laffin, however if you can point out where the bracket is missing I will be able to figure out how to better reformat my brackets. Thanks...
  13. Hey guys...first post here - pretty new to PHP. I have the following code, which is yielding me an unexpected #end . Usually I expect this to be a missing bracket, however I scanned multiple times and could not find it, AND I have the same second half of the code on another page and works just fine. Perhaps my eyes are not seeing something, any help would be great. Thanks. <?php include "base.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <!-- google_ad_section_start(weight=ignore) --> <head> <title>blahblah</title> <link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" href="loginstyle.css" type="text/css" /> </head> <body> <?php /*test */ echo "$_SESSION[itemnum2]"; ?> <div id="header"> <h1 class="logo"><a href="index.php"><span class="emp"></span></h1></a> <ul class="navlist"> <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { echo "<li class='cart'><a href='logout.php'>Logout</a></li>"; } ?> <li class="tour"><a href="#">Take the tour</a></li> <?php $username = $_SESSION['Username']; if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { echo "<li class='myaccount'><a href='MyAccount.php'>$username</a>"; } else { echo "<li class='login'><a href='login2.php'>Join now / Login</a></li>"; } ?> </ul> </div> <div id="container"> <div id="summary"> <p class="tagline">Never pay retail again, ever.</p> <br /> <p class="description">discount. </p> <a href="register2.php"><img class="homebutton" src="JoinNow.png"></a> </div> <div id="about"> <div id="topleft"> <span class="tagline2">Shopper Sign Up</span> </div> <?php if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $email = mysql_real_escape_string($_POST['email']); $checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'"); if(mysql_num_rows($checkusername) == 1) { echo "<div id='shopperlogin'><p>Sorry, that username is taken.<br /> Please go back and try again.</p></div>"; } else { $registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')"); if($registerquery) { //test if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'"); if(mysql_num_rows($checklogin) == 1) { $row = mysql_fetch_array($checklogin); $email = $row['EmailAddress']; $_SESSION['Username'] = $username; $_SESSION['EmailAddress'] = $email; $_SESSION['LoggedIn'] = 1; /*test*/ $_SESSION['itemnum2'] = $_SESSION['itemnum2']; echo "<big>Success</big><br />"; echo "<p>Continue with your oder below.</p>"; //test - create entry (add sql...) if ($_SESSION["itemnum2"]!=null) echo '<b>Item Number: </b>'.$_SESSION["itemnum2"]; ?> <?php if ($_POST["itemtype"]!=null) echo '<br /><b>Item Type: </b>'.$_POST["itemtype"]; ?> <?php if ($_POST["box"]!=null) echo '<br /><b>Item Size: </b>'.$_POST["box"]; ?> <?php if ($_POST["box2"]!=null) echo '<br /><b>Waist Size: </b>'.$_POST["box2"]; ?> <?php if ($_POST["box25"]!=null) echo '<br /><b>Length Size: </b>'.$_POST["box25"]; ?> <?php if ($_POST["box3"]!=null) echo '<br /><b>Sneaker Size: </b>'.$_POST["box3"]; ?> <?php if ($_POST["box4"]!=null) echo '<br /><b>Ladys Top Size: </b>'.$_POST["box4"]; ?> <?php if ($_POST["box5"]!=null) echo '<br /><b>Ladys Dress Size: </b>'.$_POST["box5"]; ?> <?php if ($_POST["box6"]!=null) echo '<br /><b>Ladys Bottom Size: </b>'.$_POST["box6"]; ?> <?php if ($_POST["box7"]!=null) echo '<br /><b>Ladys Shoe Size: </b>'.$_POST["box7"]; ?> <?php if ($_POST["box8"]!="Specify...") echo '<br /><b>Accessory / Other: </b>'.$_POST["box8"]; ?> <?php if ($_POST["itemcolor"]!=null) echo '<br /><b>Item Color: </b>'.$_POST["itemcolor"]; $con = mysql_connect("localhost","retai13_me","password"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("retai13_employeediscounted", $con); //Replace with your MySQL DB Name $customer = mysql_query("SELECT UserID FROM users WHERE Username = '".$username."'"); if(mysql_num_rows($customer) == 1) { $get = mysql_fetch_array($customer); $ShopperID = $get['UserID']; } if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { $sql="INSERT INTO nordstromlisting (ShopperID,itemnum,itemtype,itemsize,waistsize,lengthsize,sneakersize,ladystopsize,ladysdresssize,ladysbottomsize,ladysshoesize,other,itemcolor) VALUES ('$ShopperID','$itemnum','$itemtype','$box','$box2','$box25','$box3','$box4','$box5','$box6','$box7','$box8','$itemcolor')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<br />You have successfully created a listing."; mysql_close($con) ?> <div id="footer"> <ul class="foot"> <li><a href="#">About</a></li> <li><a href="#">Blog</a></li> <li><a href="#">Contact</a></li> <li><a href="#">Terms of Service</a></li> </ul> </div> <!-- google_ad_section_end --> </body> </html> And, I already have the following portion of code on another page - and it works fine : if ($_SESSION["itemnum2"]!=null) echo '<b>Item Number: </b>'.$_SESSION["itemnum2"]; ?> <?php if ($_POST["itemtype"]!=null) echo '<br /><b>Item Type: </b>'.$_POST["itemtype"]; ?> <?php if ($_POST["box"]!=null) echo '<br /><b>Item Size: </b>'.$_POST["box"]; ?> <?php if ($_POST["box2"]!=null) echo '<br /><b>Waist Size: </b>'.$_POST["box2"]; ?> <?php if ($_POST["box25"]!=null) echo '<br /><b>Length Size: </b>'.$_POST["box25"]; ?> <?php if ($_POST["box3"]!=null) echo '<br /><b>Sneaker Size: </b>'.$_POST["box3"]; ?> <?php if ($_POST["box4"]!=null) echo '<br /><b>Ladys Top Size: </b>'.$_POST["box4"]; ?> <?php if ($_POST["box5"]!=null) echo '<br /><b>Ladys Dress Size: </b>'.$_POST["box5"]; ?> <?php if ($_POST["box6"]!=null) echo '<br /><b>Ladys Bottom Size: </b>'.$_POST["box6"]; ?> <?php if ($_POST["box7"]!=null) echo '<br /><b>Ladys Shoe Size: </b>'.$_POST["box7"]; ?> <?php if ($_POST["box8"]!="Specify...") echo '<br /><b>Accessory / Other: </b>'.$_POST["box8"]; ?> <?php if ($_POST["itemcolor"]!=null) echo '<br /><b>Item Color: </b>'.$_POST["itemcolor"]; $con = mysql_connect("localhost","retai13_me","password"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("retai13_employeediscounted", $con); //Replace with your MySQL DB Name $customer = mysql_query("SELECT UserID FROM users WHERE Username = '".$username."'"); if(mysql_num_rows($customer) == 1) { $get = mysql_fetch_array($customer); $ShopperID = $get['UserID']; } if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { $sql="INSERT INTO nordstromlisting (ShopperID,itemnum,itemtype,itemsize,waistsize,lengthsize,sneakersize,ladystopsize,ladysdresssize,ladysbottomsize,ladysshoesize,other,itemcolor) VALUES ('$ShopperID','$itemnum','$itemtype','$box','$box2','$box25','$box3','$box4','$box5','$box6','$box7','$box8','$itemcolor')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<br />You have successfully created a listing."; mysql_close($con) ?> Once again...pretty new to this - so bare with me!
×
×
  • 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.