$t= "<script>document.write(new Date().toLocaleTimeString()+' '+new Date().toLocaleDateString())</script>"; [duplicate] - php

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 3 years ago.
I am inserting
$t= "<script>
document.write(new Date().toLocaleTimeString()+' '+new Date().toLocaleDateString())
</script>";
into the database . echo $t gives the correct data and time but while inserting into the database , it is inserted as
"<script>
document.write(new Date().toLocaleTimeString()+' '+new Date().toLocaleDateString())
</script>";
?
why does it so ? Also, The column where, I am inserting this $t is of varchar type.

You're explicitly requesting that string to be stored in the DB, not the result.
Try $t=date('Y-m-d');
Modify the date format to match your regional requirement

Related

How can I fix the error when does not recognize the to_date function in mysql(phpmyadmin)? [duplicate]

This question already has answers here:
How to convert a string to date in MySQL?
(5 answers)
Closed 3 years ago.
I want to insert this:
INSERT INTO NAVE (nume, clasa, anul_lansarii) values ('Ticonderoga','Ticonderoga',to_date('02/02/1930','mm/dd/yyyy') );
and gives me the error:
1305 - FUNCTION proiect.to_date does not exist
There is no to_date() function in MySql but you can use str_to_date():
str_to_date('02/02/1930','%m/%d/%Y')
See the demo.
to_date is not default mysql function.
But from your question i think you can use STR_TO_DATE function. like this:
INSERT INTO NAVE (nume, clasa, anul_lansarii) values ('Ticonderoga','Ticonderoga',STR_TO_DATE('02/02/1930','mm/dd/yyyy') );

Creating an Empty Format Parameter in PHP to hide the output [duplicate]

This question already has answers here:
The 3 different equals
(5 answers)
Closed 5 years ago.
So I'm new to PHP and write bad code. I am trying to format a calendar to show the entries as list entries. Furthermore, if an event time was entered at 12 AM, I am trying to hide that outputted value. Here is the tutorial that I am using https://spunmonkey.com/display-contents-google-calendar-php/.
Here is the code that is from the tutorial:
$eventdate = new DateTime($eventDateStr,$timezone);
$newmonth = $eventdate->format("M");
$newday = $eventdate->format("j");
$newtime = $eventdate->format("g");
$newtimeAM = $eventdate->format("A");
Here is what I am trying to do and my horribly written code (this if for the newtime div:
<?php
if ( $newtime="12" && $newtimeAM="AM") {
echo $eventdate->format("");
} else {
echo $newtime;
}
?>
I have written the same if statement for $newtimeAM. My questions are:
Can I use the if statement to set the value to the outputted string, (like $newtime="12")?
Can I use the format parameter to return an empty string, as to hide the values if the conditions are met?
Right now, it does display the calendar entry, but not with the time. For example, there is an entry that starts at 2 PM that I want the calendar to show, but it's not showing. Also, what references that anyone give to learn PHP online? I know w3 is pretty awesome and well as php.net.
Try fixing your if statement. One = assigns, two == checks!
if ( $newtime == "12" && $newtimeAM == "AM") {
The way your code is, you SET these vars, so nothing will output each time!

how to find who is department head of employee USING IN CLAUSE in php [duplicate]

This question already has answers here:
Passing an array to a query using a WHERE clause
(17 answers)
Closed 6 years ago.
$department_id=19
$deptshead(17,19,3)
$sql_depthead ="SELECT * FROM nonaudit_employee WHERE status = 'Active' AND rights = 3 AND deptshead IN(".$department.")AND cand_id!= ".$cand_id;
its working fine but
it only match first dept head cant check the second dept value???
I'm not sure if I correct understood.
You can try to use:
$inClause = implode(",", $deptshead);
And after that use $inClause var in your query

How to get all parameters in MSSQL Stored Procedure [duplicate]

This question already has answers here:
Find the parameter names of a stored procedure
(3 answers)
Closed 8 years ago.
When I was using asp, I was able to do the following - now I am using php and sqlsrv - how do I achieve the same in php
Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = "dbo.spGetItem"
oCmd.CommandType = &H0004 'adCmdStoredProc
oCmd.Parameters.Refresh
For Each prmTemp In oCmd.Parameters
Response.Write( prmTemp.direction & "<br/>" & prmTemp.name)
Next
Set oCmd = Nothing
The simplest way regardless of client language is to just query the metadata / catalog views:
SELECT name, is_output
FROM sys.parameters
WHERE [object_id] = OBJECT_ID('dbo.spGetItem');
select ORDINAL_POSITION, PARAMETER_NAME, DATA_TYPE, PARAMETER_MODE from information_schema.parameters
where specific_name='Proc_Name'

how can i input php in mysql without repeat? [duplicate]

This question already has an answer here:
Input my php in mysql without repeat?
(1 answer)
Closed 9 years ago.
I want to add some random number that created by PHP to my SQL without repeat.
I use this code to create 14 length random:
for ($i=0;$i<10;$i++) {
$n1 = rand(100000,999999);
$n2 = rand(100000,999999);
$pincode = (string)$n1.(string)$n2;
echo $pincode;
echo nl2br("$pincode\n");
Now I want to input created a number in My SQL and ignore the repeated number.
How can I do that ?
The best way is to use timestamp. It shall always be unique and no chance of duplicacy.
Afroz, timestamp is probably unique, but very predicteable ;-)
This might be interesting: How to 'insert if not exists' in MySQL?

Categories