DayofYear + Curdate not working - php

I cant get the dayofyear and curdate to work.
If I remove it, the code works but I need the condition.
The error message is "Trying to get property of non-object "
<?php
$rowhtipoo=mysql_query("SELECT * FROM blog_articles WHERE bog_id=1 AND fk_publish_dato_id = DAYOFYEAR(CURDATE());") or die(mysql_error());
$rwhtip=mysql_fetch_object($rowhtipoo);
?>
<div class="tipet">
<p><span class="f vvv"><?php nl2br($rwhtip->english_navn);?></span></p>
<p><?php echo nl2br($rwhtip->english_tekst);?></p>
</div>

It sounds to me like a result isn't found and mysql_fetch_object is returning a false value. Maybe you'd have better luck doing something like the example below.
http://php.net/manual/en/function.mysql-fetch-object.php.
<?php while ( $rwhtip = mysql_fetch_array($rowhtipoo) ) { ?>
<div class="tipet">
<p>
<span class="f vvv">
<?php echo nl2br($rwhtip["english_navn"]);?></span>
</p>
<p>
<?php echo nl2br($rwhtip["english_tekst"]);?>
</p>
</div>
<?php } ?>

Why don't you let PHP take care of the date?
$rowhtipoo=mysql_query("SELECT * FROM blog_articles WHERE bog_id=1 AND fk_publish_dato_id = '" . date('Y-m-d') . "';") or die(mysql_error());
Or, it can be a typo - fk_publish_datO_id ?

Related

Get an id to another page

