Check condition in PHP
Moderators: egami, macek, gesf
HI,
I want to check condition, the condition is like that , first i will check the condition where the table is exist in the database or not, if not it will display the error message, and if the table is exist it will display the content of the table on the page so for that i have created the script but its not working for me. its gives me me a error.
Parse error: syntax error, unexpected '>' in /var/www/html/Project/demo.php on line 62
NOTE => The created the text box on the page. and in this box user have to enter the date.
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("sample",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="sample";
if(isset($_POST['submit']))
{
$check = "SELECT * FROM $table where DATE='{$_POST["search"]}'";";
$fetch=mysql_query($check,$con);
if(!$fetch)
{
echo "<br>";
echo "No table Found In The Database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='{$_POST["search"]}'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
I want to check condition, the condition is like that , first i will check the condition where the table is exist in the database or not, if not it will display the error message, and if the table is exist it will display the content of the table on the page so for that i have created the script but its not working for me. its gives me me a error.
Parse error: syntax error, unexpected '>' in /var/www/html/Project/demo.php on line 62
NOTE => The created the text box on the page. and in this box user have to enter the date.
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("sample",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="sample";
if(isset($_POST['submit']))
{
$check = "SELECT * FROM $table where DATE='{$_POST["search"]}'";";
$fetch=mysql_query($check,$con);
if(!$fetch)
{
echo "<br>";
echo "No table Found In The Database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='{$_POST["search"]}'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
does this work? i modified a couple of lines to concatenate variables instead of having them nested the way that you did. You had an unterminated string that was causing issues.
Code: Select all
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("sample",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="sample";
if(isset($_POST['submit']))
{
$check = "SELECT * FROM $table where DATE='".$_POST["search"]."'";
$fetch=mysql_query($check,$con);
if(!$fetch)
{
echo "<br>";
echo "No table Found In The Database";
echo "<br>";
} else {
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
Thanks For your reply, now i can load my php page without any issues, But still condition is not executing successfully, i did all efforts but not luck. My else part is not executing even i enter the correct date for table name.
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("sample",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="sample";
if(isset($_POST['submit']))
{
$selectcondition = "SELECT * FROM baltimore where DATE='".$date."'"; //Select Query Which fetch the DATE
$check=mysql_query($selectcondition,$con);
$fetch=mysql_fetch_row($check);
if($fetch==0)
{
echo "<br>";
echo "No Table found in the database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
I did some modification in my if and else part, but not luck.
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("sample",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="sample";
if(isset($_POST['submit']))
{
$selectcondition = "SELECT * FROM baltimore where DATE='".$date."'"; //Select Query Which fetch the DATE
$check=mysql_query($selectcondition,$con);
$fetch=mysql_fetch_row($check);
if($fetch==0)
{
echo "<br>";
echo "No Table found in the database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
I did some modification in my if and else part, but not luck.
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
try removing the single quotes around the date, and echo out your query string to verify it's what you think it is. also make sure the date format you're using is the same as the date format on the field you're comparing it to.
Hi seandisanti,
first of all Sorrry to reply you too late, i tried removing a single quote from my select query, but still the situation is same, and i didn't understand "echo out your string", means
$selectcondition = "SELECT DATE FROM baltimore where DATE=".$date."";
Please reply me on this, Any help is appriciate.
Thanks
Ashish Sood
first of all Sorrry to reply you too late, i tried removing a single quote from my select query, but still the situation is same, and i didn't understand "echo out your string", means
$selectcondition = "SELECT DATE FROM baltimore where DATE=".$date."";
Please reply me on this, Any help is appriciate.
Thanks
Ashish Sood
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
please post your current code and the error that you get
I didnt get any error, the problem is this whenever i enter correct date it is not display the content of my table means it not goes into my else part. and i checked twice the format of the date is am using is similar.seandisanti wrote:please post your current code and the error that you get
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("sample",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="sample";
if(isset($_POST['submit']))
{
$selectcondition = "SELECT DATE FROM baltimore where DATE=".$date.""; //Select Query Which fetch the DATE
$check=mysql_query($selectcondition,$con);
$fetch=mysql_fetch_row($check);
if(!$fetch)
{
echo "<br>";
echo "No Table found in the database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
try this.
all i added was this section to output your query. make sure to look at the date being spit out as part of your query and the values in the corresponding field in the database. that's usually where problems come up.
Code: Select all
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("sample",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="sample";
if(isset($_POST['submit']))
{
$selectcondition = "SELECT DATE FROM baltimore where DATE=".$date; //Select Query Which fetch the DATE
$check=mysql_query($selectcondition,$con);
$check_output=mysql_error();
$fetch=mysql_fetch_row($check);
die('the query you are trying to run is <br />'. $selectcondition .'<br /> and the response from the server is <br />'.$check_output);
if(!$fetch)
{
echo "<br>";
echo "No Table found in the database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
Code: Select all
$selectcondition = "SELECT DATE FROM baltimore where DATE=".$date; //Select Query Which fetch the DATE
$check=mysql_query($selectcondition,$con);
$check_output=mysql_error();
$fetch=mysql_fetch_row($check);
die('the query you are trying to run is <br />'. $selectcondition .'<br /> and the response from the server is <br />'.$check_output);
Thanks for your quick response, I tried your code , but after entering the correct date format. its showing the die part.
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("baltimore",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="baltimore";
if(isset($_POST['submit']))
{
$selectcondition = "SELECT DATE FROM baltimore where DATE=".$date; //Select Query Which fetch the DATE
$check=mysql_query($selectcondition,$con);
$check_output=mysql_error();
$fetch=mysql_fetch_row($check);
die('the query you are trying to run is <br />'. $selectcondition .'<br /> and the response from the server is <br />'.$check_output);
if(!$fetch)
{
echo "<br>";
echo "No Table found in the database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
<?php
date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Today Date Is = ";
echo "$date";
$con = mysql_connect("localhost","root","access");
if(!$con)
{
die("Unable Connect To Database Server " .mysql_error());
}
$selectdb=mysql_select_db("baltimore",$con);
if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}
$table="baltimore";
if(isset($_POST['submit']))
{
$selectcondition = "SELECT DATE FROM baltimore where DATE=".$date; //Select Query Which fetch the DATE
$check=mysql_query($selectcondition,$con);
$check_output=mysql_error();
$fetch=mysql_fetch_row($check);
die('the query you are trying to run is <br />'. $selectcondition .'<br /> and the response from the server is <br />'.$check_output);
if(!$fetch)
{
echo "<br>";
echo "No Table found in the database";
echo "<br>";
}
else
{
$sql= "select DATE,JOBNAME,TIME,INITIALS,TIMESTAMP from $table where DATE='".$_POST['search']."'";
$mydata=mysql_query($sql,$con);
echo "<table width=100% height=10% border=1>
<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>TIME</th>
<th>INITIALS</th>
<th>System TIMESTAMP</th>
</tr>";
while($records = mysql_fetch_array($mydata))
{
echo "<tr>";
echo "<td>" . $records['DATE'] . " </td>";
echo "<td>" . $records['JOBNAME']. " </td>";
echo "<td>" . $records['TIME'] . " </td>";
echo "<td>" . $records['INITIALS'] . " </td>";
echo "<td>" . $records['TIMESTAMP'] . " </td>";
}
echo "<br>";
}
echo "</table>";
}
?>
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
Yes, that was put in to stop processing as soon as the query was generated so the page wouldn't change after echo etc. Go ahead and remove the die line and you should be all set once your query is good
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
can you please post what the output of the die part is?
Try looking at:
DATE_FORMAT: http://dev.mysql.com/doc/refman/5.5/en/ ... ate-format
Or try converting the date into a UNIX timestamp. They're easier to store and manipulate in PHP.
$date = mktime ( 0, 0, 0, $m, $d, $y );
http://php.net/manual/en/function.mktime.php
DATE_FORMAT: http://dev.mysql.com/doc/refman/5.5/en/ ... ate-format
Or try converting the date into a UNIX timestamp. They're easier to store and manipulate in PHP.
$date = mktime ( 0, 0, 0, $m, $d, $y );
http://php.net/manual/en/function.mktime.php
The basic one.
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
{
echo "Have a nice weekend!";
}
else
{
echo "Have a nice day!";
}
?>
</body>
Thanks,
hire php developer | hire magento developer
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
{
echo "Have a nice weekend!";
}
else
{
echo "Have a nice day!";
}
?>
</body>
Thanks,
hire php developer | hire magento developer