Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Italian Stalin
Jul 4, 2003

You-a gonna get-a purged!

MrMoo posted:

Which bit is the problem? I hope you have saved the items checked out with some unique id somewhere. Then to check-in you pull that list of items, iterate over them generating the HTML as necessary for your check boxes, etc.

php:
<?
foreach ($items as &$item)
{
?>
  <input type="checkbox" name="<?=$item->name;?>">
<?
}
?>

That's exactly what I needed to know! Thanks!

I'm new to PHP and what it can do with HTML. I didn't know that it could be used in such a fashion or what the proper syntax was to implement it.

This is perfect. It's going to make generating other things for my program so much easier.

Adbot
ADBOT LOVES YOU

KuruMonkey
Jul 23, 2004

fletcher posted:

Ummm really? The DOMDocument solution is so much cleaner...

Does that really look like code this guy can modify/learn from to you?

Your version is much cleaner: as I said mine was ugly and brutish - but it worked.

Since I'm not familiar with DOMDocument, I stuck to what I could whip up an answer in 15 minutes with. The difference being I would have had to lookup DOMDocument, whereas I can just write out simple regex like that.

Having seen your version; I will make a note to GET familiar with DOMDocument...

How well does it deal with malformed (x)html? Or fragments? Whats its memory footprint like?

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

armed2010 posted:

That's exactly what I needed to know! Thanks!

I'm new to PHP and what it can do with HTML. I didn't know that it could be used in such a fashion or what the proper syntax was to implement it.

This is perfect. It's going to make generating other things for my program so much easier.

As a side item, you can do this as an alternate syntax to what MrMoo suggested

php:
<?php foreach ($items as &$item): ?>
  <input type="checkbox" name="<?= $item->name?>">
<?php endforeach; ?>

Sometimes that helps if you are doing loops within your html, the curly braces will make you want to pull your hair out otherwise. I usually put foreach and endforeach in caps so it sticks out better, but whatever moistens your panties.

This also works with if, for, and while. I have been coding php for like 10 years, and I actually only found that out last year. I R Awesome.

Bonus syntax options (just so you can see the flexibiility in what you have to work with)
php:
<?php 
foreach ($items as &$item)
{
  echo '<input type="checkbox" name="'.$item->name.'">';
}
?>

php:
<?php 
foreach ($items as &$item)
{
  echo "<input type=\"checkbox\" name=\"{$item->name}\">";
}
?>

Its up to you how to do it, but IMO what MrMoo has or what I first suggested is the easiest to read if you are mixing it in with a bunch of HTML.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

KuruMonkey posted:

How well does it deal with malformed (x)html? Or fragments? Whats its memory footprint like?

It does what it can with malformed html but it will fail if it's really malformed. It can do fragments as well, you don't need an entire page. No idea about the memory footprint, at that point you should probably be using a real API.

MrMoo
Sep 14, 2000

Begby left out one more option, using heredoc:

php:
<?
foreach ($items as &$item)
{
  echo<<<MOO
  <input type="checkbox" name="{$item->name}">
MOO;

}
?>

apekillape
Jan 23, 2009

by Peatpot
This will never end.

The scraping code I set up earlier seemed to work great, but I noticed it skipped a about a third total of the listings. I looked through the records and matched them against the pages, and apparently when the page just gets too darn long (example: http://www.songmeanings.net/artist/directory/m/) it stops and jumps to the next one or something.

Anyone have an idea why? I can't see any particular reason it would do that, and it's not giving me an error code or anything.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

apekillape posted:

This will never end.

The scraping code I set up earlier seemed to work great, but I noticed it skipped a about a third total of the listings. I looked through the records and matched them against the pages, and apparently when the page just gets too darn long (example: http://www.songmeanings.net/artist/directory/m/) it stops and jumps to the next one or something.

Anyone have an idea why? I can't see any particular reason it would do that, and it's not giving me an error code or anything.

Curl is timing out. Set the curl timeout to a higher value.

apekillape
Jan 23, 2009

by Peatpot

DarkLotus posted:

Curl is timing out. Set the curl timeout to a higher value.

It wasn't set at all before, I added the line and set it to 30, then 60. It still stops after 519 records.

I haven't gone to song source page and counted all of them directly, but as it has nothing from the Mu- section (that's how I originally noticed) I assume it's just getting stopped somewhere way before it's over for that section, and skipping ahead.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

apekillape posted:

It wasn't set at all before, I added the line and set it to 30, then 60. It still stops after 519 records.

I haven't gone to song source page and counted all of them directly, but as it has nothing from the Mu- section (that's how I originally noticed) I assume it's just getting stopped somewhere way before it's over for that section, and skipping ahead.

