nav33n 472 Purple hazed! Team Colleague Featured Poster

Then it *should* work. Unless you post your complete code, we won't be able to pin-point where exactly the problem is.

nav33n 472 Purple hazed! Team Colleague Featured Poster

If you don't mention form posting method [POST/GET], it will take the default value, ie., GET. So, $_POST will be empty.

Apart from that, It should work.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Post your code.

nav33n 472 Purple hazed! Team Colleague Featured Poster

If you know something and want to show your knowledge then please do not post those here as questions. Better post those as an article ,that will really help the new members.

In my opinion, It doesn't matter if it is a forum thread or an article to share knowledge. Forum thread is read by many people, including new members, experienced members and guest users. So, it's fine.


@landonmkelsey,

If you had also explained what is the danger it would have been great.

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

@Hitman Mania, The problem with your code is, the function array_search will return the key if it finds the needle in the array. Since "a" is the first element of the array, this will return 0 [the key].
0 which also corresponds to "false" is causing your script to fail.

@wrivera, Why use 2 loops when you can use one ? ie.,

<?php
if(isset($_POST['submit'])) {
	$vowels = array("a","e","i","o","u");
	$username = $_POST['fname'];
	$length = strlen($username);
	$count = 0;
	for($i=0;$i< $length; $i++) {
		$count = (in_array(strtolower($username{$i}),$vowels)) ? ($count + 1 ) : ($count + 0);
	}
	echo "There are {$count} vowels in $username<br />";
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Enter your First Name:<br><br>
<form action="test2.php" method="post">
Name: <input type="text" name="fname" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

in_array checks if a character is in the vowel array. If yes, increment count, else, don't do anything.

strtolower will make sure that it counts the vowels even if the user has entered his username in uppercase.

Cheers!
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

This above code works fine for me [apart from the insert query].
Few things to remember when dealing with databases.

1. Always sanitize user's input. Never trust your users. This can be achieved using mysql_real_escape_string .
2. If you are sure that the posted value is going to be an integer, use, is_numeric .
3. Mention all the column names in your insert query. For example,

$query = "insert into table (col1, col2) values ('val1','val2')";

Doing so will save you from the headaches you might have in future. Example, You are asked to add another field to log the time of insert. Then you have to change all the scripts in which you have an insert query.

Lastly, your query is wrong. There are no ' ' around table name.

INSERT INTO stock (mention_column_names_here) VALUES ('$item_name', '$item_model', '$item_desc', '$item_cost', '$item_qty')

P.S. It's also better to store your query in a variable. You can print out the variable incase your query isn't working and test it in phpmyadmin or mysql console.

Oh, Btw, you can also make use of die(mysql_error()); to know why your query failed.
ie.,

$result = mysql_query($query) or die(mysql_error());

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

$row will have an array. You can explode only strings, not arrays. And, as JRM mentioned, I don't recommend the use of mysql_fetch_row. Since this returns an numeric index array, you will have to use $row[0], $row[1] etc.
Say, after sometime, you change the database structure, by adding/removing a field [first field for example], then that is going to be a big problem as $row[1] will now correspond to the newly added field!

Always use mysql_fetch_array or mysql_fetch_assoc.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Not sure what exactly I changed, but this works.

<html>
<head>
<script type="text/javascript">
function resizeText(multiplier,p,what) {
	if (document.getElementById(p).style.fontSize == "") {
		document.getElementById(p).style.fontSize = "1.0em";
  	}
  	if(what == "increase") {
  		document.getElementById(p).style.fontSize = parseFloat(document.getElementById(p).style.fontSize) + (multiplier * 0.2) + "em";
  	} else {
  		document.getElementById(p).style.fontSize = parseFloat(document.getElementById(p).style.fontSize) - (multiplier * 0.2) + "em";
  	}
}
</script>
</head>
<body>
<?php 
 $c=0;
 $c = $c +1;
 $text = "Click the button to increase the size of the font. Keep clicking it until you get tired.";
 $p="par".$c;

echo "<p align='right'><input type='button' name='button' value='Increase font' onclick='resizeText(1,\"$p\",\"increase\");' />";
echo "<p align='right'><input type='button' name='button' value='Decrease font' onclick='resizeText(1,\"$p\",\"decrease\");' />";         
echo "<p align='justify' id='".$p."'>".$text."</p>";
?>
</body>
</html>

Cheers!
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

Wow, did you just spam me in my question thread?

You didn't even answer the question!

:) Thanks for notifying. Appropriate action has been taken.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yay! You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

