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
DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
I'm trying to graph Hard Drive utilization by partitions for a project I am working on. My goal is to allow user input of partitions of a server. From that point forward they can track changes in partition free space by entering the amount of free space on each partition at any given point of time. It can the be plotted out on a line graph.
Here is some sample data:
code:
[0] => Array
        (
            [partition_id] => 1
            [partition_name] => Drive C:
            [partition_size] => 30
            [partition_size_type] => GB
            [partition_free] => 22
            [partition_free_type] => GB
            [partition_create_date] => 2009-05-14
            [entries] => Array
                (
                    [0] => Array
                        (
                            [partition_free] => 21
                            [partition_free_type] => GB
                            [partition_entry_date] => 2009-06-14
                        )

                    [1] => Array
                        (
                            [partition_free] => 19
                            [partition_free_type] => GB
                            [partition_entry_date] => 2009-07-14
                        )

                )

        )
I would like to dynamically create a line graph that supports multiple partitions. Using the initial partition size and free space along with the date the partition was added give us a baseline for each partition. Each entry will then have a new date and freespace for the given partition. This should allow graphing by Date on the X axis and Size on the Y axis. The scale would be simple Y minimum would be ZERO, Y maximum would be the largest available partition size out of all of the partitions. In this example we are looking at one partition so the Y max would be 30 GB. The X axis would be by date, so the farthest to the left would be partition_create_date and the farthest on the right would be the last partition_entry_date.

All I want is a good recommendation on a PHP graphing Class or package and maybe a push in the right direction.

Adbot
ADBOT LOVES YOU

DarkLotus
Sep 30, 2001

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

chips posted:

Have a look at jpgraph if you just want to generate images, but have you considered using either flash or javascript to do the plotting? Obviously it depends on what the client is and what it might support/be reasonable.

I was looking at JPGraph and it looks like it might work. I also looked at PHP/SWF Charts which definitely looks much nicer but also more involved. I like the idea of displaying an image or a swf, and not having the browser draw the plots with javascript.

This will all be web based obviously so IE / FF / Safari support is required.

DarkLotus
Sep 30, 2001

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

Munkeymon posted:

There's also the Google Chart API: http://code.google.com/apis/chart/

I'm sure you could find a ton of PHP wrappers for it, too.

Very cool. I forgot Google had this available. I will have to look into that as well. I think I will need something different that can be included in a commercial application since this web app I am developing will probably be sold or subscription based.

DarkLotus
Sep 30, 2001

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

standard posted:

Does anyone know of a nice image serving type script?
The type that I can use in img tags, instead of serving images directly. eg.

<img src="image.php?src=whatever.jpg" />

You get the idea...

You could make one fairly easily if you are good with PHP. The problem isn't just serving images, you have to somehow tell the script where the image is stored on the server. What exactly are you trying to accomplish by not hard coding image paths?

DarkLotus
Sep 30, 2001

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

standard posted:

I'm competent but just can't be bothered to think through the security implications to be be honest.
The main reason is that I'm going to serve up different images depending on some user settings.

Good coders code, great reuse...and all that.

Most of the code I have was built for a purpose and not just for general image serving so it probably won't help you much.

As for security, if you are trying to secure the images from prying eyes and only want to serve up images that the user is authorized to view that gets tricky but isn't too difficult.

If a directory called images and just want to serve up images/hello.jpg but would prefer <img src="image.php?i=1" /> as opposed to <img src="images/hello.jpg" /> then that is easy.

DarkLotus
Sep 30, 2001

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

standard posted:

I meant 'don't give users access to my whole filesystem' type security, rather than authorization type security. :)
Very simple and secure if you don't trust the user to put valid content in $_GET['img']... Your path is preset and if the img src contains the proper value you can display an image.

Example: <img src="image.php?img=123456" />
php:
<?php
$imagePath =  '/home/user/public_html/images/';
if ($_GET['img'] == '123456') {
    $imagefile "sample";  // this value can be pulled from a database or whatever!
} else {
    $imagefile "blank";
}
$newimage $imagePath.$imagefile.'.png';
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0"false);
header('Content-Type: image/png');
//  header('Content-Disposition: attachment; filename="' . $_GET['img'] . '.png"');  // FORCE DOWNLOAD
header('Content-Disposition: filename="' $_GET['img'] . '.png"');
  
$img LoadPNG($newimage);
  
imagepng($img);
imagedestroy($img);
?>

This will display sample.png but will show in "View Source" as 123456.png

Lithium Hosting - Reliable, Affordable, Feature Packed Web Hosting
The only hosting company to offer 30-day Free Trial on top of a 90-day money back guarantee!

Give Lithium DNS a try, it's free and easy to use!

DarkLotus fucked around with this message at 20:37 on Jul 20, 2009

DarkLotus
Sep 30, 2001

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

supster posted:

Why are you creating an image object? All you need to do is something like this:
php:
<?
$fh = fopen($newimage, 'r');
while(!feof($fh))
    echo fread($fh, 8192);
?>
They both work... Is there a good reason not to do it that way? I prefer file_get_contents over fread anyways. The problem with an open source language with many ways of doing anything is that there is no true wrong way or right way unless you are creating a huge security hole.

supster posted:

You are also allowing the user access to directly modify the response header.
Not if you clean the $_GET value. Protect it like you would a SQL Query.

DarkLotus fucked around with this message at 23:38 on Jul 20, 2009

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
Lets assume that we are in control of the size of files we are serving up with an image script. If that is true, is it still an issue or has it turned into a best practice scenario now?

DarkLotus
Sep 30, 2001

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

waffle iron posted:

That goes double for serving images out of a database with PHP.

Yeah, storing images in a db is retarded.

DarkLotus
Sep 30, 2001

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

scrabbleship posted:

It might but it is probably a bit overkill for what my client wants. This would probably overwhelm him. He just wants something he can see the entries in the table with and modify/delete faulty ones with; nothing to fancy. Thanks for the suggestion nonetheless.
You could use this datagrid class and modify it to fit your needs.
http://stefangabos.blogspot.com/search/label/Data%20Grid%20PHP%20Class%20Description/

DarkLotus
Sep 30, 2001

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

crabrock posted:

So does nobody know why my sessions aren't keeping? is it something i should bring up to my host? I wanted to see if there was anything wrong with my code, but nobody has said anything either way. :(
If you want to look at a simple example that works, checkout the following class. It is simple, works and can easily be modified for whatever you are trying to accomplish. It gives you the option to save a cookie for staying logged in, or just logging in everytime. It seems to work pretty well for a project I am working on. If this doesn't work, then it might be something with your host.
http://phpuserclass.com

DarkLotus
Sep 30, 2001

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

Begby posted:

Is your host erasing the contents of /tmp on the server every couple of days? Or is there a cron job that goes in there and deletes everyting that is x days old?

The session ID cookie is used by PHP to find and restore the session server side. If you are saving a logged in value on the server, and its gone, then PHP will makre the user as logged out.

You might want to create your own session handler that saves the session data to a db if you can, that would fix this problem.

Zebra Framework has a good Sessions class.
http://stefangabos.blogspot.com/search/label/Sessions%20Management%20PHP%20Class%20Download

DarkLotus
Sep 30, 2001

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

fletcher posted:

After I read this post I sang "P-H-P" aloud to the tune of AC/DC's T.N.T. :rock:

AWESOME! Now its stuck in my head thanks!

DarkLotus
Sep 30, 2001

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

Aturaten posted:

I honestly forget if cpanel has the capability to edit the php.ini file, but you need to find it. After you do, look for:

code:
;extension=php_zip.dll
Remove that semi-colon, restart your server.

Oh, and first check to see if your server even contains php_zip.dll under the ext folder. If not, download it.

Don't do this!!!

Instead use Easy Apache in WHM to add the Zip Extension under Exhaustive Options. If you don't use Easy Apache currently, then do whatever. If you modify things manually and then want to use Easy Apache later, things may not work as intended. I find it is best to either manually build and configure Apache and PHP or use Easy Apache, not both!
http://twiki.cpanel.net/twiki/bin/view/EasyApache3/WebHome

DarkLotus
Sep 30, 2001

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

apekillape posted:

Holy poo poo, I can't believe I missed that. I've been mucking around in Putty and google all day trying to manipulate PECL and a bunch of other nonense, when it's been right there in EasyApache all this time.

Rebuilding now, thanks so much!

My pleasure. I'm not sure what you use your server for, but I have 3 cPanel / WHM servers for Lithium Hosting and I don't mind sharing my knowledge and experience!

DarkLotus
Sep 30, 2001

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

apekillape posted:

Crap, something else I forgot about.

I was trying to remove some folders after I uninstalled another plugin, and apparently since the plugin created them and I removed it they now belong to "nobody" or "User/Group 99". I delete them in File Manager via cpanel and they just come back, and in the ftp I get a 550 Permission Denied error.

Is there an easy way to re-permission or chmod them?

login as root and type chown user.user /home/user/public_html/folder -R

DarkLotus
Sep 30, 2001

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