I won't pretend to be an expert. Look into CURLOPT_BUFFERSIZE and CURLOPT_CONNECTTIMEOUT.

ryo
Jan 15, 2003
I made a little room booking database to use in the school I work at. On the odd occasion a teacher will press submit twice when booking a room (I assume that's what's happening) and it'll enter the database twice.

I wrote a couple of lines to check for duplicate data but it doesn't seem to work. Here's the code to check for duplicates:

code:
$doublecheck = mysql_query("SELECT bookingid FROM bk_booking WHERE date='$_POST[bookdate]' AND period='$_POST[period]' AND room='$_POST[room]'");
	if (mysql_num_rows($doublecheck)>0)
	{
		echo "Room has already been booked.";
		echo "<Br><br><a href=\"".$_SERVER['HTTP_REFERER']."\">Back</a>";
		
	}
Here's the INSERT statement I use after the check. The data always goes in fine so I know that the variables have the right information in them and aren't empty.

code:
$booksql = "INSERT INTO bk_booking (date,period,teacherid,room,timestamp) VALUES ('$_POST[bookdate]','$_POST[period]','$_POST[teacher]','$_POST[room]','$timestamp')";
The problem is, it doesn't work! Here's some sample data where the booking has gone in twice:

code:
bookingid  teacherid  room  date        period  timestamp 
1669       86         lrc   1264507200  6       1264514388 
1670       86         lrc   1264507200  6       1264514388 

Any ideas?

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

ryo posted:

Any ideas?

In your if statement are you doing any kind of exit? Is the insert in an else clause as part of that if? I think what is happening is that the insert is happening no matter what since you aren't skipping it if the result is true.

On a side not, holy loving poo poo this code is really insecure. You need to use prepared statements or at the very least do some sort of cleaning/checking of the data you are including in your queries. Take a look at PDO.

Edit: Oh yeah, does your link ever show up? Have you tried running your select query in an sql editor to make sure it works properly with some test data (or echo your query, copy it, then paste it write into your sql query program).

Begby fucked around with this message at 17:22 on Jan 26, 2010

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

ryo posted:

Any ideas?

Since it's for a smaller app, just disable the submit button after they click it so they can't click it twice. Also, use PDO as already has been suggsted. Again, since it's a small app, people probably won't be trying to do SQL injection, but that code you posted is frightening.

cka
May 3, 2004
Either disable the submit button on form submission (the simple way), or add in a unique indexed column to your database to prevent duplicate data from being posted (the other simple way.) On your form, have PHP generate a hidden input field with uniqid() as the value, and use that data as your unique key. Then, if someone double-submits, the data should only be added once (the query on the second insert would fail because of the unique key data submitted.) You can also probably work it into your app as a CSRF token if it's a publicly available script, which would also help secure it up a bit.

ryo
Jan 15, 2003
I made it a few years ago when I was an innocent butterfly with no considerations for SQL injections etc. Luckily the MySQL user for this doesn't have privaleges for any other DB.
Thanks for the suggestions!

SmirkingJack
Nov 27, 2002
I have a remote MySQL 5.1 server that I am trying to connect to via SSL. From the command line on the web server (FreeBSD 8, Apache 2.2, PHP 5.2.x), I can use the mysql client and connect just fine by specifying the location of ca-cert.pem, but when I try to connect using mysqli the page just hangs.

'Show processlist' on the remote databases's side shows

pre:
+----+----------------------+--------------------+------+---------+------+-------+------------------+
| Id | User                 | Host               | db   | Command | Time | State | Info             |
+----+----------------------+--------------------+------+---------+------+-------+------------------+
|  2 | unauthenticated user | <web ip>:58711     | NULL | Connect | NULL | login | NULL             |
+----+----------------------+--------------------+------+---------+------+-------+------------------+

Without SSL I can connect via PHP without a problem. This is what I am using:

