-
Posts
473 -
Joined
-
Last visited
-
Days Won
12
Everything posted by Strider64
-
Still using obsolete code, trying search for mysqli or PDO login tutorials....I'm sure you find plenty.
-
Successful registration, but does not write information in DB
Strider64 replied to Fregbind's topic in PHP Coding Help
I have two questions (they're probably stupid). First, why do you think this problem is a Regex problem? Second, if it doesn't store the user's info in the database table, how can you say that it works? Aren't you contradicting yourself? (Well, actually three but I can't count ) -
That was the major blunt of the problem, I still had a little logic error in the script though. However, fixing all the errors helped narrow it down. If anyone wonders what the solution is, here it is: <?php include("bouncyballdbs.php"); $lowestHighScore = $_POST['lowestHighScore']; $todaydate = date('Y-m-d H:i:s', strtotime($_POST['todaydate'])); $playername = $_POST['playername']; $playerscore = $_POST['playerscore']; $insertScore = 'INSERT INTO ' . DATABASE_TABLE . '( todaydate, playername, playerscore ) VALUES ( :todaydate, :playername, :playerscore )'; $insertParams = array( ':todaydate' => $todaydate, ':playername' => $playername, ':playerscore' => $playerscore ); $stmt = $pdo->prepare($insertScore); $stmt->execute($insertParams); try { /* I had to make it a <= symbol and set the limit to 1, for I only add 1 if the player gets */ /* a high score */ $query = 'DELETE FROM ' . DATABASE_TABLE . ' WHERE playerscore <= :lowestHighScore LIMIT 1'; $stmt = $pdo->prepare($query); $stmt->bindParam(':lowestHighScore', $lowestHighScore, PDO::PARAM_INT); $stmt->execute(); } catch (PDOException $e) { // Report the Error! error_log($e->getMessage(), 3, ERRORLOG_PATH); }
-
Thanks, I didn't think of the error logging....duh. However, I think that is what the problem is and if not I know now of error logging. Thanks Again.
-
I wrote a game in Flash Actionscript 3 about three years ago and I'm in the progress of updating my php code from old mysql to PDO. I have the scores inserting correctly from Actionscript to the Database Table. However, Deleting the lowest score doesn't seem to work, normally I can debug what is wrong, but the game runs in Flash. I think it's a logic error more than anything else. I kind of want to dust off this game, so I can improve the game play and the graphics. Here's is the short php code that transfer over from actionscript to the database. <?php include("bouncyballdbs.php"); $lowestHighScore = $_POST['lowestHighScore']; $id = $_POST['id']; $todaydate = date('Y-m-d H:i:s', strtotime($_POST['todaydate'])); $playername = $_POST['playername']; $playerscore = $_POST['playerscore']; $insertScore = 'INSERT INTO ' . DATABASE_TABLE . '( todaydate, playername, playerscore ) VALUES ( :todaydate, :playername, :playerscore )'; $insertParams = array( ':todaydate' => $todaydate, ':playername' => $playername, ':playerscore' => $playerscore ); $stmt = $pdo->prepare($insertScore); $stmt->execute($insertParams); $query = 'DELETE FROM ' . DATABASE_TABLE . ' WHERE playerscore < :lowestHighScore'; $stmt = $pdo->prepare($query); $stmt->bindParam(':lowestHighScores', $lowestHighScore, PDO::PARAM_INT); $stmt->execute(); The $id is no longer use and I should probably just take that out of the script. Thanks in advance, John
-
Or you can just do a var_dump($difference); or whatever variable you have for the dfference to see the different options besides the difference in days. I believe $difference->h would be hours?
-
The following might help you out: (Reading you're post again, I see you're pulling it from a database table, there are ways of doing that directly from MySQL also. I am sure some guru here will help you with that.) Though you can do it in PHP like this: <?php function number_of_days($date) { $today = new DateTime(); $future = new DateTime($date); $difference = $future->diff($today, true); echo "There are " . $difference->days . " days till the Detroit Tigers opening day!"; } number_of_days("2015-04-06 13:08:00");
-
Dependency interjection is pretty neat for the class(es) don't have to rely on another class(es). Here's kind of a silly example: <?php class Customer { private $firstName; private $lastName; public function __construct($firstName, $lastName) { $this->firstName = $firstName; $this->lastName = $lastName; } public function getFirstName() { return $this->firstName; } public function getLastName() { return $this->lastName; } } class Store { private $customer; private $product; public function __construct($product, Customer $customer) { $this->customer = $customer; $this->product = $product; } public function getCustomer() { return $this->customer; } public function getProduct() { return $this->product; } } $sales = new Store("iPhone 6", new Customer("Bill", "Gates")); $customer = $sales->getCustomer(); echo $customer->getFirstName() . ' ' . $customer->getLastName() . ' snuck into an Apple Store an bought an ' . $sales->getProduct() . "!<br>\n"; echo '<br>'; echo $sales->getCustomer()->getFirstName() . ' ' . $sales->getCustomer()->getLastName(); $person = new Customer("Steve", "Jobs"); $store = new Store("MicroSoft Windows", $person); //var_dump($store); echo '<br>'; echo $store->getCustomer()->getFirstName() . ' ' . $store->getCustomer()->getLastName() . ' Product : ' . $store->getProduct() . "<br>\n"; It's great for testing modules, I would guess it would also be great for a large project where you can have multiple people working on it.
-
If the $userdata variable is associative and you need to maintain the keys as they were, you can use the uasort() function <?php $usersdata = array( 12345 => array( 'username' => "Toby", 'email' => "toby@toby.com", 'permissions' => "1,2,3,4" ), 12346 => array( 'username' => "Tom", 'email' => "tom@tom.com", 'permissions' => "5,6,7,8" ), 12347 => array( 'username' => "Mable", 'email' => "mable@olddear.com", 'permissions' => "1,2,3,4" ), 12348 => array( 'username' => "Twit", 'email' => "twit@twit.com", 'permissions' => "1,2,3,4,5,6,7" ) ); echo '<h2>Array as is</h2><pre>'. print_r($usersdata, 1) . '</pre>'; // Sort by Username's Name: uasort($usersdata, function($x, $y) { return strcasecmp($x['username'], $y['username']); }); echo '<h2>Array sorted by username\'s name</h2><pre>' . print_r($usersdata, 1) . '</pre>'; The function can stay the same, but the uasort() function will take into account and maintain the index association of your values. - I know it's being a little bit nit picky but the uasort is better for associative arrays.
-
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Apple Bavarian Torte</title> </head> <body> <h1>Apple Bavarian Torte (4 stars)</h1> <p>A classic European torte baked in a springform pan. Cream cheese, sliced almonds, and apples make this the perfect holiday treat (12 servings).</p> <h2>INGREDIENTS</h2> <ul> <li>1/2 cup butter</li> <li>1/3 cup white sugar</li> <li>1/4 teaspoon vanilla extract</li> <li>1 cup all-purpose flour</li> <li>1 (8 ounce) package cream cheese</li> <li>1/4 cup white sugar</li> <li>1 egg</li> <li>1/2 teaspoon vanilla extract</li> <li>6 apples - peeled, cored, and sliced</li> <li>1/3 cup white sugar</li> <li>1/2 teaspoon ground cinnamon</li> <li>1/4 cup sliced almonds</li> </ul> <h2>DIRECTIONS</h2> <ol> <li>Preheat oven to 450 degrees F (230 degrees C).</li> <li>Cream together butter, sugar, vanilla, and flour.</li> <li>Press crust mixture into the flat bottom of a 9-inch springform pan. Set aside.</li> <li>In a medium bowl, blend cream cheese and sugar. Beat in egg and vanilla. Pour cheese mixture over crust.</li> <li>Toss apples with sugar and cinnamon. Spread apple mixture over all.</li> <li>Bake for 10 minutes. Reduce heat to 400 degrees F (200 degrees C) and continue baking for 25 minutes.</li> <li>Sprinkle almonds over top of torte. Continue baking until lightly browned. Cool before removing from pan.</li> </ol> <h2>REVIEWS</h2> <h3>4 stars</h3> <p>I loved the buttery taste of the crust which complements the apples very nicely.</p> <p><cite>Reviewed on Sep. 22, 2014 by MMASON.</cite></p> <h3>2 stars</h3> <p>Nothing special. I like the crust, but there was a little too much of it for my taste, and I liked the filling but there was too little of it. I thought the crunchy apples combined with the sliced almonds detracted from the overall flavor.</p> <p><cite>Reviewed on Sep. 1, 2014 by GLENDACHEF.</cite></p> <h3>5 stars</h3> <p>Delicious!! I recommend microwaving the apples for 3 minutes before baking, to soften them. Great dessert - I'll be making it again for the holidays.</p> <p><cite>Reviewed on August 28, 2014 by BBABS.</cite></p> </body> </html>
-
There's really nothing wrong in how you did it for it works and that is all that matters. However, this is how I would do it: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Temperature Conversion</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>Fahrenheit to Celsius Conversions</h1> <article> <?php $fahrenheit = 0; /* Convert Fahrenheit to Celsius */ function fahrenheitToCelsius($fahrenheit) { return round( ($fahrenheit - 32) * 5/9, 1); } do {//begining of loop $celsius= fahrenheitToCelsius($fahrenheit); echo "<p>$fahrenheit° F = $celsius° C.</p>"; ++$fahrenheit; } while ($fahrenheit <= 100);//end of loop ?> </article> </body> </html> However, I sure everyone else here would do it a little bit differently.
-
You sure it works? do {//begining of loop $convertCelsius = degreeConverter($degFahrenheit); echo "<p>$degFahrenheit degrees Fahrenheit = $convertCelsius degrees Celsius.</p>"; ++degFahrenheit; // Cough Cough.... } while ($degFahrenheit <= 100);//end of loop
-
<a href="index.php?category=pizza">Mmm Pizza</a> Then at the top or another page: <?php if (isset($_GET['category']) { $my_favorite_food = $_GET['category']; } ?>
-
You might want to consider using a form with individual time slots for the input, I have done something similar and can be seen by clicking on my signature link. Anyways, I have tried using contenteditable on tables in the past and it's a pain in the you-know-what. Loops can help you on in writing a form, I know this isn't exactly what you're talking about, but here is an example of what I'm talking about: <form class="appointmentBook" action="appointment.php" method="post"> <fieldset class="appFieldSet"> <legend class="appLegend"><?php echo $displayDate->format('F j, Y'); ?></legend> <?php $counter = 0; foreach ( $data as $appBook) { $output = (object) $appBook; echo '<input type="hidden" name="data[' . $counter . '][date]" value="' . $output->date . '">' . "\n"; echo '<input type="hidden" name="data[' . $counter . '][time]" value="' . $output->time . '">' . "\n"; echo '<input type="hidden" name="data[' . $counter . '][name]" value="' . $output->name . '">' . "\n"; echo '<label class="appLabel">' . $output->time . '</label>' . "\n"; echo '<input class="appText" type="text" name="data[' . $counter . '][info]" value="' . $output->info . '" ' . $readonly . '>' . "\n"; $counter++; } /* Don't show the submit button if no one is logged in */ if ($user) { echo '<input type="submit" name="submit" value="Submit" class="appSubmitBtn">' . "\n"; } ?> </fieldset> </form> You can style forms to look like you want to in CSS and you can even make them look like tables if you so want. HTH John
-
Here's a different way of doing it and it has the same results. <?php $userChoice = array(-2, "Please choose", -1, "N/A"); $year = date("Y"); $dob = range($year-18, $year-74); ?> <select name="birthyear" class="date"> <?php echo '<option value="' . $userChoice[0] . '">' . $userChoice[1] . '</option>' . "\n"; echo '<option value="' . $userChoice[2] . '">' . $userChoice[3] . '</option>' . "\n"; foreach ( $dob as $value ) { echo '<option value="'. $value . '">' . $value . '</option>' . "\n"; } ?> </select>
-
I remember a while back a company offering free products (samples) and what they did is took your credit card number (I am assuming they used a billing service) and charge a nominal fee like $5.00 or something like that. An when the product shipped the person was credited the money or so they said for I never tried it. The point being people will tend not to make multiple accounts if they might get socked with forking over money. The problem with this is two things, one you alienate some people and two some people won't bother signing-up. I fall in the the first category, I'm suspicious anytime a company asks for a CC#.
-
Close -> <?php class Cat { public $isAlive = true; public $numLegs = 4; public function __construct($name) { $this->name = $name; } public function meow() { return "Meow meow"; } } $cat1 = new Cat('CodeCat'); echo $cat1->meow();
-
Why don't you just output the strings to lower case using strtolower() : http://php.net/manual/en/function.strtolower.php that way you don't have no fuss no muss? That's what I would do.
-
define('DATABASE_HOST', 'localhost'); // normally it's called localhost: define('DATABASE_NAME', 'notes_db'); define('DATABASE_USERNAME', 'root'); // usually it's called root: define('DATABASE_PASSWORD', 'your password'); $con = new mysqli(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
-
If your ISP is still using that version either tell them to upgrade and if they won't then I would recommend shopping for a new ISP that is using a current version at least PHP 5.4 (preferably 5.5 or 5.6).
-
try $mail->isSendMail() instead of $mail->isSMTP() - I was having a problem yesterday with my remote server and this fix it. So it might be the problem? An like stated ports 465 or ports 587 need to be commented out $mail->Port = 587.
-
When I first started out I found it easier to write my own script than try to use someone else's script (Trust me I found out the hard way), for I found out that there is a lot of bad scripts on the Internet, scripts that use obsolete techniques or scripts that are way above by level of understanding (as a beginner). My opinion if you do use a script be it a library of some kind. From quickly glancing over you issue(s) I see that it deals with uploading images and maybe editing them. If you do an internet search I know you will find some pretty good php image libraries (I know I have used some of them myself). I think that would be better than trying to modifying someone's script to fit your need and I think you would find understanding PHP better. Just my opinion. You might even consider using a PHP framework that too would probably be better than using someone's script.
-
Should "secret questions" be used to allow password changes?
Strider64 replied to NotionCommotion's topic in PHP Coding Help
I personally would say no, for a lot of hackers use social hacks. By that I mean a would be hacker can get that kind of information in different ways, for example an official looking email asking those kind of questions. I'm also surprised by OWASP. -
Looking for Recommendation on Good Anonymous Email Application
Strider64 replied to TecTao's topic in PHP Coding Help
You can have it where the website handles the transactions where the emails are sent via the webpage (acting like the middle man) and you could give the seller (or buyer) to opt out if so desire.