simple question

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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

simple question

Post by ol4pr0 »

i added this into my form

Code: Select all

<input type=hidden name="dato" value="<?PHP ECHO ('F d Y'); PHP?>"></input>
but it gives me this result in my database.
<?PHP ECHO ('F d
What am i doing wrong here
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Maybe you want :

<input type=hidden name="dato" value="<?php echo date('F d Y'); ?>"></input>

Though doing that in a hidden field seems a bit pointless as you could just get the date on the receiving page (i.e the page in action=" ... ")
*shrug* ;)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

php echo date('F d Y'); // tried this.
Also had it declared before with a $dato = date....

Didnt work @ all.
markl999 wrote: Though doing that in a hidden field seems a bit pointless as you could just get the date on the receiving page (i.e the page in action=" ... ")
*shrug*
and how would i do that.?

Code: Select all

<form action="{$_SERVER['PHP_SELF']}"  method="post>
Thats becuase it needs to be added automaticly without having to type it.
i could also do a READONLY TABINDEX="-1"

Could it because i am trying to use it inside a function { ?

Seem to have more troubles with php functions its like they are private by default somehow.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, you basically have a form, and you post that form back to the same page, then 'do something' with the form. Lets say for arguments sake you are inserting the form variables into a database.
In the bit of code that inserts into the database just do $dato = date('F d Y'); , you shouldn't need to pass it in a hidden field as it's the type of information that can be gained at the point where you need to use it and not before, if that makes sense ;)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Absolutly lost it there on the last part.

However i did try to declare date('Y d F') just before the query if you mean that. No result :cry:
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Hmm, would have to see the query code, but if for example you have :

$dato = date('Y d F');
$query = "INSERT INTO foo (fname, lname, dato) VALUES ('{$_POST['fname']}', '{$_POST['lname']}', $dato)";
mysql_query($query) or die(mysql_error());

That sorta thing should be ok.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

oke gave that example a try.. couldnt make it happen in my query

which looks like this

Code: Select all

function process_form() 
{
	$dato = date('F d Y');

	$query ="INSERT INTO pongo (Empresa, dato, Codigo, Paqnr, 
Desde, Envio, information, comentario, peso_total, peso, Valor) VALUES  ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Paqnr']."','".$_POST['Desde']."','".$_POST['Envio']."','".$_POST['Information']."','".$_POST['Comentario']."','".$_POST['Peso_Total']."','".$_POST['Peso']."','".$_POST['Valor']."', $dato)";
i am trying to have that dato inserted and try to have my xml output being sorted by date for this


viewtopic.php?t=17417
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

My mistake, that should be '$dato' inside the query, not just $dato.

If it still "doesn't work" then post the output of echo $query;
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

yea i did notice the '$dato' and thats why i gave the $dato a try.

however this is what i got now.

Code: Select all

'"$dato"')"
and like you suspected it didnt work. however i am lost on the echo $query part
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

$query ="INSERT INTO pongo (Empresa, dato, Codigo, Paqnr, 
Desde, Envio, information, comentario, peso_total, peso, Valor) VALUES  ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Paqnr']."','".$_POST['Desde']."','".$_POST['Envio']."','".$_POST['Information']."','".$_POST['Comentario']."','".$_POST['Peso_Total']."','".$_POST['Peso']."','".$_POST['Valor']."', '$dato')"; 
echo $query; //for debugging purposes
mysql_query($query) or die(mysql_error());
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

The example you gave me produced this error
Parse error: parse error, unexpected T_VARIABLE in on line 73
which is the query line.


I tried the following

Code: Select all

"'. $dato .'"
which gave me this error
Notice: Undefined index: dato on line 73
Notice: Undefined variable: dato on line 73
INSERT INTO pongo (Empresa, dato, Codigo, Paqnr, Desde, Envio, information, comentario, peso_total, peso, Valor) VALUES ('111','','1111','11','11','1','1','1','111','1','11','')Column count doesn't match value count at row 1
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Hmm..weird, there's no parse error in the query line i pasted..i checked :o
And Notice: Undefined index: dato on line 73 doesn't make any sense as you're not using it as an index, or shouldn't be....

Might be worth double checking you copied and pasted my example ok, unless i've gone crazy and did make an error i can't see ;)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well thanks for the help. i got it fixed.. here is what it should of been all along.

Code: Select all

function process_form() 
{
	$dato = date('Y d F');
	
	// are all these values going into the field PONGO or is pongo the table name?  if it's the table name, instead of the table name put field names like i've done 
	$query ="INSERT INTO pongo (Empresa, Codigo, Paqnr, Desde, Envio, information, comentario, peso_total, peso, Valor, dato) VALUES  ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Paqnr']."','".$_POST['Desde']."','".$_POST['Envio']."','".$_POST['Information']."','".$_POST['Comentario']."','".$_POST['Peso_Total']."','".$_POST['Peso']."','".$_POST['Valor']."','".$dato."')"; 
//	echo $query; //for debugging purposes
:oops: i still had a .$_POST['dato']. in the VALUES list

Lets see if i can get all the $rows in my xml document now.. if you feel up to i would like you to take a look.

It doesnt have any errors, the xml document is well formatted. it only wont display all $rows like it should. ( 40 instead of 1 )

viewtopic.php?p=85001#85001
Post Reply