php:
<?php
    $conn mysqli_init();
    $conn->ssl_set(NULLNULL,"/var/www/certs/ca-cert.pem"NULLNULL); 
    $conn->real_connect($ip$user$pwd$db3306NULLMYSQLI_CLIENT_SSL);
?>

Any ideas, or clues of where to look? I can't find any logs that indicate a problem.

SmirkingJack fucked around with this message at 16:01 on Jan 27, 2010

Yossarko
Jan 22, 2004

How do I chmod folders that have been uploaded to the server via FTP ?

I work in Windows and have a framework with lots of sub folders. When I upload a website to the internet, I have a "setup" script that I first run that sets lots of things up, and sets a bunch of folders that need to be written to (via administration, or log files) to 755 or I even tried 777 but it fails. I can make a directory and write files in a folder, but I can't CHMOD an existing folder (I'm guesssing it's owner is my FTP login).

How do I get around this ? I used to connect via FTP and ftp_chmod the folders but I'm trying to do this without FTP.

I can't be the only one who transfers his website via FTP and then wants to be able to CHMOD ?

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Yossarko posted:

How do I chmod folders that have been uploaded to the server via FTP ?

I work in Windows and have a framework with lots of sub folders. When I upload a website to the internet, I have a "setup" script that I first run that sets lots of things up, and sets a bunch of folders that need to be written to (via administration, or log files) to 755 or I even tried 777 but it fails. I can make a directory and write files in a folder, but I can't CHMOD an existing folder (I'm guesssing it's owner is my FTP login).

How do I get around this ? I used to connect via FTP and ftp_chmod the folders but I'm trying to do this without FTP.

I can't be the only one who transfers his website via FTP and then wants to be able to CHMOD ?

One option is to use PHP's FTP extension. Another is to make one writable folder that holds all the others, since the new folders you create there should inherit permissions by default.

Hanpan
Dec 5, 2004

I'm looking at upgrading an online store I run, and I was wondering what PHP based stores people would recommend? (Not sure if this thread is the right place for this, I hope so.)

I'm kind of torn between using an out of the box solution or biting the bullet and programming my own as obviously most online solutions are bloated to hell. Whenever I decide to tackle it myself, I think of all the different aspects of an online store and get scared off by the scale.

I'm not sure I want something as large scale as Magento. I currently use Trading Eye which is fine, but the urls are a bit nasty and the search functionality is a bit poo poo. I'd like something that is well programmed, simple to theme and of course secure. I also need to consider google sitemaps and such too.

SiCk
Jul 4, 2003

My name's SiCk, and I'm the Biggest Idiot Ever!

Hanpan posted:

I'm looking at upgrading an online store I run, and I was wondering what PHP based stores people would recommend? (Not sure if this thread is the right place for this, I hope so.)

I'm kind of torn between using an out of the box solution or biting the bullet and programming my own as obviously most online solutions are bloated to hell. Whenever I decide to tackle it myself, I think of all the different aspects of an online store and get scared off by the scale.

I'm not sure I want something as large scale as Magento. I currently use Trading Eye which is fine, but the urls are a bit nasty and the search functionality is a bit poo poo. I'd like something that is well programmed, simple to theme and of course secure. I also need to consider google sitemaps and such too.

Personally, Because it's what i know - I'd use Drupal with the UberCart module.. there's alot of support for it, but it can be a bit tricky getting used to hacking it to do what you want, if it's a little more specific. Most of the time there's a module for what you need, and someone else has usually done it before..

Finite
Jan 9, 2003

What do you mean mullets aren't fashionable?!?
I'm in the process of finishing up a website for an estate agent, and a small issue has cropped up during testing.

My client has the ability to upload floorplans to their website, which get resized automatically by the code I've written. However, a lot of these files come with a large amount of whitespace around the edge.

I'm using GD2 to do the resizing, and I can't find any obvious way to detect large areas of whitespace and crop it outside of imagecolorat(), a loop, and probably too much processing time.