It outputs, three records for the user who is at the bottom of the user table, i.e date_joined DESC.

Actually, date_joined DESC should sort the records on date_joined column with the latest date on top. Can you try this query ?

SELECT media.file_name, users.username, users.creative_specialism
FROM media, users
WHERE media.user_id = users.user_id 
GROUP BY media.user_id 
ORDER BY users.date_joined DESC
LIMIT 3

GROUP BY will group all the records having common user_id in media table, more like, what DISTINCT would do.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi, You don't have to run the select query thrice. In my opinion, this should work.

SELECT media.file_name, users.username, users.creative_specialism
FROM media, users
WHERE media.user_id = users.user_id 
ORDER BY date_joined DESC
LIMIT 3
nav33n 472 Purple hazed! Team Colleague Featured Poster
<form method='post' action='test.php' onSubmit='javascript: return validate();'>
</form>

This was reported long time ago. [Unfortunately, I can't find it] . Click on Toggle plain text and see <b></b> right next to javascript.
Browser: Firefox 3.5.5 & IE7.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I told you about step 2 and step 4. But, I should have been more descriptive [since you are kinda new to php].
But, in the end it doesn't even matter :P Congrats on finding the solution!
Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

Indeed :P

nav33n 472 Purple hazed! Team Colleague Featured Poster

Cheers man :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

If it is *really* something small, then maybe its time for me to get a new pair of eyes. :D
Anyways, Lets hope someone else here finds what's wrong.
Anyways, Good luck :).

nav33n 472 Purple hazed! Team Colleague Featured Poster

That's really strange. :S Sorry, It seems like I have reached the dead end and can't think of one good reason why it's failing to update the record.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. I see what you are talking about. Did you try printing the query and executing it in phpmyadmin or mysql console ?
Your script looks good though :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, I checked your script and it is fine. I don't see any errors. Apart from saying 'It works', does it say anything else ? Could you be more specific ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Pass $row as a parameter to this date function and return the changed value.
Eg.

function changeDate($date) {
 $newdate = date('d/n/y',strtotime($date)); 
 return $newdate;
}

Call this function wherever applicable. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

@evstevemd,
You missed "/" in myfoldername variable. So it will create the sql file as,

MyBackupsdb-backup-1259831393-....... .sql

@futhonguy,
You can use evstevemd's code.

$myfoldername = getcwd()."\\MyBackups/";//your folders name 
mkdir($myfoldername , 0777);
$handle = fopen("$myfoldername".'db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');

Notice the "/" in $myfoldername.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You have to mention the path where you want the .sql file to be created.
This will create a folder called backup [if it doesn't exist and then create the .sql file in that folder].

<?php
backup_tables('localhost','root','','test2');


/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
	
	$link = mysql_connect($host,$user,$pass);
	mysql_select_db($name,$link);
	
	//get all of the tables
	if($tables == '*') {
		$tables = array();
		$result = mysql_query('SHOW TABLES');
		while($row = mysql_fetch_row($result)) {
			$tables[] = $row[0];
		}
	} else {
		$tables = is_array($tables) ? $tables : explode(',',$tables);
	}	
	//cycle through
	foreach($tables as $table) {
		$result = mysql_query('SELECT * FROM '.$table);
		$num_fields = mysql_num_fields($result);		
		//$return.= 'DROP TABLE '.$table.';';
		$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
		$return.= "\n\n".$row2[1].";\n\n";
		
		for ($i = 0; $i < $num_fields; $i++) {
			while($row = mysql_fetch_row($result)) {
				$return.= 'INSERT INTO '.$table.' VALUES(';
				for($j=0; $j<$num_fields; $j++) {
					$row[$j] = addslashes($row[$j]);
					$row[$j] = str_replace("\n","\\n",$row[$j]);
					if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
					if ($j<($num_fields-1)) { $return.= ','; }
				}
				$return.= ");\n";
			}
		}
		$return.="\n\n\n";
	}
	
	//save file
	if(!is_dir("backup")) {
		mkdir("backup",0777);
	}
	$handle = fopen('./backup/db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
	fwrite($handle,$return);
	fclose($handle);
}
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

:) As the error itself says, foto is undefined.

