Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Check condition in PHP

General discussions related to php

Moderators: macek, egami, gesf

Check condition in PHP

Postby Gamers » Tue Oct 09, 2012 2:37 am

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'] . "&nbsp;</td>";
echo "<td>" . $records['JOBNAME']. "&nbsp;</td>";
echo "<td>" . $records['TIME'] . "&nbsp;</td>";
echo "<td>" . $records['INITIALS'] . "&nbsp;</td>";
echo "<td>" . $records['TIMESTAMP'] . "&nbsp;</td>";

}
echo "<br>";
}
echo "</table>";
}
?>
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Check condition in PHP

Postby seandisanti » Tue Oct 09, 2012 8:10 am

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'] . "&nbsp;</td>";
            echo "<td>" . $records['JOBNAME']. "&nbsp;</td>";
            echo "<td>" . $records['TIME'] . "&nbsp;</td>";
            echo "<td>" . $records['INITIALS'] . "&nbsp;</td>";
            echo "<td>" . $records['TIMESTAMP'] . "&nbsp;</td>";
         }
         echo "<br>";
      }
      echo "</table>";
   }
?>
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: Check condition in PHP

Postby Gamers » Tue Oct 09, 2012 11:49 pm

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'] . "&nbsp;</td>";
echo "<td>" . $records['JOBNAME']. "&nbsp;</td>";
echo "<td>" . $records['TIME'] . "&nbsp;</td>";
echo "<td>" . $records['INITIALS'] . "&nbsp;</td>";
echo "<td>" . $records['TIMESTAMP'] . "&nbsp;</td>";
}

echo "<br>";
}
echo "</table>";
}
?>


I did some modification in my if and else part, but not luck.
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Check condition in PHP

Postby seandisanti » Wed Oct 10, 2012 9:00 am

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.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: Check condition in PHP

Postby Gamers » Fri Oct 12, 2012 8:31 am

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
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Check condition in PHP

Postby seandisanti » Fri Oct 12, 2012 9:19 am

please post your current code and the error that you get
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: Check condition in PHP

Postby Gamers » Fri Oct 12, 2012 9:25 am

seandisanti wrote: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.

<?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'] . "&nbsp;</td>";
echo "<td>" . $records['JOBNAME']. "&nbsp;</td>";
echo "<td>" . $records['TIME'] . "&nbsp;</td>";
echo "<td>" . $records['INITIALS'] . "&nbsp;</td>";
echo "<td>" . $records['TIMESTAMP'] . "&nbsp;</td>";
}

echo "<br>";
}
echo "</table>";
}
?>
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Check condition in PHP

Postby seandisanti » Fri Oct 12, 2012 9:42 am

try this.

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'] . "&nbsp;</td>";
echo "<td>" . $records['JOBNAME']. "&nbsp;</td>";
echo "<td>" . $records['TIME'] . "&nbsp;</td>";
echo "<td>" . $records['INITIALS'] . "&nbsp;</td>";
echo "<td>" . $records['TIMESTAMP'] . "&nbsp;</td>";
}

echo "<br>";
}
echo "</table>";
}
?>


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
$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);
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: Check condition in PHP

Postby Gamers » Fri Oct 12, 2012 9:54 am

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'] . "&nbsp;</td>";
echo "<td>" . $records['JOBNAME']. "&nbsp;</td>";
echo "<td>" . $records['TIME'] . "&nbsp;</td>";
echo "<td>" . $records['INITIALS'] . "&nbsp;</td>";
echo "<td>" . $records['TIMESTAMP'] . "&nbsp;</td>";
}

echo "<br>";
}
echo "</table>";
}
?>
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Check condition in PHP

Postby seandisanti » Fri Oct 12, 2012 10:36 am

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
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: Check condition in PHP

Postby Gamers » Fri Oct 12, 2012 6:28 pm

@seandisanti
I also tried removing the die part but it still not executing the else part. Now Please guide me what else I can do.
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Check condition in PHP

Postby seandisanti » Mon Oct 15, 2012 7:38 am

can you please post what the output of the die part is?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: Check condition in PHP

Postby MeroD » Tue Oct 16, 2012 4:18 am

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
MeroD
New php-forum User
New php-forum User
 
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: Check condition in PHP

Postby Gamers » Wed Oct 17, 2012 8:55 am

My script is working now, thank all for supporting me :)
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Check condition in PHP

Postby jinijames » Thu Oct 25, 2012 4:37 am

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
jinijames
New php-forum User
New php-forum User
 
Posts: 20
Joined: Fri Oct 19, 2012 4:32 am
Location: India


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.