Is this going to be a plausible solution? Is there a better way of doing it? Should I just advise they crop off large areas of whitespace in Photoshop before uploading (they'd be comfortable doing this)?

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

Finite posted:

Is this going to be a plausible solution? Is there a better way of doing it? Should I just advise they crop off large areas of whitespace in Photoshop before uploading (they'd be comfortable doing this)?

Uh yeah.

Hav
Dec 11, 2009

Fun Shoe

apekillape posted:

It wasn't set at all before, I added the line and set it to 30, then 60. It still stops after 519 records.

How many characters?

Hav
Dec 11, 2009

Fun Shoe

ryo posted:

code:
$doublecheck = mysql_query("SELECT bookingid FROM bk_booking WHERE date='$_POST[bookdate]' AND period='$_POST[period]' AND room='$_POST[room]'");

Apart from a redundant 'jebus, escape those POST values', I think you're probably testing for the string literal rather than the variable. eg '$_POST[bookdate]' rather than '1264507200'. You should also string the elements ($_POST['bookdate']) and avoid string interpolation because it makes the baby jesus cry.

Mysql_real_escape_string may just save your life.

Sebbe
Feb 29, 2004

Finite posted:

I'm in the process of finishing up a website for an estate agent, and a small issue has cropped up during testing.

My client has the ability to upload floorplans to their website, which get resized automatically by the code I've written. However, a lot of these files come with a large amount of whitespace around the edge.

I'm using GD2 to do the resizing, and I can't find any obvious way to detect large areas of whitespace and crop it outside of imagecolorat(), a loop, and probably too much processing time.

Is this going to be a plausible solution? Is there a better way of doing it? Should I just advise they crop off large areas of whitespace in Photoshop before uploading (they'd be comfortable doing this)?

This isn't GD2, but if you have access to ImageMagick, perhaps this script could be useful: autotrim

I have no idea how much processing time it requires, however.

apekillape
Jan 23, 2009

by Peatpot

Hav posted:

How many characters?

I'm sorry, what do you mean?

electricHyena
Sep 12, 2005

oh no not again
This might be the easiest question in here, as I know nothing about PHP. I just installed ZenPhoto on my site and I'm having some issues with the code.

My problem right now is that the page with all the images on it displays the actual text "view slideshow" as the link to the slideshow page. I would really prefer it to be a button instead, but have no idea how to make it insert an image in that spot.

I'm pretty sure this is the line that does it:
code:
<?php if (function_exists('printSlideShowLink')) printSlideShowLink(gettext('View Slideshow')); ?>
This seems like it would be really simple but I have no idea where to begin.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

electricHyena posted:

This might be the easiest question in here, as I know nothing about PHP. I just installed ZenPhoto on my site and I'm having some issues with the code.

My problem right now is that the page with all the images on it displays the actual text "view slideshow" as the link to the slideshow page. I would really prefer it to be a button instead, but have no idea how to make it insert an image in that spot.

I'm pretty sure this is the line that does it:
code:
<?php if (function_exists('printSlideShowLink')) printSlideShowLink(gettext('View Slideshow')); ?>
This seems like it would be really simple but I have no idea where to begin.

There will be a function called "printSlideShowLink()" somewhere in ZenPhoto. It looks like it takes a string argument, which is being obtained form some sort of localization function 'gettext()'

I'm guessing this function spits out a string like:

code:
'<a href="/' + someDynamicThing + '">' + the StringArgument + '</a>'
You will want to change it to spit out somethign like:

code:
'<a href="/' + someDynamicThing + '"><img src="/myCoolViewGalleryButton.gif" /></a>'
Search for the string "function printSlideShowLink(" in the source code of ZenPhoto to find it's definition.

KuruMonkey
Jul 23, 2004

Lumpy posted:

being obtained form some sort of localization function 'gettext()'

Just a little aside:

http://php.net/manual/en/book.gettext.php

Its PHP's built in localisation.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

KuruMonkey posted:

Just a little aside:

http://php.net/manual/en/book.gettext.php

Its PHP's built in localisation.

Ahh, cool. I use my framework's localization stuff, had no clue PHP even had that built in. One of these days I should actually just spend some time reading the manual. I picked up PHP as a "solve this specific problem" tool, so I know the parts of it I've used well, but never really looked around at the rest of it much. Then again, I don't do all that much PHP any more. :effort:

Hav
Dec 11, 2009

Fun Shoe

apekillape posted:

I'm sorry, what do you mean?

How many characters is the 519 records that you're returned before the thing stops? 519 seems a little arbitrary.

electricHyena
Sep 12, 2005

oh no not again
Thanks Lumpy, it worked great!

Finite
Jan 9, 2003

What do you mean mullets aren't fashionable?!?

Sebbe posted:

This isn't GD2, but if you have access to ImageMagick, perhaps this script could be useful: autotrim

I have no idea how much processing time it requires, however.

This was a bit too vicious for what I had in mind, so after some tests I wrote my own to see if I could make it better. Ended up as far too intensive for what I had in mind, so pre-cropping the images turns out to be the more sensible solution aside from writing a little client-side uploader to help them out.

Too much work for a small problem, so I've abandoned the idea. Thanks for the link though.

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
Anyone have anything interesting to say about Facebook's HipHop PHP compiler?

meh. Pretty significant accomplishment to get something like this into large-scale production, but it's not really a bold new idea.

spiritual bypass
Feb 19, 2008

Grimey Drawer

supster posted:

Anyone have anything interesting to say about Facebook's HipHop PHP compiler?

meh. Pretty significant accomplishment to get something like this into large-scale production, but it's not really a bold new idea.

Every big PHP application I've ever dealt with spends the great majority of its actual running time waiting for databases rather than actually executing PHP. I can't imagine using it unless I had an app running on a thousand servers.

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
Yes, but at the scale HipHop is intended to be used at you've already moved so much of your data to memory (via memcached) that PHP execution starts becoming the bottleneck - which is where stuff like HipHop comes in.

I certainly wasn't implying anyone in this thread should consider using it - there's only a small handful of PHP sites out there that are at the level where something like this would have any significant impact.

supster fucked around with this message at 00:22 on Feb 5, 2010

a foolish pianist
May 6, 2007

(bi)cyclic mutation

I've got some php code that produces a table, and it leaves a large quantity of whitespace at the top of the page, such that I have to scroll down to see the table.

The code is as follows:
code:
<body>
<?php
	!!!DATABASE_CALLS_EDITED_OUT_HERE!!!

	print('<table border="1">');
	print("\n");
	print("<td>ID Number</td>\n<td>Sign Name</td><td>Unicode</td><td>Cuneiform Sign</td>");
	$valquery = "SELECT name, code FROM $cuncodes";
	$result = mysql_query($valquery);
	$count = 0;
	$key1 = "name";
	$key2 = "code";


	while ($row = mysql_fetch_array($result)){
		print("<tr>\n");
		print("<td> $count </td>\n");
		print("<td>$row[$key1]</td>\n");
		print("<td>$row[$key2]</td>\n");
		print('<td><font size="28">&#x');
		print($row[$key2]);
		print(";</font></td>\n");
		print("</tr><br>\n");
		$count = $count + 1;
	}
	?>
</body>
and it produces what you see here: http://www.dataintensive.org/sumtest/sumtest.php

Anybody know what's going wrong?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

a foolish pianist posted:

I've got some php code that produces a table, and it leaves a large quantity of whitespace at the top of the page, such that I have to scroll down to see the table.

Anybody know what's going wrong?

Looks like your <table> isn't structured quite right.

Have a look at http://www.w3schools.com/tags/tag_table.asp

Because your table is not structure properly, that <br> gets printed out BEFORE the table, causing that whitespace. Install firebug and you can see how Firefox interprets your malformed HTML. If you are just trying to get each row to be on a new line with that <br>, don't bother, each row will automatically be on new line.

fletcher fucked around with this message at 04:02 on Feb 5, 2010

a foolish pianist
May 6, 2007

(bi)cyclic mutation

Thanks. I'm feeling really stupid right now.

a foolish pianist fucked around with this message at 04:07 on Feb 5, 2010

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

a foolish pianist posted:

I've got some php code that produces a table, and it leaves a large quantity of whitespace at the top of the page, such that I have to scroll down to see the table.

The code is as follows:
code:
...
</tr><br>
...
and it produces what you see here: http://www.dataintensive.org/sumtest/sumtest.php

Anybody know what's going wrong?

That's a plain old HTML question.

ed
darn,b

Adbot
ADBOT LOVES YOU

spiritual bypass
Feb 19, 2008

Grimey Drawer
I found something that really confuses me about an application. There's a function that serializes an array and then posts that string to another file using cURL. That file just unserializes and the post and passes the data into a function. It looks to me like it would make far more sense just to pass the stuff straight into the function from the initial function.

Is there any reason to do something like that?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply