• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

PHP & SQL help

Another Joomla hater here. I used to do a bit of freelance web-design work and on occasion set up a Joomla based site for a client. It's awful.

I use Joomla and quite like it. Much more customizable more quickly than Wordpress.

I think it's problem is that it's a little too complex for non-programmers and a little too confused for programmers who can see the inefficiencies they'd write better themselves.
 
I think my problem with Joomla is that it is quite often implemented by idiots, so the resulting sites are unmanageable. But yes, to a non-programmer (which is to say that I've done degree-level courses successfully in programming, but do not consider myself a programmer) the code is bafflingly opaque in places.

I'm using PHP solely because it's (at least one of) the most commonly used for the task of building websites that use databases, so there are tons of sites that give help and guidance, and indeed tons of tutorials, both online and in book form. I don't have an aversion to learning Python, but I have no reason to believe that it would make the job any easier. Also, CE has the situation just about nailed, except in that the person for whom I'm making the site is more or less housebound, so while enthusiastic about pubs, does not get to visit them.

The only problem I'm left with for now is that it doesn't seem to like multiline text from a textarea. I suspect that this is an encoding issue, though.
 
You should avoid using mysql_query since it makes it very easy to unintentionally add security risks to your web site. If you'd like to learn more, do a search for "SQL Injection."

Instead, I'd recommend using the "PHP Data Objects":

http://www.php.net/manual/en/book.pdo.php

Not only does using PDO help produce more secure code, but, as you learn how to use it you'll find that it's actually easier to create and maintain code using it.

-- Roger
 
Absolutely, but again, this is a relatively small noncommercial site that will contain no personal details (aside from a PHPBB forum with probably few users) or card details or the like. It just won't be interesting to actual dedicated crackers, which means I'm only looking at the possibility of script kiddies breaking the functionality. PDO is something I might be interested in looking at later for improving my employment situation, but it really isn't necessary for this project, and would just delay something on which I'm already further behind than I would like. As an aside I note that PHPBB is still using mysql_query; they appear to have been considering PDO back in 2010 but still haven't made the change, although I obviously realize that in that case it would be a major task.

I solved my multiline text problem, by the way, and learned of the existence of nl2br in the process.
 
...PDO is something I might be interested in looking at later for improving my employment...

Welcome to the wonderful world of PHP - a billion ways to do everything and more opinions than you'd ever believe possible. For example...

PDO is all well and good, and I even use it myself, but in this situation the obvious thing to do is use mysqli instead. It's almost a direct replacement for the mysql functions you're using (e.g. mysql_real_escape_string becomes mysqli_real_escape_string). It has several advantages over what you're using, including the fact that it won't suddenly start throwing out shed-loads of scary looking warnings that ruin your web site when some idiot (e.g. your hosting company) secretly upgrades your version of PHP on you.
 
My host (1and1) is actually quite good for that sort of thing, albeit that they have irritated me in other ways over the last couple of years. They give me plenty of warning when upgrading PHP or MySQL, and allow me to use the old version for a while if I need some time to migrate.

I may well look at SQLi tomorrow and use it if the transition is simple enough.
 
If your buddies ask you to throw together some site for pub enthusiasts and you think spending time with them in one of the venues that database thing shall contain is much more fun than reading "well-meaning" pedantic tips of people programming for different goals, there's nothing better than PHP. That's what it was invented for, after all. ;):)
No. Using PHP is always a bad idea. If it's the only language you know, you should learn something else.
 
Quick debug tips:
Use print_r() to get better insight into what's in a variable.

http://stackoverflow.com/questions/...ference-between-echo-print-and-print-r-in-php

Print strings with surrounds, like: print_r(">>" . $yourstring . "<<");
This way you can tell when the string is empty because you see >><< which is a whole lot better than empty space!

Use "\n" to get a newline in your print statements, in case you wondered.

Okay, my ancient PHP mojo has now run dry.
;)
 
Can you say briefly what's wrong with it, or point me to a resource where I can find this out?
This may be a bit out of place given that you're just trying to build something simple, but since I started down this road already...

The problem with PHP is that everything is wrong with it. It's a bad idea on every level, and badly implemented on every level.

Here's a short overview of some of the failings of PHP: http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

What I'd recommend, personally, is using Python, CherryPy, Mustache templates, and MariaDB or MongoDB (or TokuMX, which is MongoDB + transactions) with the MongoEngine library. Ruby, Sinatra, and Mongoid is another good option.

But the one important thing is not to use PHP.
 
Last edited:
This may be a bit out of place given that you're just trying to build something simple, but since I started down this road already...

<snip>

But the one important thing is not to use PHP.

Thus shall it ever be. VBA is an abomination and an insult to all right-thinking people too, but it still runs half the world's macros.

There's something to be said for things that are ridiculously easy to learn.
 
My first guess would be to check your data types. A varchar works but others don't? Are you trying to write strings to numeric SQL fields perhaps?

A ha ha ha ha. Yes, it was not updating that field because I didn't tell it to, and I didn't notice this because I am a dick. Thanks for that.

Issue already resolved. We were just about to allow the thread to drift into another geek flamewar, so stick around for a while ;)
 
The connection must be opened correctly, I think, because the varchar fields do get updated. The update line is this:

Code:
mysql_query("UPDATE pubs_pubs SET pubname='$pubname', xcoord='$xcoord', ycoord='$ycoord', locdesc='$locdesc', zoneref='$zoneref', flagcol='$flagcol' WHERE id='$id'")
 or die(mysql_error()); 
 
 echo 'done!'


In this example, if I edit all fields, pubname and locdesc, which are varchars, will update fine, while notes, which is text, will remain unchanged.

I suppose I could in theory just change notes to be a very long varchar, since I'm on MySQL 5.1, but as this is largely a learning exercise, I'd like to know why it isn't working now.

Have you fixed this yet? If not I'll sort this for you. Let me know.
 
Yes, Octavo pointed out back in post #10 that it wasn't updating the notes field because I hadn't told it to update the notes field.

Still blundering along with the rest of it.
 
Yes, Octavo pointed out back in post #10 that it wasn't updating the notes field because I hadn't told it to update the notes field.

Still blundering along with the rest of it.

If you need any help give me a shout.

The more basic the problem the harder it is to spot sometimes.
 

Back
Top Bottom