Adding echo row inside of include statement - php

Can I pull data from mySQL into include statement so it will open whatever URL I place into field "theme"
<?php include("<? echo $rows['theme']; ?>"); ?>
I want to add this to index.php and I have a editable form where I can add any URL to field theme. Can someone help me get this to work?

<?php
// here you are already inside the php tags so you don't need any others
include($rows['theme']); // you don't need to echo anything just pass the value
?>
However i would recommend you use a switch statement to check the value on $rows['theme']

Simple:
<?php include($rows['theme']); ?>

You can:
<?php
$theme = $rows['theme'].".php";
include($theme);
?>
But you should validate input if it's coming from user.

Related

How to show a link if user_id =1 in HTML with PHP

I am new and learning PHP and HTML. I have one user table where I am displaying data. I want to show Delete button if user_id = 1. else I want to hide it. My current link code is like below
delete
I have done PHP code for doing achieve my above description
<?php
if ($row['user_id']==1){
echo //// I want a link here
}
?>
But since my link have also used some PHP codes, I am confused and not able to properly echo button. I am trying from an hour and not able to fix it. Let me know if someone can help me for do it.
Thanks!
I think you want to add variables in string:
<?php
if ($row['user_id']==1){
echo 'delete';
}
?>
Use . to combine strings & variables:
'string'.$var
Read about string concatenation in PHP.
Here is a possible solution for your problem:
<?php
if ($row['user_id'] === 1) {
echo ''.$row['username'].'';
}
here an an example...
<?php if ($row['user_id']==1){ ?>
delete
<?php } ?>
you can put html code in echo like this
echo "<tag name></tag name>"

how to display data from database using yii framework

I'm new to yii..I created one form that contains name,password and role.
I want to display all three data in view page.I'm using encode method but it display only one field.can anyone helpme..
<?php echo CHtml::encode($data->fieldname); ?>
it display one field name but I want to display all three..
Help me...
You need to write above code for each field separately:
<?php echo CHtml::encode($data->fieldname); ?>
<?php echo CHtml::encode($data->fieldpassword); ?>
<?php echo CHtml::encode($data->fieldrole); ?>
Note that, I suppose your fields are fieldpassword and fieldrole.
Update:
This is not possible to write only one command. All these 3 commands is required. But if you mean number of lines, you can do this:
<?php echo CHtml::encode($data->fieldname)."-". CHtml::encode($data->fieldpassword)."-".CHtml::encode($data->fieldrole);

Drupal 7 entityforms module: How to get value of a field with php?

I am using the entityform module to capture some user submitted data http://drupal.org/project/entityform
I need to pull in some of the entity field values into one of my templates. I was trying to do this with some code that works for regular node fields..
<?php echo $node->field_title[$node->language]['value']; ?>
I've tried..
<?php echo $entity->field_title[$node->language]['value']; ?>
But that doesn't work. Anyone have any ideas on how I can accomplish this?
<?php
$field_data = field_get_items('entityform',$entityform,'field_title');
echo render(field_view_value('entityform',$entityform,'field_title',$field_data));
?>
field_get_items documentation , field_view_value documentation
If you know the entityform_id of a submission, you can load it like this:
entity_load('entityform', $entityform_id);

how to pass a php values to javascript?

here is the code??
posting code:
$.post('get.php',{selected:"aaaa"},function(return){alert(return);});
when i check the values of "selected" value using
<?php
$r=$_POST['selected'];
echo $r;
?>
is displays the value "aaaa" correctly..
this code works fine...
<?php
$r=$_POST['selected'];
?>
var answer="<?php echo "welcome" ?>";
when we echo the value"welcome" it is stored in the variable answer.and i could print that...
but when i put like this....
<?php
$r=$_POST['selected'];
?>
var answer="<?php echo $r ?>";
an empty value is stored in answer... and nothing gets displayed....
whether specifying $r inside " " is not right... how to specify that......
Assuming that the php code you are showing, is located in get.php, there is no use of using javascript in that same file. If you want to get the returned value in a javascript variable in your page, you need to use the first php snippet and use the return value in your .post function:
javascript in original page:
$.post('get.php',{selected:"aaaa"},function(data){
var answer = data;
});
get.php
<?php
$r=$_POST['selected'];
echo $r;
?>
$_POST['selected'] is probably empty to start with. Make sure you're sending a nonempty value for selected, and that you're using POST. (The easiest way is to look in your browser's developer tools for the initial request).
Note that directly outputting user input into the page introduces a Cross-Site Scripting Vulnerability: The input "; alert("evil"); can show that. Assuming you're using UTF-8 all around, you can write:
var answer = <?php echo json_encode($_POST['selected']); ?>
Also, there are often better ways to transfer data from php to JavaScript, including XHR requests/JSON or data-* attributes.

Echo a PHP Session

I have a form that is supposed to store some of its data into a session. For the purpose of this example.
This information is then collected on another page.
<?php
session_start();
print_r($_SESSION['booking-form']); ########### for debugging purposes ###########
if ($_SESSION['booking-form']) {
echo $_POST['GT_title']
?>
<!DOCTYPE html>
<html>
<?php
}
elseif ($_SESSION['booking-form']) {
}?>
</html>
Now although the debug is working the echo is not working ie. echo S_POST['GT_title'].
How do I echo the information on the second page.
Can I echo it wherever I want it in the html (ie. in the middle of the body somewhere with
On the first page some data in the form can be changed with options. This would need to update the session before the page is changed.
CLARIFICATION
For the purpose of a booking form. The user filled in a series of options that were then echo'd on the next page. At this point they need to log in so the form data must enter into a session. The session data should then be returned on a third page.
1) what information? $_POST['GT_title'] would refer to a form element, presumably on the previous page. Does it exist? Is it filled in? what are you expecting?
2) You can echo where ever you like.
3) clarify? you can update a session with post values easily.
$_SESSION['foo'] = $_POST['bar']
your question isn't really that clear.
You can echo it wherever you want but if it doesn't exist or doesn't have a value then it might appear to be not working. To know for sure use var_dump($_POST['GT_title']);
For your echo question: Are you sure that GT_title is set? Posting the form on your previous page might help.
You can echo wherever you want, you can just put
<?=$varname?>
anywhere in your html.
You can also update your session wherever you want.
$_SESSION['abc'] = value;
echo '<pre>';
print_r($_POST);
echo '</pre>';
Print it after your header.
I hope this helps a little :)

Categories