String Operation: string. string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zxn
Forum Newbie
Posts: 3
Joined: Thu May 25, 2006 5:49 am

String Operation: string. string

Post by zxn »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I was tring to link two strings together and then save it into dbf file. 
I used "." to integrate the two string it seems work. But when saving the new string into dbf file, only the first string was save. 

Please see the code below:

Code: Select all

$dbname= realpath("../data/comment.dbf");
$db = dbase_open($dbname, 2);
$string= $HTTP_FORM_VARS["oldComment"].gmstrftime ("%a %d-%b-%y %H:%M:%S %z", time ()). ':<br>' . $HTTP_FORM_VARS["newComment"]; 	
Printf ("The new comment is: %s ", $string); 
$def = array($HTTP_FORM_VARS["theme"],$string);
dbase_replace_record($db, $def,($HTTP_FORM_VARS["SelRecNumber"]+1));								 
dbase_close ($db);
The string is correct when printing out (oldComment + Time+ newComment). But in the dbf record only 'oldcomment' was saved.
Any idea why this is happening?
Thanks

Xiaonan


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post by William »

Try putting this instead and see what it outputs.

Code: Select all

echo "{$HTTP_FORM_VARS['oldComment']}".gmstrftime("%a %d-%b-%y %H:%M:%S %z", time()).":<br>{$HTTP_FORM_VARS['newComment']}";
Edit: If you copied before I added this edit please re-copy as there were a few mistakes.

Another edit, if you still seem to have problems make a new PHP file with the following code and set your form action to the new file.

Code: Select all

<?php
	print "<pre>";
	print_r($HTTP_FORM_VARS);
	print "</pre>";
?>
If you're not sure what to do with the data it outputs just post here. :) (as long as the form doesn't give out any information you prefer not to give out.)
zxn
Forum Newbie
Posts: 3
Joined: Thu May 25, 2006 5:49 am

Post by zxn »

Thanks for your reply.

The echo code you wrote works fine that both the value of {$HTTP_FORM_VARS['oldComment']} and {$HTTP_FORM_VARS['newComment']} diplayed on screen .

However the value of {$HTTP_FORM_VARS['newComment']} still not save in dbf record.

why?
zxn
Forum Newbie
Posts: 3
Joined: Thu May 25, 2006 5:49 am

Post by zxn »

The strange thing is if I change the order of the two $HTTP_FORM_VARS[]. It works fine.

See code below:

Code: Select all

$dbname= realpath("../data/comment.dbf");
$db = dbase_open($dbname, 2);
$string= $HTTP_FORM_VARS["newComment"].gmstrftime ("%a %d-%b-%y %H:%M:%S %z", time ()). ':<br>' . $HTTP_FORM_VARS["oldComment"];        
Printf ("The new comment is: %s ", $string);
$def = array($HTTP_FORM_VARS["theme"],$string);
dbase_replace_record($db, $def,($HTTP_FORM_VARS["SelRecNumber"]+1));                                
dbase_close ($db);
Post Reply