nonshatter 26 Posting Whiz

Diolch yn fawr ardav!
So, each iteration relates to a disk drive. The charts are used to show the amount of free/used disk space for each of the six drives.
E.g:

if ($i == 1)     // disk drive 1 of 6 
	{
		$arrData[0][1] = "Used";   //This is the label for Gb used
   		$arrData[1][1] = "Free";   //This is the label for Gb remaining
   		$arrData[0][2] = $used;    //This is the no of Gb used
   		$arrData[1][2] = $free;    //No of Gb free
	}

Your idea for using associative labels instead of numbers is good. I'll have a play around when i'm back in the office tomorrow and post my solution. Cheers

nonshatter 26 Posting Whiz

Okay, I've been racking my brain trying to figure this one out but the more I try, the more I get stuck.
I need to construct a multi-dimensional array as follows, so for each iteration there are 4 values added to the array. (there is a total of 6 iterations, but here I'm only showing 3):

while($i < 7)
{
        if ($i == 1) 
	{
		$arrData[0][1] = "Used";
   		$arrData[1][1] = "Free";
   		$arrData[0][2] = $used;
   		$arrData[1][2] = $free;
	} 
	elseif($i == 2)
	{
		$arrData[0][3] = "Used";
   		$arrData[1][3] = "Free";
   		$arrData[0][4] = $used;
   		$arrData[1][4] = $free;
	}
	elseif($i == 3)
	{
		$arrData[0][5] = "Used";
   		$arrData[1][5] = "Free";
   		$arrData[0][6] = $used;
   		$arrData[1][6] = $free;
	}
    $i++;
}

This is fairly simple... but it also looks pretty damn ugly.
What I want to do is for a function to handle this (rather than having thirty+ lines of code). So here's my rather rusty logic:

//perform the six iterations
for ($i=1; $i<7; $i++) 
{ 
    $free = 'some number';
    $used = 'another number';
    $array[][] = generateArray($free,$used,$i);     //call the function on each iteration
}

function generateArray($free,$used,$i)
{
    // My problem is working out how to dynamically generate the correct keys numbers here...
    $arrData[0][1] = "Used";
    $arrData[1][1] = "Free";
    $arrData[0][2] = $used;
    $arrData[1][2] = $free;
    return $arrData;
}

Can someone please lend me a hand. (the array is used to generate 6 different Pie charts)
Many thanks

nonshatter 26 Posting Whiz

Have a look at the BETWEEN function in MySQL.
You could try this, although I really don't know whether it will work in the format you're using. Worth a try though

("SELECT * FROM mytable WHERE date BETWEEN '12-10-2010' AND '12-10-2010'");
nonshatter 26 Posting Whiz

where's the code

nonshatter 26 Posting Whiz

The query will still work even if there isn't a space between the asterisk and the 'FROM'
The query looks fine. The issue is most likely with the variable not being set.
Try this and post the result:

<?php
    $show = $_GET['id'];

    if (isset($show))
    {
        $news_sql = mysql_query("SELECT *FROM latestnews WHERE id='$show'") or die("MySQL syntax error: ". mysql_error());
    }
    else { die ('$show isn't set! the $_get didn't work...'); }
?>

Note:- The $_GET must mean that the URL has a variable called 'id' (www.site.com/script.php?id=2)
And say I used $_GET then the url should be something like (www.site.com/script.php?foo=bar)

nonshatter 26 Posting Whiz

You can still use the $_GET method to grab variables from your URL using form method="post", but you'd have to append the Id variable to the form action like this:

<form action="<?php 'process.php?id=$id' ?>" method="post">

(that's if you're actually using a form, you haven't stated whether you are).

Can you be a bit more specific with what you're trying to do?

nonshatter 26 Posting Whiz

Never mind, I've created my own error handling function for mysql errors. Instead of suppressing the error messages (which isn't particularly useful in a lot of situations), I've used a file handle to write these errors to my own log file:

This means users don't get hold of info they shouldn't. And this way I'll be made aware of the errors instead of them being silenced by using '@'

E.g:

mysql_select_db("db") or (writeErrors(mysql_error(),$ip,$date,__FILE__,__LINE__));

function writeErrors($error,$ip,$date,$file,$line)
{
    //write to the logfile
}
nonshatter 26 Posting Whiz

Yes I have used the suppression operator but this isn't ideal. The user will still get an error message in some circumstances.

E.g, this code:

@ $dbconnect = mysql_connect("ipaddress", "username", "");
        mysql_select_db("db");

This still displays the error:

Access denied for user 'user'@'domain' (using password: NO)

I want the errors to be logged, and NOT displayed to stdout at all!

Surely there's a way to do this...?

nonshatter 26 Posting Whiz

Hi all,

I'm trying to figure out how to stop MySQL errors being displayed to the user.

I have turned off all the necessary options in php.ini such as

display_errors = Off
log_errors = On
error_log = /path/to/log/

I have even tried to override these settings using ini_set() in my script.
This prevents PHP syntax errors from being displayed, but Mysql errors are still being shown to the user!

How do I turn this off?

nonshatter 26 Posting Whiz

I *think* in this case they will be two copies of the same value. You could probably check for definite if you use the PHP debugger in Linux CLI.

nonshatter 26 Posting Whiz

Sorry I was incorrect. text-align won't work because it only applies to in-line content, not a block-level element like a table.

<html>
<head>
</head>
<body>
        <table style="margin:0 auto;">
        <tr>sdkjfs'asfjd'pjdfsa'kjfsdl;kajsf;lkjasd;lfkja</tr>
        <tr>
                <td style="margin:0 auto;">
                        <input type="button" class="btn" value="New" name="New" onClick="window.location.href='new2.php'" onMouseOver="hov(this,'btn btnhov')" onMouseOut="hov(this,'btn')" align="absmiddle">&nbsp;
                        <input type="submit" value="Delete" name="delete" class="btn" onMouseOver="hov(this,'btn btnhov')" onMouseOut="hov(this,'btn')" >
                </td>
        </tr>
        </table>
</body>
</html>
nonshatter 26 Posting Whiz

Using <center> is deprecated since HTML 4.0. You should use CSS to control the styles:

<style type="text/css">
    td.tdcenter
    {
         text-align:center;
         padding: 2px;
    }
</style>

<tr>
        <td class="td_center">
		<input type="button" class="btn" value="New" name="New" onClick="window.location.href='new2.php'" onMouseOver="hov(this,'btn btnhov')" onMouseOut="hov(this,'btn')" align="absmiddle">
 
&nbsp; <input type="submit" value="Delete" name="delete" class="btn" onMouseOver="hov(this,'btn btnhov')" onMouseOut="hov(this,'btn')" ></td>
</tr>
nonshatter 26 Posting Whiz

Personally, I wouldn't rely on updating your database to determine this. Precisely for the reason you just mentioned and it isn't necessary.

Have a read of this chapter of the php manual to see what fits your bill

http://www.php.net/manual/en/features.http-auth.php

nonshatter 26 Posting Whiz

So what are you trying to do?

From the title of your post it seems you're trying to create a table in a database, but your code is just printing data from your database?

nonshatter 26 Posting Whiz

I don't fully understand what you're asking. But PHP is a server-side language - Meaning that any request by the client must be sent to the server so PHP can process it.

You can process form data on the same page by using the $_SERVER global, as long as it is saved as .php:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

Otherwise, you can send it to another page to be processed:

<form action="process.php" method="post">
nonshatter 26 Posting Whiz

That's because it's outside of the foreach loop. Add the explode function inside the foreach scope and it should work :D

nonshatter 26 Posting Whiz

You can use Javascript inside a php function to control your redirects.

<?php

    redirect("www.redirecting.com/page.php"); 

    function redirect($url)
    {
?>
        <script type="text/javascript">
		window.location = "<?php echo $url ?>"
        </script>
<?php
    }
?>
nonshatter 26 Posting Whiz

So $testname is going to be your array right?

Try:

$testname[] = "|".$row['full_path']."|";

Then you could use a foreach() to loop through the array and apply the explode() function

nonshatter 26 Posting Whiz

Hi all, I have virtually no knowledge of C, but I have a problem with one of my scripts. It runs fine on a 64-bit Linux machine, yet it gives me a seg fault when run on 32-bit linux. gdb tells me that the seg fault occurs on line 314.

Here is the relevant section of code:

304        #define VSN_BUF_SIZE 1000
305        char* buffer = NULL;
306        buffer = (char *)malloc(sizeof(char) * (VSN_BUF_SIZE+1));
307        if (level > stdio_level && level > log_level)
308        {
309                free (buffer);
310                return 0;
311        }
312        
313        //  Seg fault occurs here: 
314        int count = vsnprintf(buffer,VSN_BUF_SIZE, format, ap);

Running through gdb from line 305, I get this:

(gdb) break script.c:305
(gdb) run
Starting program: /home/bin/script.c
305   in script.c 
(gdb) print buffer
$15 = 0xb7ea2720 ""
(gdb) n
306 in script.c
(gdb) print buffer
$16 = 0x0
(gdb)

The value of buffer at line 306 is 0x0, which is the NULL pointer. This is not what should happen, is it? - the buffer should point to the memory allocated on line 305, right?

I think the issue may be with malloc on line 306. If malloc returns NULL does that mean it cannot allocate the amount of memory requested?

Can someone please help me out here?

nonshatter 26 Posting Whiz

You can use strlen() to check this.

if(strlen($x) ==0)
{
    echo "X is blank";
}
nonshatter 26 Posting Whiz

yes, it is an incorrect command. It needs to be in this format:

$sql = mysql_query("UPDATE purchorderdetails SET unitprice='$price' WHERE record_number='$record_number'") or die(mysql_error());

I presume you have an 'ID' primary key field in your table? If not, it would be wise to create one, Otherwise you won't be able to limit which record(s) you are updating!

See here for an example of the Mysql UPDATE query http://www.tizag.com/mysqlTutorial/mysqlupdate.php

nonshatter 26 Posting Whiz

You can use another regular expression to decide whether to allow/deny the email address.

(\.([a-z]{3})$)

I'm no expert on these, but *I think* this will match ".com" at the end of the email address, so you'll need to work on how to match the sub-domains that you want to allow

**Edit=~ strpos() may do the job more easily. Look at this example from the php manual:

<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?>

And an even more useful example using strstr()

<?php
$email  = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com

$user = strstr($email, '@', true); // As of PHP 5.3.0
echo $user; // prints name
?>
nonshatter 26 Posting Whiz
$result = mysql_query ("select Name from dba.wx_faq_backup group by Name") or die (mysql_error());

echo "<select name='DB_Backup' value=''>Database Backup</option>";

$i=1;
while($nt=mysql_fetch_assoc($result))
{
    echo "<option selected value='$i' > $nt[Name] </option>"."<BR>";
    $i++;
}
echo "</select>";

Before, you were populating the value of the selection, rather than the actual selection option. You may want to put a numeric ID in the value property (signified by the $i)

nonshatter 26 Posting Whiz

Your coding was slightly incorrect. Your input field AND your submit button have the same names (name="submitcost").

This works:

<?php

	if (isset($_POST['submit'])) {
		$price = $_POST['submitcost'];
		echo $price ."<br>";
                echo "it works";
	}


?>

<form name="unitcost" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input ID="submitcost" name="submitcost" size="21" maxlength="20" VALUE=""> &nbsp; 
    <input type="submit" name="submit">
</form>

You should remember to put ALL your html property values in double quotes. And next time please post your code in [#code] tags!

nonshatter 26 Posting Whiz

Try re-writting your query so that it looks something like this:

$insert = mysql_query("INSERT INTO info (field1,field2,field3) VALUES ('$fname','$lname','$note')") or die(mysql_error());

(replacing <field1><field2> etc with the names of the corresponding columns in your database)

nonshatter 26 Posting Whiz

Personally, I find IDEs to be a waste of time. I just stick to the good old fashioned Notepad++ for windows, or gedit/kate for linux

Here's a list you can look at though http://www.ibm.com/developerworks/opensource/library/os-php-ide/index.html

(Eclipse seems to be a popular one)

nonshatter 26 Posting Whiz

Try the free clone of red hat first --> CentOs v5 --> http://mirror.centos.org/centos/5/isos/ If you don't like it, then go for fedora. If you're committed on learning the command-line stuff, rather than tinkering around appearance and software etc, then it really doesn't matter in my opinion.

Otherwise, you may need to buy a proper Redhat OS and/or pay for its support. In a big corporate, where uptime and stability is key - this is where the commercial grade of RHEL comes to the fore.

Even with CentOS which is basically RHEL, the support is not as good Red Hat themselves.

Edit:- Excuse my last post, Fedora is actually sponsored by RH, (and is not debian-based)!

nonshatter 26 Posting Whiz

You can break out of the php tags to make it a bit more manageable:

<td><a class="mylink" href="<?php 'www.'.$row['website']; ?>"> <?php echo "www.$row['website']" ?></a></td>

You'll also need an image link for the thumbnail...

<td> <img src="/path/of/image" alt="image description" href="<?php $row['url'] ?>" height="78px" width="78px"></td>

This prints "www.outputsite.com" and the link URL will be exactly the same. I think that's the solution to the problem as I understand it anyway

nonshatter 26 Posting Whiz

k, either try removing the double quotes completely from the version/encoding or if that still fails, try removing the escape chars, I'm not sure how necessary they are.

nonshatter 26 Posting Whiz

Looks like there's a few bugs in there...

1. You have commented out the filename so you're pointing to just 'a'. Not sure what you're trying to do here... This makes no sense! Also, you're trying to write three lines of code on one line... You should concatenate these lines

$fname=a;//$_GET('search_fname');echo $fname;
$lname=a;//$_GET('search_lname');

2. Your query variables should have single quotes around them like this:

$sql="SELECT fname,lname,email FROM user WHERE fname='$fname' AND lname='$lname'";

3. You have used incorrect quotes here:

$xml_name = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" ;

Change it to:

$xml_name = '<? xml version=\"1.0\" encoding=\"ISO-8859-1\";' ?>

4. You've missed the last closing php tag:

<? echo $fname; echo $lname; ?>

Those are the ones I saw straight away... there's probably more in there though

nonshatter 26 Posting Whiz

Hi there,

All Linux distros have some differences... But essentially, they all perform the same operations, albeit with slight desktop and/or command-line variations.

CentOS is a good, (free) RedHat-based distro, whereas Fedora is based on a debian system. When I first began using Linux I used Ubuntu (another debian based system, similar to fedora). The reason for this was for its ease of use - particularly in terms of software management and graphical interface.

Here's a little test you can take to see which distro(s) are best for your needs http://www.zegeniestudios.net/ldc/

nonshatter 26 Posting Whiz

This should get you started... It permutes the string, working out each combination. But it only works out combinations with the same amount of characters of the input string.

E.g. The 4 letter string "abcd" returns the following 4 letter combinations:
abcd
abdc
acbd
acdb
adcb
adbc
bacd
badc
bcad
bcda
bdca
bdac
cbad
cbda
cabd
cadb
cdab
cdba
dbca
dbac
dcba
dcab
dacb
dabc

<?php

	if (isset($_POST['submit']))
	{
		$input = $_POST['inputing'];
		permutate($input,0,inputlen($input)); // call the function.
	}

	// function to generate and print all N! permutations of $input. (N = inputlen($input)).
	function permutate($input,$i,$n) 
	{
		if ($i == $n)
		{
			echo $input ."<br>";
		}
		else 
		{
			for ($j = $i; $j < $n; $j++) 
			{
				swap($input,$i,$j);
				permutate($input, $i+1, $n);
				swap($input,$i,$j); // backtrack.
			}
		}
	}

	// function to swap the char at pos $i and $j of $input.
	function swap(&$input,$i,$j) 
	{
		$temp = $input[$i];
		$input[$i] = $input[$j];
		$input[$j] = $temp;
	}   
	
?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
	<input type="text" name="inputing">
	<input type="submit" name="submit" value="Submit">
</form>
nonshatter 26 Posting Whiz

Do i need to mount?
Do i need to repartition?

I'm not sure what exactly you're trying to do here... All you need for users to connect is a correct network set up with the correct services running. You could mount the VM disk over the network as well if that's what you want.

Can you be more explicit what you are trying to achieve?

nonshatter 26 Posting Whiz

That's fantastic. Thanks for your help.

Can you just explain to me this line:

($text1=~ m{^([a-z]{3}\-\d{3})$}i)?

I see that first, your checking that the first three chars must be letters. What does the \d mean? and also the i? I can't see how it checks that the last three characters are numbers?

nonshatter 26 Posting Whiz

you could create a loop and counter to count the number of users...

$sql = "SELECT COUNT(CDID) AS total FROM rtnUser GROUP BY CDID"; 
$query = mysql_query($sql);

$count=0;
while ($recordset = mysql_fetch_assoc($query))
{
   $count++;
}
echo "$count";
nonshatter 26 Posting Whiz

Okay, I've worked out a pretty ropey solution. It's not great but it kinda does what I want for now.

print "Enter Defect Number: ";
my $text1 = <STDIN>;
chop($text1);

if((length($text1) < 8))
{
	if ($text1 =~m/-/)
	{
		print "the string is correct\n";
	}
	else
	{
		if((length($text1) < 7))
		{
			print "The string needs a -\n";
			my $pre = substr($text1, 0, -3);
			my $post = substr($text1, -3, 5);
			print "$pre". '-' .$post. "\n";
		}
	}
}
else
{
	print "bad input\n";
	exit;
}

I'd welcome a better solution. Cheers

nonshatter 26 Posting Whiz

Hi all, I'm relatively new to Perl and particularly new to regular expressions.

This is really simple script I've just mocked up. All it does is to take the input string and check if it's in the correct format or not.

Here are some examples of correct format (will always be three letters followed by a '-' followed by three numbers):
TJD-111
IIS-193
XTT-920
If a user enters input without the '-' E.g:
JDJ222
XTT920
Then add a '-' between the characters/numbers.

Simple eh?

use strict;
print "Enter Defect Number: ";
my $text = <STDIN>;

if ($text =~m/-/)
{
	print "the input is correct\n";
        # do some other stuff
}
else
{
	print "The string needs a minus \n";
        # In this case, append the '-'
}
nonshatter 26 Posting Whiz

Also found this on linuxquestions forum:

"However, after many hours of searching and reading the solution to my problem was rather simple.
In the Preference/Privacy menu you have to change the Firefox will: to "Use custom settings for history" and there is "Accept cookies from sites" Exceptions box. In it was my problem web site.
Problem resolved."

Hope this works for you!

nonshatter 26 Posting Whiz

Can you explain what it is your code does? Do you set cookies etc in your code? Do all your scripts produce this same error, or is it just one that's causing the problem? Perhaps commenting out blocks of your code will narrow down the issue (should your problem reside in your code).

nonshatter 26 Posting Whiz

This could possibly be a problem specific to WAMP/LAMP or whatever you're using. You could try removing it completely and do a fresh install of each piece of software e.g. apache / php5 / mysql seperately. But it could be a lot of work if it turns out to not work!

Here are the packages you'll need if you decide to go down that route:

sudo apt-get install apache2
sudo apt-get install mysql-server php5-mysql mysql-client-5.1
sudo apt-get install php5 php5-cli
nonshatter 26 Posting Whiz

Hmm that's a strange one... There's nothing wrong with your config file.

There was a guy posting about this same problem earlier. You can find his thread here http://www.daniweb.com/forums/thread320621.html

He said that his problem was with an infinite loop caused by header redirects. Are you using header redirects in your code? If you are, perhaps try and comment them out and see if the problem remains.

nonshatter 26 Posting Whiz

Ohhhh apologies. I see what you're doing now...

Shouldn't it be odbc_result() instead of odbc_results() ?

Also leave the single quotes around the variables in your query otherwise mysql will enter them literally

nonshatter 26 Posting Whiz

I did an Online Auction website for my first PHP project. It took about 8 weeks of hard work.

Depends on how much time you have I guess...

nonshatter 26 Posting Whiz

Why not put your function(s) in a seperate file, and include that file as you need it

File1.php

function stuff()
{
     // do some stuff...
}

File2.php

include('File1.php');
$location=stuff();
echo $location;
nonshatter 26 Posting Whiz

Just found this on the ubuntu forum:

"You can remedy this by installing a simple Firefox extension called User Agent Switcher, effectively allowing you to switch your user agent string within the browser, allowing you to view sites that are IE only, etc.

After you get it installed, restart Firefox, and then modify your User Agent string via Tools > User Agent Switcher. Then choose Internet Explorer 6 (Windows XP). Then view the site you were trying to view before. Bingo!

Here's the link: https://addons.mozilla.org/firefox/59/"

nonshatter 26 Posting Whiz

I've never come across that message before but what Firefox is telling you is that the site is redirecting you in a loop E.g. Page A sends you to Page B which sends you to Page A.
An alternative is to install Google Chrome and see if you get a similar error message, if that fails:
Could be a cookies problem - have you cleared the cache on your virtual host?
Could you post the contents of /etc/apache2/sites-available/default

nonshatter 26 Posting Whiz

I've never used access, but you should be able to do the processing using PHP

First, convert to returned datetime variable to a unix timestamp
Then apply the date() function to display just the bits you want.

$date=odbc_result($query);
$convert_date = strtotime($date);
$formatted_date = date("Y-m-d", $convert_date);
echo $formatted_date;

Should work...

nonshatter 26 Posting Whiz

Sounds like a driver issue. Have you checked whether your hardware is supported on Ubuntu? I had the same problem with a Netgear wireless dongle. Have you using a wired connection?

nonshatter 26 Posting Whiz

Use sprintf() to control your output

nonshatter 26 Posting Whiz
for ($i=0;$i<=$x;$i++)
 {
	$query = mysql_query("select amount_id from payment where admission_no='$admission_no[$i]'") or die (mysql_error());
 }

You do not need to concatenate the query/variable. Just put single quotes around the variable you're inputting