Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I need to format Date time to specific date format using php.
Now date format
2014-02-10 09:32:24
I need format
2014/02/10
error is :Parse error: syntax error, unexpected '$ModifiedDate' (T_VARIABLE), expecting ',' or ';' in ................. line
Here i tried like this
<?php
include(config.php);
$sql = "SELECT Id,Title,description,Image,Category,ModifiedDate from News WHERE ISActive=true";
$query = mysql_query($sql);
if(mysql_num_rows($query)>0){
while($test = mysql_fetch_array($query))
{
$Mod = $test['ModifiedDate'];
$ModifiedDate = date_format($Mod, 'yyyy/MM/dd');
echo"<td><font color='black'>"$ModifiedDate"</font></td>";
}
}
else
{
echo "No Records";
}
?>
You forgot to concatenate the variable. Do like this
echo"<td><font color='black'>".$ModifiedDate."</font></td>";
//^----- ^----- Add those dots !
Use below format,
date_format($Mod, 'YY/MM/DD');
try this code:
$ModifiedDate = date_format($Mod, 'Y/m/d');
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have this PHP code:
$uniqueSessionID = 'd41740fd9dc75cb8a3eeee27165d2323';
$returnUrl = 'http://qapache.us.oracle.com:15671/OA_HTML/OA.jsp?OAFunc=ICX_\nCAT_PUNCHOUT_CALLBACK&OAHP=ICX_POR_HOMEPAGE_MENU&OASF=ICX_CAT_PUNCHOUT_\nCALLBACK&transactionid=1577779317'
$timestamp = $conn->real_escape_string('2016-02-10 07:57:21');
$cxmlVersion = $conn->real_escape_string('1.1.007');
$payloadID = $conn->real_escape_string('20040316032452.913060910.144270#ap6172rt.us.oracle.com');
$sql2 = "INSERT INTO return_cart_url (`sessionid`, `timestamp`, `version`, `return_url`, `payloadID`)
VALUES ('{$uniqueSessionID}','{$timestamp}', '{$cxmlVersion}' '$returnUrl', '{$payloadID}')";
if ($conn->query($sql2) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql2 . "<br>" . $conn->error;
}
And i get this error:
Column count doesn't match value count at row 1
All my columns are varchar. In the beginning i only had the columns uniqueSessionID and returnURL, and with these 2 it worked. It happened when I added the timestamp, cxmlVersion and payloadID.
Anyone who can explain me why this happens?
You forgot 1 comma :
'{$cxmlVersion}','$returnUrl'
you forget one , after cxmlVersion
$sql2 = "INSERT INTO return_cart_url (`sessionid`, `timestamp`, `version`, `return_url`, `payloadID`)
VALUES ('{$uniqueSessionID}','{$timestamp}', '{$cxmlVersion}', '$returnUrl', '{$payloadID}')";
I am guessing it is because you are missing the brackets in the values definition of the return Url, and there is a missing colon after cxmlVersion.
VALUES ('{$uniqueSessionID}','{$timestamp}', '{$cxmlVersion}' '$returnUrl', '{$payloadID}')";
Becomes:
VALUES ('{$uniqueSessionID}','{$timestamp}', '{$cxmlVersion}', '{$returnUrl}', '{$payloadID}')";
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am getting an error while running this code:
Fatal error: Call to a member function bindParam() on boolean in D:\xampp\htdocs\ipack\insertstatus.php on line 9
<?php
header('Access-Control-Allow-Origin: *');
include 'dbconnection.php';
$jobno = "AFE/0001/2015";
$jobseq = 0;
//to get INTJOBNO
$intjobno = "";
$data = $dbh->query("select INTJOBNO from PRTJOBHD where JOBNO = :jobno and JOBSEQ = :jobseq");
$data->bindParam(':jobno',$jobno,PDO::PARAM_STR);
$data->bindParam(':jobseq',$jobseq,PDO::PARAM_STR);
$data->execute();
foreach($data as $row) {
$intjobno = $row['INTJOBNO'];
echo $intjobno;
}
>
Have a look at this answer: PDO's query vs execute. You cannot bind parameters to PDO query, you need to use prepare instead.
header('Access-Control-Allow-Origin: *');
include 'dbconnection.php';
$jobno = "AFE/0001/2015";
$jobseq = 0;
//to get INTJOBNO
$intjobno = "";
$data = $dbh->prepare("select INTJOBNO from PRTJOBHD where JOBNO = :jobno and JOBSEQ = :jobseq");
$data->bindParam(':jobno',$jobno,PDO::PARAM_STR);
$data->bindParam(':jobseq',$jobseq,PDO::PARAM_STR);
$data->execute();
foreach($data as $row) {
$intjobno = $row['INTJOBNO'];
echo $intjobno;
}
PDO::query() returns a PDOStatement object, or FALSE on failure.
Source
It means your query has failed for some reason.
In this case you are using the wrong function to do what you want to do.
You need to prepare your statement since you want to bind two parameters in your query.
Use $dbh->prepare() instead of $dbh->query().
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
There is an error in my code but the code works perfectly. I mean all the values are inserted in the database but there is an error like this on the screen:
Severity: Notice
Message: Array to string conversion
Filename: models/some_model.php
Line Number: 106
This is my code:
View:
<?php foreach($app as $row){
echo "<tr><td><input type=checkbox name=appname[] value='".$row->app_name."'/>".$row->id."</td><td>".$row->app_name."</td><tr>".
?>
Controller:
public function hide(){
$this->load->model('some_model');
$visi = $this->input->post('appname');
$success = $this->some_model->hideApp($visi);
foreach($visi as $key=>$value)
{
$success = $this->some_model->hideApp($visi[$key]);
}
if($success == TRUE)
$this->hideApp_page(TRUE);
else $this->hideApp_page(FALSE);
}
Model:
public function hideApp($visi){
$visi = $this->db->escape_str($visi);
$queryStr = "UPDATE appwarehouse.application_table SET visibility='hidden' where app_name='$visi';"; /* this is line 106*/
$query = $this->db->query($queryStr);
return $query;
}
$visi is array like [1,2,3,4]
when you put $visi in hideApp()
it will be display "array to string error"
so maybe you can remove this line $success = $this->some_model->hideApp($visi);
you have already do some_model->hideApp($visi[$key]) in the foreach loop
so i don't know why you write this$success = $this->some_model->hideApp($visi);
if you still want to run $success = $this->some_model->hideApp($visi);
you have to put $visi into a string
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Im trying to run a query(UPDATE) inside a while loop like this:
<?php
session_start();
include("../DB/thedb.php");
$user = $_POST['u'];
$ruta = $_POST['r'];
$select_all_p_from_user = #mysql_query("SELECT * FROM publicaciones WHERE from_user_p = '$user' AND user = '$user'");
while($rows_all_user = #mysql_fetch_array($select_all_p_from_user)){
$update_from_user = $rows_all_user['from_user_p'];
$update_user = $rows_all_user['user'];
$update_foto = $ruta;
$update_nombre = $rows_all_user['nombre'];
$update_comentario = $rows_all_user['comentario'];
$update_time = $rows_all_user['time'];
$update_date = $rows_all_user['date'];
$update_p_photo = $rows_all_user['p_photo'];
$update_to_delete = $rows_all_user['to_delete'];
//Process to update selected ROW
// This is the line 55
$update_current_row = #mysql_query("UPDATE publicaciones SET from_user_p = '$update_from_user', user = '$update_user', foto = '$ruta', nombre = '$update_nombre', comentario = '$update_comentario', time = '$update_time', date = '$update_date', p_photo =
'$update_p_photo', to_delete = '$update_to_delete' WHERE from_user_p = '$user' AND user = '$user'") or die mysql_error(); // End of the line
}
?>
I'm getting the following error:
Parse error: syntax error, unexpected T_STRING on line 55
Try this,
or die (mysql_error());
instead of
or die mysql_error();
Also, in update query, for the time and date columns need to be wrapped with backticks since those are all reserved words.
`time` = '$update_time', `date` = '$update_date'
The error you're encountering is a parse error. It does not have anything to do with MySQL. The error is that you have not placed the argument for or die inside parenthesis.
A couple of BIG warnings:
You've not escaped the data you send to MySQL. If any of the fields you're fetching from the publicaciones table contains ' you'll get errors.
If a user logs in with $_POST['u'] = "' OR ''='" the select statement will result in every record.
Please look into http://no2.php.net/mysql_real_escape_string to fix your big security issues.
Illustrative comic:
(source: smashingmagazine.com)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
I want to fetch every result from table 'Themes'.
function display_all_themes()
{
global $pdo;
$select = $pdo->prepare("SELECT * FROM themes");
$select->execute();
while ($row = $select->fetch(PDO::FETCH_ASSOC))
{
echo $select['theme_name'].'<br />';
}
}
Getting this error:
Fatal error: Cannot use object of type PDOStatement as array in C:\xampp\htdocs\driptone\inc\functions.inc.php on line 137
Line 137:
echo $select['theme_name'].'<br />';
What is the problem?
Thanks.
You're using $select instead of $row inside loop.
while ($row = $select->fetch(PDO::FETCH_ASSOC)) {
echo $row['theme_name'].'<br />';
}
use $row, except $select
echo $row['theme_name'].'<br />';
You assigned it to $row but you're calling $select.
Should be:
while ($row = $select->fetch(PDO::FETCH_ASSOC))
{
echo $row['theme_name'].'<br />';
}