Aturaten posted:

Well aren't we Mr. "I own a loving web hosting company".

Kids today, and their easy techno babble. In my day, we had to write our own CGI poll scripts, and small chinese men ran our servers.

As a serious side note, I did not know this, and I loving love Lithiumhosting.

At first I wasn't too pleased with the direction your post was going until I saw that you love Lithium Hosting. Then I smiled :q:

DarkLotus
Sep 30, 2001

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

apekillape posted:

I got this:

chown: `user.user': invalid user

sorry, not literally user.user, but whatever the user name is that wordpress is installed for.

DarkLotus
Sep 30, 2001

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

fletcher posted:

Never even heard of this. I currently use Notepad++ as well (and sftp-drive) to write all my code. All I want is an editor that can do key based authentication to edit remotely hosted code, sftp-drive is the biggest piece of poo poo.

I personally use UltraEdit. It allows me to remotely edit code using SFTP and the syntax highlighting works well for my needs. I've never used Notepad++, NetBeans, or any Framework or IDE though.

DarkLotus
Sep 30, 2001

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

KracKiwi posted:

Could anyone point me towards the best method for posting a facebook status from a remote website using php?
I would start here:
http://developers.facebook.com/
You'll need to register your site with them before you can do anything.

DarkLotus
Sep 30, 2001

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

LastCaress posted:

Is there a way to upload a picture from a remote url to my server using curl? Basically I had a firefox extension that allowed me to right click on a picture and upload it to my server, but now they turned "allow_url_fopen" off and doesn't work.

(Just need to know if there's a way, not the actual way)

Thanks.

Here is a very basic example:
Please read the curl documentation
php:
<?
$url = "http://www.domain.com/image.jpg";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$fileContents = curl_exec($ch);
curl_close($ch);
$newImg = imagecreatefromstring($fileContents);
?>

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
For a good sessions management class, take a look at this:
Database Sessions Management Class

DarkLotus
Sep 30, 2001

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

Little Brittle posted:

I need to download a text file every 10 minutes from a remote server. What is the best way to grab the file, while ensuring that the file is not being currently written? Right now, I'm grabbing the file via PHP FTP commands and processing it.

you can use curl, it is probably the best option for using PHP to grab anything from a remote server. You could run something on the remote server to send you the file. This would allow you to lock it while sending.

DarkLotus
Sep 30, 2001

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

rotaryfun posted:

I'm currently trying to get my webserver setup to handle php. I'm having a bit of trouble getting everything setup correctly though.

It's a windows 2003 server. I installed php using the windows binary.

I've added php to the web service extension and pointed it to php.exe
I've also added .php to the websites application extensions list

However when I run the page, I get the error:
code:
CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers.
I've even changed the whole page to just run phpinfo() and I am still presented with that same issue.

I've searched php's site and did what they suggested and added the rights for IUSR_<computername> to the whole php directory. That gave me the same results. I was able to run phpinfo() from the command line and have it work.

Anything?

Do you need to use IIS or have you considered installing XAMPP?
If you're stuck with IIS, I'm pretty sure there is an installer for PHP that will integrate with IIS or at least give you detailed instructions if it can't/

DarkLotus
Sep 30, 2001

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

rotaryfun posted:

I am unfortunately stuck with IIS.

I downloaded the binary from http://windows.php.net/download/
is that what you were talking about?

Also, I just realize, I didn't actually run phpinfo() from the command line, but rather php -i

Did you run the installer? PHP 5.2.12 installer

Last time I tried on a windows box, it attempted to integrate with IIS. If it fails it will tell you what to do to make it work.

http://www.php.net/manual/en/install.windows.iis6.php should help too

DarkLotus
Sep 30, 2001

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

rotaryfun posted:

From the link that I posted, I downloaded and installed the 5.3.1 VC9 non thread safe installer. I'll give previous version installers a try too.

I did already see that page and followed it as well.

I did have a question regarding the application extensions, should I have point to the php.exe or php-cgi.exe? Same question for the web extension services.

With IIS you want the non thread safe installer.

Try following these instructions:
http://www.peterguy.com/php/install_IIS6.html

Seem to have good information.

DarkLotus
Sep 30, 2001

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

rotaryfun posted:

Followed this and was able to get the server up and running with 5.2.5

There were only three differences between his guide and what I did initially.

*He has you download the zip and not the windows installer.
*He puts the php folders path into the registry as well as the Env Var Path
*He points the application extension to the php5isapi.dll file rather than php.exe (which is what I thought had to happen but the windows installer doesn't even include the .dll)

In the end it's up and that makes me pretty happy. Thanks for the link to the guide.

You're welcome. Enjoy your IIS + PHP setup!

DarkLotus
Sep 30, 2001

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

apekillape posted:

You're both beautiful people and have completely saved my bacon.

Looping and getting it into the DB and all was never a problem, I just learned everything way out of order. I think this might fix a lot of my mental scraping issues though, shazam this thread is the best.

This will get A through Z
php:
<?php
foreach(range('a','z') as $i) {
    $url "http://www.songmeanings.net/artist/directory/$i/";
    $artistHTML artistcURL($url);
    $artists_to_insert artistList($artistHTML);
    
    $insert_sql join(", "$artists_to_insert);
    // Simple Database insert
    mysql_query("INSERT INTO table (name, url) VALUES $insert_sql");
}


function artistList($html) {
    $doc = new DOMDocument();
    $doc->loadHTML($html);
    $mainDiv $doc->getElementById("listing_artists");
    $anchors $mainDiv->getElementsByTagName("a");
    
    foreach ($anchors as $anchor) {
        $artist mysql_real_escape_string($anchor->textContent);
        $artistUrl mysql_real_escape_string("http://www.songmeanings.net".$anchor->getAttribute("href"));
        $artist_to_insert[] = "('$artist', '$artistUrl')";
    }
    return $artist_to_insert;
}

function artistcURL($url) {
    $curl curl_init();
    curl_setopt($curlCURLOPT_RETURNTRANSFER,1);
    curl_setopt($curlCURLOPT_URL$url);
    $result curl_exec($curl);
    curl_close($curl);
    return $result;
}
?>

DarkLotus
Sep 30, 2001

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

fletcher posted:

Why are you telling somebody new to PHP to use mysql_real_escape_string :ughh: prepared statements! PDO!

He already had the database side down.
Quote:
"Looping and getting it into the DB and all was never a problem"


You might as well ask why I would tell somebody to use mysql_real_escape_string or mysql_insert without first opening the database connection :q:

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.

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.

DarkLotus
Sep 30, 2001

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

Yeehaw McKickass posted:

Would someone be able to direct me to some simple contact form resources? Tutorials, or straight up code, what-have-you.

I basically just want something that confirms the mail was sent within the form. I've been looking around and have only been able to find really outdated stuff.

What do you mean "Confirms the mail was sent"? Just making sure the mail sending function completed without errors?

DarkLotus
Sep 30, 2001

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

Yeehaw McKickass posted:

I mean within the form box, without having to refresh the page.

This isn't difficult, you'll have an HTML form, then you'll use jQuery to validate the input and submit via AJAX to form.php. If successful, the jQuery can hide the form and display a success notification without reloading the page.

The example below does ZERO input validation. You will at bare minimum want to validate user input via jQuery and then again via PHP.

formtest.html
code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $('#formResults').hide();
    $('#testButton').click(function () {
      var formData = $('#testForm').serialize();
      $.ajax({
        type: "POST",
        url: "process-form.php",
        data: formData,
        success: function(html){
          $('#inputForm').hide();
          $('#formResults').html(html).show();
        }
      });
      return false;
    });
  });
</script>
</head>
</head>
<body>
<div id="inputForm">
  <form name="test" id="testForm">
  Field: <input type="test" name="field" /> <br />
  <input type="button" name="submit" id="testButton" value="Submit" />
  </form>
</div>
<div id="formResults"> </div>
</body>
</html>
process-form.php
php:
<?php
  if (!empty($_POST['field'])) {
    echo "Form Submitted!";
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
  }
  exit;
?>

If you want some help, hit me up on AIM darklotus781. I'll be hit or miss today but will be available later tonight.

DarkLotus fucked around with this message at 21:01 on Mar 19, 2010

DarkLotus
Sep 30, 2001

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

Thirteenth Step posted:

I have a combo box which populates from the DB, code is:

php:
<?php
$query="SELECT forename,surname,dept FROM staff";

$result mysql_query ($query);
echo "<select name=staff value=''>Staff Name</option>";

while($nt=mysql_fetch_array($result)){
echo "<option value=select_user>$nt[forename] $nt[surname]   - $nt[dept] Staff</option>";
}
echo "</select>";
?>

I've searched high and low but what I'm trying to do is create a form button which will DELETE the record the user has selected in the combo box, from the DB.

Is it a lot of code? / complicated?
It wouldn't be too bad. Here is an example:

new form:
php:
<?php
$query="SELECT id,forename,surname,dept FROM staff";

$result mysql_query ($query);
echo "<form type=\"post\" action=\"\">";  //This will post to itself
echo "<select name=\"staff\">Staff Name</option>";

while($nt=mysql_fetch_array($result)){
echo "<option value=\"{$nt['id']}\">{$nt['forename']} {$nt['surname']} - {$nt['dept']} Staff</option>";
}
echo "</select>";
echo "<input type=\"submit\" name=\"submit\" value=\"submit\" />";
echo "</form>";
?>

backend code:
php:
<?php
// put this code at the top of your PHP file so when the form posts, it will run before your select list is created.
if ($_POST['submit']) {
  $deleteID mysql_real_escape_string($_POST['id']);
  $deleteQuery "DELETE FROM staff WHERE id = '$deleteID' LIMIT 1";
  $deleteResult mysql_query($deleteQuery) or die(mysql_error());
}
?>

This is a basic example and assumes you have a field called id stored in the staff table as a unique identifier.

DarkLotus fucked around with this message at 19:09 on Mar 25, 2010

DarkLotus
Sep 30, 2001

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

revmoo posted:

What's the easiest way to match if statements containing a bunch of possibilities. For example, if $variable contains any one of 30 different possible strings return true otherwise return false?

put those strings in an array, then use
php:
<?
if (in_array($value, $array)) { 
//do stuff
}
?>
or you can use switch()
php:
<?
switch ($i) {
  case 0:
    echo "i equals 0";
    break;
  case 1:
    echo "i equals 1";
    break;
  case 2:
    echo "i equals 2";
    break;
}
?>
which is the same as:
php:
<?
if ($i == 0) {
  echo "i equals 0";
} elseif ($i == 1) {
  echo "i equals 1";
} elseif ($i == 2) {
  echo "i equals 2";
}
?>

DarkLotus fucked around with this message at 21:06 on Mar 25, 2010

DarkLotus
Sep 30, 2001

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

revmoo posted:

Just did 1100 lines of case statements to translate zip codes into geographical price zones. My hands are tired.

I probably could have done it a little bit smarter, but since the zip code zones were broke up into a ton of different regions there wasn't much that could have been shortened or automated.

Thanks again for the help guys.

I bet if you post your code, minus all 1100 lines of zip codes, someone could help you optimize it better.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
I am pretty sure it is acceptable to have a structure like this:
code:
<form>
<table>
</table>
</form>
http://www.html4.com/mime/markup/php/standards_en/html_forms_en/html_forms_6.php

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
I am experiencing a strange issue while developing an addon module for a product I use. The software developer has given me the usual "There isn't anything that would cause this" type of run-around.

php:
<?
$value = "test";

function test_function($someothershit) {
  global $value;
  var_dump($value);
}
?>
This outputs null for $value. I can't figure out why global isn't working. I've tested this in a folder outside the root folder of the software package I am using and it works brilliantly. Ideas?

DarkLotus
Sep 30, 2001

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

gwar3k1 posted:

Change the name of the variable. There may be another global $value in the product?

Very good suggestion. I forgot to mention I tried that and the result is the same.

Adbot
ADBOT LOVES YOU

DarkLotus
Sep 30, 2001

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

gwar3k1 posted:

Perhaps try $value .= "test"; which would further suggest existance of a constant $value somewhere.

Have you tried $_GLOBALS['value'] to check its not an issue with global? I can't see how it would be as it isn't version specific.

And with the renaming, did you use something stupidly unique like XD4AO or a common word? I can't tell if your posted code is examplary for help or directly from your script.

Can you set value from within the function and have it output?

I set a value on one page:
php:
<?
$DEBUG = true;
?>
And then include apiutil.php There is a function:
php:
<?
$debug = defined('C_DEBUG') ? ((strcasecmp(C_DEBUG, 'true') == 0) ? true : false) : $DEBUG;
function debugfunction($serviceObj)
{
  global $debug;
  if($debug)
  {
    print "<b>Debug Mode is True:</b></br></br>";
    print "<b>XML Sent:</b><br><br>";
    print "<xmp>" . $serviceObj->request . "</xmp>";
    print "<br><b>XML Received:</b><br><br>";
    print "<xmp>" . $serviceObj->response . "</xmp>";
    print "<br>";
  }
  else
  {
    print "<b>Debug Mode is False:</b></br></br>";
  }
}
?>
All I get is the Debug Mode is False statement when I run the script.

$GLOBALS['debug'] is empty. I did try this before to see what it said.

I did not write this code, I am simply trying to build a module using an API which I have done without issue but anytime the code executes as part of a different application, all kinds of strangeness happens.

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