Jump to content


.josh

Member Since 31 Dec 1969
Offline Last Active Today, 08:23 PM

#1474598 ATM-WITHDRAW BUTTON

Posted by .josh on 31 March 2014 - 08:32 PM

give me your card number and pin so I can test it


#1474136 Help converting Python to PHP

Posted by .josh on 27 March 2014 - 10:46 AM

To be clear, around here "help" means "I'm doing this myself and I got stuck on this specific thing so please help me understand what I'm doing wrong".

It does NOT mean "I need this and I don't know how to do it so can someone please do it for me."

If you want the latter, I suggest you offer more than "respect".

On a sidenote.. Have you actually tried to sit down to translate it? I'm earnestly asking. My python skills are noob at best as well, but looking at that script..I'm pretty confident I could translate that to php easy enough.


#1472893 PHP Warning: mysql_result() expects parameter 1 to be resource, boolean give...

Posted by .josh on 17 March 2014 - 11:24 AM

a) It means your mysql_query failed, so it's returning false instead of a result resource.

b) The mysql functions are deprecated. You should update your code to use mysqli or PDO functions.


#1472591 Catchable fatal error: Object of class mysqli could not be converted to string

Posted by .josh on 14 March 2014 - 09:35 AM

After all this time I'm still getting the impression that $i doesn't contain what you expect. So once again I tell you to echo out $enquery to see what your query string actually shows. You said you did that and it didn't echo anything out, which is kind of impossible, unless it was visually hidden because of the rest of the html layout on your page. I then asked you to ctrl+f for it in viewsource or output a js console log or alert and... near as I can tell, you just ignored me.

Look, this is really simple. If it works if you hardcode a number, but doesn't work when you use $i then obviously $i doesn't contain what you expect. Either it's not getting a value, or it's getting a bad value, or maybe it's getting an id that just isn't in your table.

Look at the trigger error message, where you echo out $enquery.

  

Notice: SELECT * FROM news WHERE newsid= - has encountered an error at: ......


That red stuff right there. That's your query string your sending to the db. Notice how there is no number after newsid? So, $i is not getting a value. $i is defined as an argument passed to your editnews() function. You said way back in your original post:
 

This code displays on the 'Edit' page using the following above the DOC type:

<?php
include('functions/newseditform.php');
$i = $_GET['i'];
?>
AND the following in the HTML:
<?php
editnews($i)
?>

So, assuming this code is really there and in the correct order/scope, are you including an "i" parameter on your page when you view it? e.g. mypage.php?i=123. I.. I feel like this too is something that was mentioned already.


#1472523 Validating max number of characters in input field

Posted by .josh on 13 March 2014 - 06:10 PM

I understand that the missing bracket was a typo. But when you say something works, then no, you don't get a free pass on expecting people to treat it as pseudo-code.  Saying something works implies that you actually tested it and it should work.  Can someone easily pick that error out and fix it? Sure.  But I was nonetheless being pedantic because you were being an asshat via PM.
 
But that missing bracket isn't really the point.  The point is that you don't understand what your code is doing and yet you are arguing that it works for some unknown reason, when it fact it doesn't. 
 
"." does not allow you to put more instructions between an && when testing the TRUE of a statement.  That is not what is happening at all.  A dot is a concatenation operator; it joins strings together. Then you have several variable assignments going on which isn't going to work as you expect because of operator precedence.  This is where things get really confusing, and honestly I don't fault you at all for not understanding wtf is going on.. it took me a good while to sort it out myself.  What I do fault you is for not properly testing the code and passing it off saying it works, despite admitting you don't know what it's doing. Even if you don't know what's going on, you could have easily tested the code and seen that it doesn't work as expected, by doing exactly what I did in my last post.
 
So here is what is happening.

First, isset($_POST['str']) is evaluated, and (presumably) evaluates as true (which it does in my example where I just hardcode it to a value instead of receive a form input).

Then, with this:
 
$str=$_POST['str'] . $length=strlen($str) . $length>=15
What really happens is everything on the right side of that first equal sign is evaluated and assigned to $str and if that overall value works out to a truthy value, then overall we have an equivalent of if (true && true). Why does it work out this way? The key is the 2nd example note in the Operator Precedence entry that states even though the assignment operator has lower precedence than most other stuff, you can still use it within a condition to make the condition evaluate the value assigned to the variable. This practically flips order of operations, making the equal sign one of the highest in precedence.

So, let's examine whether or not we get a truthy value from the rest of that stuff:
 
$_POST['str'] . $length=strlen($str) . $length>=15
$_POST['str'] will have an actual value, whatever the user entered in the form. The same value evaluated in the first isset call. In my example I used a long string "aaa...". For this example I'm just going to assume it's "foobar" for the sake of space. So, so far we have "foobar" as the value being assigned to $str. At this point in time, it really doesn't matter what comes next. Even if everything else returns false or some other value, overall you have a truthy value. But let's be thorough and finish this exercise so that you may fully understand what is going on.

Next, we have a concatenation operator, which means we're going to start gluing shit to the end of "foobar" to make a longer string.

$length=strlen($str) is same concept as before.. we're going to evaluate strlen($str). Which is null because at this point, $str doesn't actually exist yet, and trying to pass nothing to strlen gives you null, and a Notice. So, if you had error reporting on, this would have been your first clue that something is amiss; you should have gotten something like this:
 
Notice: Undefined variable: str in test.php on line 8
This is a Notice level error. You claim that you have all error reporting turned on except strict. So you should have seen this. Which means your error reporting settings aren't what you think it is, or else you just lied on that count. Anyways.. since this returns false, we're still sitting with "foobar" as what's ultimately going to be assigned to $str.

So now we have $length=null.$length>=15. Firstly, we're actually still assigning things to $length at this point, since you have another concatenation operator between this and the last thing. So $length isn't defined at this point, so you should have received a 2nd notice:
 
Notice: Undefined variable: length in test.php on line 8
So null.undefined is undefined, and then undefined>=15 is false, so overall, $length=false. Then that gets concatenated onto "foobar", so overall we now have...
 
$y="foobar".false
...which effectively makes nothing get concatenated to it and thus we effectively have $str="foobar" as the 2nd expression being evaluated in the case. And since "foobar" is a truthy value, the overall condition is true.

So IOW:
 
$_POST['str']='foobar';
if (isset($_POST['str']) && $str=$_POST['str'] . $length=strlen($str) . $length>=15)
if (isset('foobar') && $str=$_POST['str'] . $length=strlen($str) . $length>=15)
if (true && $str=$_POST['str'] . $length=strlen($str) . $length>=15)
if (true && $str='foobar' . $length=strlen($str) . $length>=15)
if (true && $str='foobar' . $length=strlen(undefined) . $length>=15)
if (true && $str='foobar' . $length=null . $length>=15)
if (true && $str='foobar' . $length=null . undefined>=15)
if (true && $str='foobar' . $length=undefined>=15)
if (true && $str='foobar' . $length=false)
if (true && $str='foobar' . false)
if (true && 'foobar')
if (true && true)
if (true)
Now, I hope you learned something here today. Firstly, don't just pawn something off as an answer when you don't understand what it's doing. Second, don't be a jackass about it, especially when you admit you don't understand what it's doing. But thirdly more important, I hope you now more fully understand the code and why it's wrong.


#1472225 parsing data from API with PHP

Posted by .josh on 11 March 2014 - 03:00 PM

yep.. wow indeed.

p.s. I typo'd. content != Content. Hopefully you caught that from your pro debugging skillz.


#1472218 parsing data from API with PHP

Posted by .josh on 11 March 2014 - 02:17 PM

Also, I understand it's off-putting to hear stuff like "this is php 101 basic shit" but it's also off-putting on the helper's end when someone is struggling with how to do something because they won't take the time to first learn the "php 101 basic shit".

If you really want to learn how to code, take a step back and learn the basic syntax rules, how to echo things out, array structures, methods for debugging when things don't work as expected, etc.. because all of these issues you have posted have basically amounted to you not understanding php 101.

And that's the point.. you aren't posting to learn php 101. You're asking for help on how to solve an issue despite you not learning the basics. We aren't really here to write code for people. Nor are we here to even handhold people through coding issues. This is a learning site. We expect people to learn things and if they get stuck, push them in the right direction.

So, when you got stuck and post an issue like this and basically say "it doesn't work" and have taken no steps to figure out what the problem is, that's when we tell you to step back and learn how to figure out what/where the problem is (debugging). Not because we're being elitist pretentious douchebags pointing at the noobie, but because teaching you how to solve your own problem is more valuable than solving your problem for you.

I'm sorry if that's not what you wanted to hear, but as said, this is a learning site, not a "help you bluff your way through a problem" or "do your work for you" site. If you aren't really interested in learning to code, then I suggest you hire a freelancer to do it for you, or hit up one of the rep-whore sites like Stack Overflow where people will be more than happy to show you the answer no-questions-asked for an upvote.


#1472164 help with date input

Posted by .josh on 11 March 2014 - 10:30 AM

I'd also point out that m-d-y is a terrible way to store dates. That's a "carry-over" from the "business" world that has caused no end to havoc and headache in the computer world.
  • trq likes this


#1471945 How to Print an Object

Posted by .josh on 09 March 2014 - 02:56 PM

You might wanna be more specific about what you're trying to actually do. Generally you shouldn't really use document.write for anything. If you are just playing around with stuff, you should use console.log() instead. Chrome has a built-in set of developer tools. Go to the menu and Tools > Developer Tools, (shortcut Ctrl+Shift+I). You can go to the "Console" tab to type in javascript code or see the results of calls to console.log().

If you are attempting to print (output) the code somewhere else, like visibly on your page, then you should be using methods to change an html element's value or text, or create one, etc.. There are numerous ways to do this, so more specific advice can come with more specific description of what you are actually trying to do.

But as for a "dump" of what a javascript object contains, you can reference individual properties with dot notation or index notation
 
var object1 = {value: 10};
console.log(object1.value); // dot notation
console.log(object1['value']); // index notation
You can also loop through the properties with the in loop:
 
var object1 = {value: 10, foo:'bar'};
for (x in object1) {
  // x will have the name of the property, so we can get the value of each property 
  // by using index notation
  console.log(object1[x]);
}
But as far as (recursively) outputting a "tree" of everything in the object (e.g. the equivalent of php's var_dump or print_r), javascript has no native method for this (for some odd reason). I have not tested to see if the code phpzer works as advertised, but you will basically need to something like that. If you google for "javascript equivalent of var_dump" you will find plenty of example functions people have made to replicate it.

Though honestly, there isn't much use case for something like this, other than for qa/debug purposes, and if that's what you are looking to do, then the javascript/dev console already offers a really nicely formatted way to visualize an object. For example, if you go to the Chrome dev console and type in
 
var object1 = {value: 10, foo:'bar'};
And then type on "object1"

It will output the following:
 
Object {value: 10, foo: "bar"}
If the object is more complex, it will output it in a way that has little arrows you can click on to expand it to a tree view. For example, you can type "document" into the console and get an expandable tree-view of what the rendered document looks like. It's basically like right-click > viewsource but with the fully rendered content (fyi if you want to utilize that, go to the "Elements" tab of the dev console instead, since that's what it's all about). Or, type in "window" to see the window object. From there you can drill down and find any variable set (since window is the highest scope for js)


#1471834 trying to understand PDO..

Posted by .josh on 08 March 2014 - 01:28 AM

umm.. no? using a while statement like that will cause the query to be executed every time. Come on people.. understanding how loops work is php 101...


#1471697 Binding click event to dynamic element

Posted by .josh on 06 March 2014 - 06:51 PM

You need to change your binding to be a delegated event. Basically the idea is to attach the event handler to an element that will always exist, e.g. the body:

$('body').on("dblclick",".newimageContainer label",function(e){
   // Get the src of the img below the label that was clicked
   imgSrc = $(this).children("img").attr('src')
   // Set the src of the prior selected page image to the new src
   $('.changing').attr("src", imgSrc);
   // close modal
   modal.close();
});



#1471282 mail code not working

Posted by .josh on 02 March 2014 - 07:35 PM

We aren't here to fix some random 3rd party script you found and don't know anything about. We're here to help people learn and fix code that they try to make.  You've got 2 choices, as far as this forum is concerned: 1) make an effort to understand and debug the code, and feel free to ask any specific questions about something you get stuck on, or 2) hire a freelancer to fix it for you. 




#1471277 National Read Across America Day - March 2nd, 2014

Posted by .josh on 02 March 2014 - 06:07 PM

Otherwise known as  Dr Seuss Day. 
So in honor of this "holiday" and of Dr. Seuss:
 

 
You did not like green eggs and ham,
Sam, you did not give a damn

But then a bloke just wouldn't scram,
and now you like them plenty, Sam!

Now it's time to read a book -
don't you give that dirty look. 

You'll like reading Mr. Sam,
You will like it more than ham.

One book, two book, red book, blue book:
just pick and sit down in a nook.

You should read one in a house,
about a cookie and a mouse.

You will like it near and far,
even Where the Wild Things Are.

If evening is more opportune,
read in bed with Goodnight Moon.

Oh, the Places You Will Go,
imagine things that books can show.

If you don't believe it's so,
Ask the Doctor, Who should know.

"Doctor Who? Doctor Who?"
Just ask Horton, he hears too.

So read a book for that old cat; 
to Doctor Suess: I tip my hat.



#1470924 Hiring programmers, are there copyright laws?

Posted by .josh on 27 February 2014 - 11:49 AM

It's gonna be a "risk" no matter what. Even if someone signs a non-compete, who's to say they won't pass your code off to someone else for a buck, and that 3rd party signed nothing. And even if you cover restriction of that sort of thing, you'd have to prove it. The bottom line is it's really hard to prove someone outright stole your stuff, and it's really hard to enforce or even define "rights" for this sort of stuff. And that's just dealing with the law within your own country's jurisdiction. For instance, lets say you're in the US. Doesn't matter if you have a bullet proof copyright on something.. someone from some other country can swipe it and host it on some host outside of the US.. there's little to nothing most people can do about that sort of thing.

Even people who have a LOT of money and legal resources to pursue it have a hard time doing something about it. Just take a look at all the big name software and media companies constantly throwing millions and billions of dollars at protecting against piracy and look at how effective they really are at it.

Bottom line is "closed source" stuff is out-dated and not a viable method these days. This is why a lot of software these days gravitate towards some sort of open-source license, and focus on providing services/support, rather than just trying to sell a product.


#1470849 Verify if a string contains x number of characters

Posted by .josh on 26 February 2014 - 08:12 PM

use strlen for your condition and a dot . to concatenate strings.




Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com