Hello this is my first post here, I need your help.
First of all, I want to say sorry for my bad English. I hope you will understand me :D
So, I'm a newbie in php and I have a problem.
I want to take the id from a file, to another file, but I don't know how. I will show you my code below.
while($array = $db->get_row($row))
{
$id = $array['id'];
$Nume = $array['user_name'];
$date = date("Y-m-d H:i:s", $array['date']);;
$stitle = $array['shorttext'];
$text = $array['text'];
$logs .= '
<div class="post">
<div class="post-meta clearfix">
<h4 class="post-title left">
'.$stitle.'
</h4>
<p class="post-info right">
<span>'.$Nume.'</span>
'.$date.'
</p>
</div>
<div class="post-box">
<div class="post-content">
<div class="post-intro">
'.$text.'
</div>
</div>
<div class="post-footer clearfix">
<div class="continue-reading">
</div>
</div>
</div>
</div>
<br>
';
}
Here where is ID, I want to take that id to the news page. (the code is in index.php)
'.$stitle.'
In news.php have to select from mysql all but only the table with the ID from index.php
if(isset($_GET['id']))
{
$id = (int)$_GET['id'];
$row = $db->sql("SELECT * FROM `ucp_news` WHERE `id` = '".$id."' ");
$array = $db->get_array($row);
Can you help me, please?
Your PHP code is correct, although you should be using htmlspecialchars() when adding the variables to the output. This to prevent XSS attacks, and the like.
Though, your problem lies most likely in this line:
<a href="/index.php?page=news id='.$id.'">
More specifically, the missing ampersand (&) between news and id. Try to look at the value of $_GET['page'] when clicking on the link, then you should see what the problem is.

Using if-statements in PHP to print HTML

I'm fairly new to PHP and I've been trying to construct some code to print basic HTML, however the code causes an error 500 whenever used. I am guessing it is a syntax error since I've tried the code in a couple of forms and nothing seems to work (including removing the database lookup and just trying to compare to set values to each other). The script needs to get a variable from the db, compare it to a set value and print the HTML if true, here is the code I am trying:
<?php
$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$db->setQuery('SELECT #__categories.title FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = '.$id);
$category = $db->loadResult(); ?>
<?php if strcmp($category,"Blog")==0 : ?>
<div style="display: -webkit-inline-box" class="sharelogos">
<img src="/images/sharing-icons/facebook.png" width="30px" alt="Facebook" />
</div>
<?php endif; ?>
Any help will be appreciated, thanks!
You if is incorrect, try like this
<?php if (strcmp($category,"Blog")==0) { ?>
<div style="display: -webkit-inline-box" class="sharelogos">
<img src="/images/sharing-icons/facebook.png" width="30px" alt="Facebook" />
</div>
<?php } ?>

Echoing forum Id to new page to display content?

can someone please help me i am having problems creating my forum.
At the moment users can create posts, the post title is listed down the page and then the user is suppose to be able to click the title link and be taken to read_post.php and then this should take the user to another page where the post content can be viewed, i am trying to do this by echoing the forum post id but it doesnt seem to want to work, instead i get this error:
Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
can someonee please show me where im going wrong.
here is my sql function:
function read_forum() {
global $connection;
global $forum_id;
$query = "SELECT *
FROM ptb_forum, ptb_profiles
WHERE ptb_forum.id = $forum_id ";
$forum_set = mysql_query($query, $connection);
confirm_query($forum_set);
return $forum_set;
}
here is the link code that takes the user to read_post.php which suppose to echo the forum id and display the content for each individual post.
<?
$forum_set = get_forum();
while ($forum = mysql_fetch_array($forum_set)) {
?>
<div class="forumcase" id="forumcase">
<div class="pend-forum-content">
<?php echo "<strong>{$forum['title']}</strong> - Posted by {$user['first_name']}"; ?>
</div>
here's my code for read_post.php:
<?php
$page_title = "Read Post";
include('includes/header.php');
include ('includes/mod_login/login_form2.php'); ?>
<?php
confirm_logged_in();
if (isset ($_GET['frm'])) {
$forum_id = $_GET['frm'];
}
?>
<?php include('includes/copyrightbar.php'); ?>
<div class="modtitle">
<div class="modtitle-text">Messages Between <?php echo "{$forum['display_name']}"; ?> & You</div>
</div>
<div class="modcontent57">
<br /><br /><br/><br/>
<div class="forum">
<div class="forum-pic"><?php echo "<img src=\"data/photos/{$_SESSION['user_id']}/_default.jpg\" width=\"100\" height=\"100\" border=\"0\" align=\"right\" class=\"img-with-border-forum\" />";?>
</div>
<div class="message-links">
<strong><< Back to Forum
</div>
<br /><br /><br/><br/>
<?php
$datesent1 = $inbox['date_sent']; ?>
<?php
$forum_set = read_forum();
while ($forum = mysql_fetch_array($forum_set)) {
$prof_photo = "data/photos/{$message['user_id']}/_default.jpg";
$result = mysql_query("UPDATE ptb_forum SET ptb_forum.read_forum='1' WHERE ptb_forum.id='$forum_id'")
or die(mysql_error());
?>
<div class="message-date">
<?php echo "".date('D M jS, Y - g:ia', strtotime($message['date_sent'])).""; ?></div>
<div class="img-with-border-msg-read"><?php echo "<img width=\"60px\" height=\"60px\" src=\"{$prof_photo}\"><br />"; ?></div>
<div class="conversation-text">
<?php echo "<i>Conversations between you and </i>{$forum['display_name']}.<br /> "; ?></div>
<div class="message-content">
<?php echo "<strong>Message Subject: </strong><i>{$forum['subject']}</i>"; ?>
<br/>
<br/>
<br/>
<br/>
<?php echo "<strong>Message:<br/></strong></br ><i>{$forum['content']}</i>"; ?>
</div>
<div class="reply-box">
<? include ('message_reply.php'); ?>
</div>
<?php
}
?>
<br/>
<br/>
<br/>
</div>
</div>
<?php include('includes/footer.php'); ?>
</div>
You have an error in your query... Your parameter is not quoted...
$query = "SELECT *
FROM ptb_forum, ptb_profiles
WHERE ptb_forum.id = '$forum_id'";
However... I suggest that you refrain from using the mysql_ family of functions. They are deprecated and due to be removed from PHP in a future release. You should be using parameterized queries using MySQLi or PDO.
Also, global is evil. I've never had a need to use it in 10 years of PHP programming. Neither should you.

Different meaning in the mysql code?

$result=mysql_query("select * from dosyabegeni where veri_id='" . get_custom_field('dwcode') . "'");
Not Working
It says the number and the screen, but the application does not work
veri_id='" . get_custom_field('dwcode') . "'");
veri_id='" . echo get_custom_field('dwcode') . "'");
Working
veri_id='HelloTest'");
veri_id='1234567890'");
veri_id='" . $_GET['test'] . "'");
Main Codes
<?php
include('/home/emre2010/public_html/EntegreOz/DosyaBegeni/config.php');
$result=mysql_query("select * from dosyabegeni where veri_id='" .get_custom_field('dwcode') . "'");
while($row = mysql_fetch_array($result))
{
$sira_id=$row['sira_id'];
$veri_id=$row['veri_id'];
$begeni=$row['begeni'];
?>
<div class="reviewbox">
<div class="summarywrap">
<div class="summarywrapinner">
<div class="summary">
<div class="reviewsection"><div class="rating points">
<a href="#" class="begeni" id="<?php echo $sira_id; ?>">
<span style="color:#fff;" align="center"> <?php echo $begeni; ?> </span>
</a>
<p class="ratingtext">completed!</p></div>
</div><div class="clear"></div>
<div class="clear"></div>
</div>
<div class="ratingsummary"></div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
What's the problem?
Are you meaning to run the review box from within the while loop? If your SQL is only supposed to return one row, you really shouldn't have all that stuff within the while loop. I don't see an end bracket. If you are then you're doing it pretty archaically. You should put the information from the while loop into an array instead and then run a separate loop in your content, but that's not really going to solve the problem. The only issue you could have is either not returning rows because they don't exist, or an error in your SQL.
If your SQL query isn't returning any rows then you need to do two things. One, echo out the sql query. And two, print any possible errors.
echo $sql.'<br />';
print(mysql_error());
You never know, you might have misspelled a column on the table of the db itself.
If that's not working, then print the $row out.
Outside of your while loop do:
print_r($row);

MySQL select on PHP can't get it to work

I am having a problem retrieveing information from a MySQL Data Base. Could you help me out? This is the code I wrote:
<?php
$result = mysql_query("SELECT * FROM notas LIMIT 1 ORDER BY id DESC");
while($nt = mysql_fetch_array($result)) {
?>
<div class="nuevos_1">
<div class="over_descripcion">
<div class="over_title">
<h3><?php echo $nt[titulo] ?></h3>
</div>
<div class="over_autor">
<span><b>Por: </b><?php print ucwords(str_replace("-", " ", $nt[autor])); ?> <?php echo $nt[fecha] ?></span>
</div>
<div class="over_texto">
<span><b><?php echo strtoupper(str_replace("-", " ", $nt[categoria])) ?></b> <?php echo substr(strip_tags($nt[texto]), 0, 240)."..." ?></span>
</div>
<div class="over_ver_mas">
<input type="button" value="Leer más" onclick="location.href='/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>'" />
</div>
</div>
<a href="/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>">
<img src="http://<?php echo $nt[imagen] ?>" border="0" />
</a>
</div>
<?php }; ?>
Nothing inside the SELECT notas database is showing. It is simply gone...
Thanks!
Limit 1 has to go after the ORDER BY
change your query to
SELECT * FROM notas ORDER BY id DESC LIMIT 1
what does the error message say
$result = mysql_query("SELECT * FROM notas LIMIT 1 ORDER BY id DESC");
if (mysql_error()) {
die(mysql_error());
}
The other answers above have it correct - you've got a syntax error in your query. If you'd done the basic step of having:
$result = mysql_query(..) or die(mysql_error());
you'd have seen the error message. Never EVER assume that a query succeeds. Always check for error conditions.
As well, you've got a minor syntax bug in your output:
... <a href="/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>"> ...
^^^^^
Your array keys are not quoted, which means they're interpreted as define()'d constants. PHP is polite and will treat those constants as strings if there actually is not constant with that name, but it will issue a warning for every occurence. It should be:
<?php echo $nt['fecha'] ... ?>
I don't too well about PHP, but your select statement limits to just one result. You might want to change this line:
$result = mysql_query("SELECT * FROM notas LIMIT 1 ORDER BY id DESC");
You will not get more than one result as it is.

Categories