$ficheiro=$_FILES['foto'];

should be

$ficheiro=$_FILES['file'];

One more thing, notices are usually generated when you don't initialize a variable [and start using it]. Check out php.net -> error_reporting for more details.
Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hey, Hi.. Instead of ereg_replace, you an use str_replace. Both serve the same purpose. Replace \n with \\n so it don't get escaped. Anyways, the second 'error' is not an error but a notice. You can declare and initialize a variable to avoid getting notices. [or] you can make use of error reporting

error_reporting(E_ALL ^ E_NOTICE);

in your script.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hum, I've always looked at installing a new OS as fun. Course I've probably been doing it longer than with, and installed a wider range of operating systems.

Now of course I install them in a VM. I like VirtualBox. It does a nice job. Heck, that's how I run Windows when I need too (about once every 3 or 4 months).

No. It's not always about you. Give us all a break and take your Linux/mac obsession somewhere. We have no idea why you 'promote' Linux and use Mac. We are definitely not mind readers. Your words/suggestions are of no value here . And regarding your first post and mine, well, mine was a tad bit helpful than your,

download and burn the ISO to CD, and install it in place of Windows. You'll never have Trojan problems again.

Beyond that, I don't have a clue, I gave up on Windows years ago.

Bah! Anyway, I will now stop feeding the troll. Have a good life.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I am facing Torjan virus when i used net it come with in one minute anybody can help me in this regard i will be very thankful.

Post your question in this forum specifying all the details of your computer/operating system etc.

@Mad hatter,
Get over with your linux obsession. It's not doing any good to anyone.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Ah, nevermind. My apologies.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can set a cron to run on every first day of the month, which will copy the record from main table to archive table[and delete entries in the main table].
We do it the same way in our company, but the data is archived on yearly basis. I also hope that your tables are neatly indexed as they play a vital role in the execution time of a query.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Sorry man. That's just not my area of expertise. :) Lets see if someone else can help you with this. Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Great :) Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Are you sure its administrator ? I know about mysql's 'root', but never heard of administrator.
And when you say phpmydirectory, are you talking about phpmyadmin or something else ?
Also check which php.ini file is being used by web server. In wamp, it uses the file in C:\wamp\Apache2\bin . .

nav33n 472 Purple hazed! Team Colleague Featured Poster

$query = mysql_query("SELECT * FROM Employee WHERE $method = '$search'");
$result = mysql_query($query);

This is wrong. Try,

$query = "SELECT * FROM Employee WHERE $method = '$search'";
	$result = mysql_query($query);
nav33n 472 Purple hazed! Team Colleague Featured Poster

Check out tcpdf. It has around 40+ examples of writing pdf. It's easy. [Get the data from mysql, format it like html and create pdf on the fly!]

nav33n 472 Purple hazed! Team Colleague Featured Poster

Ah! All's well. :) Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

I tried to use the above code for an example and i came across a Deprecated on Call-time pass-by-reference for these following code:

array_map( 'stripslashes',&$_POST ); //Strips slashes
    array_map( 'mysql_real_escape_string',&$_POST ); //Escapes data to protect against sql injection

.

can anyone assist me on this? thanks

Use

array_map('stripslashes,$_POST); 
array_map('mysql_real_escape_string',$_POST);

Here is a quote from php.net .

There is no reference sign on a function call - only on function definitions. Function definitions alone are enough to correctly pass the argument by reference. As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Or you could insert the data from the first page into the database as soon as it is submitted, have the user fill out the second part, and just update the row when the second part is submitted.

The only problem with this is , if a user loses his interest midway [ie., after submitting 1st form], there will be a obsolete record in the table. Or else, this is good.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can do it in 2 simple ways (maybe there are even more, but I am not aware of it).
You can either save the data of the first form in session after it is posted, and then, when the second form is posted, get all the data (session data and the 2nd form's posted data) and insert a record to the table.
The second method is to have hidden fields in the 2nd form, which will save all the values of the first form and when the 2nd form is submitted, you will have the data of 1st and 2nd form :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

What I meant was ,

function procRestSearch($searchQuery){ 
	//Don't forget to have $searchquery defined before calling this function
	$intSearchCounter = 0; //Used to set the arrays
	$searchResult = mysql_query($searchQuery);
	$strRest = array();
	while($searchRow = mysql_fetch_array($searchResult, MYSQL_ASSOC)){
		//Change/Add/Delete the variables below to match what data needs to be returned
		$strRest[$intSearchCounter] = array('restID' => $searchRow['rest_id'], 
			'restName' => $searchRow['rest_name'], 'restAddress' => $searchRow['rest_address'], 
			'restAddress2' => $searchRow['rest_address2'], 'restCity' => $searchRow['rest_city'], 
			'restState' => $searchRow['rest_state'], 'restZip' => $searchRow['rest_zip'], 
			'restCC' => $searchRow['rest_country_code'], 'restAC' => $searchRow['rest_area_code'], 
			'restPhone' => $searchRow['rest_phone_no'], 'restFAC' => $searchRow['rest_fax_no'], 
			'restManager' => $searchRow['rest_manager'], 'restAsManager' => $searchRow['rest_assistant_manager'], 
			'restWebsite' => $searchRow['rest_website']);		
		$intSearchCounter++;
	}
	return $strRest;
}

And secondly, using the above error reporting would still display the errors but not the notices. As I said in my previous post, if you like to fix the notices, initialize your variables, use $var instead of $var[something] and so on. (notices can be ignored).
Does it work for you ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Initialize the array outside the while loop. The array is getting over-written everytime it enters the loop. So you are getting only the last record.
Secondly, notices can be ignored. If you use variables without initializing them, you will get a notice. It is a good programming practice to initialize all your variables before using them. But sometimes, it gets a little annoying. You can disable notices by changing your php.ini file.
Search for error_reporting and uncomment this line.

error_reporting = E_ALL & ~E_NOTICE

Meaning, show all errors except notices.
Check this link to configure error reporting in your script.

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

I clicked the link you provided, went to the second post and saw all the "printf" in bold. When I click "toggle plain text", no HTML code whatsoever is shows. No <strong> or <bold> .
I'm using ff3 on Windows vista 64

It did for me.

<strong class="highlight">String</strong> format = "<strong class="highlight">String</strong> a = %s <strong class="highlight">String</strong> b = %s \n";
System.out.printf(format, a, b);

FF 3.5.5 on windows XP.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You *cannot* decrypt it. If you store sha1 of a string, while authenticating, convert the string to sha1 and compare it with the value in the table.

nav33n 472 Purple hazed! Team Colleague Featured Poster

When the user submits the page, build your query depending upon the user's selection.
If the user has selected from_year and to_year, include that in your condition and so on.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Please be specific with your question.

nav33n 472 Purple hazed! Team Colleague Featured Poster

The echo statement is incorrect.

echo "<a href=\"inventorid.php?inventorid=".$data2['inventorid']."\">".$data2['inventorid']." ".$data2['firstname']." ".$data2['lastname']."</a>\n";

is the correct syntax.
Also, to make life simple, you can use,

$inventorid = $data2['inventorid'];
$firstname = $data2['firstname'];
$lastname = $data2['lastname'];
echo "<a href='inventorid.php?inventorid=$inventorid'>$inventorid $firstname $lastname</a>\n";

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Ofcourse you can. But for that, you should make sure all the required fonts are installed.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Technically, it doesn't matter if you have only 1 line statement after a condition. ie.,

<?php
$x = 1;
if($x == 1) 
    echo "$x is valid.";
else 
    echo "$x is invalid";
?>

This will not work if you have more than 2 statements in your condition.
Btw, its not a good practice to miss { } for your conditions.

nav33n 472 Purple hazed! Team Colleague Featured Poster

m not student.. m professional..and this is required for my proj..
dnt worry i solved it now...no need to waste ur time..

Congrats on solving your problem. I am glad you learnt something new :)

If you post your answer, even others may get to learn something from this thread.