I am a total noob at php and I am creating a basic wordpress plugin for a site.
I have a function

function My_Function_2() {
?>

Then I have an input inside a div coming from an options page:

<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
Define Box height
<table width="350">
<tr valign="top">
<th width="200" scope="row">Enter Box Height</th>
<td width="50">
<input name="Box_height" type="text" id="Box_height"
value="<?php echo get_option('Box_height'); ?>" />
(ex. 400)</td>
</tr>
</table>

But when I try to $box_height to use in a url later on, it doesnt work.
If I set box_height to a value using an array it works. So I think I need to make the input variable into a Global Variable somehow?
Sorry if I havent made this very clear, im not very well experienced

Recommended Answers

All 9 Replies

I am a total noob at php and I am creating a basic wordpress plugin for a site.
I have a function

function My_Function_2() {
?>

Then I have an input inside a div coming from an options page:

<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
Define Box height
<table width="350">
<tr valign="top">
<th width="200" scope="row">Enter Box Height</th>
<td width="50">
<input name="Box_height" type="text" id="Box_height"
value="<?php echo get_option('Box_height'); ?>" />
(ex. 400)</td>
</tr>
</table>

But when I try to $box_height to use in a url later on, it doesnt work.
If I set box_height to a value using an array it works. So I think I need to make the input variable into a Global Variable somehow?
Sorry if I havent made this very clear, im not very well experienced

Where did you put the variable? Session? Cookie? Database? If you don't put the variable somewhere, the only page that can use it is the page that your form posted it to.

Thanks for your reply.

Wordpress stores the value in a database. I have a database field in the coding too. So if I put in a value and save it. I can come back the the page later and the value will still be there. It doesnt use cookies.
Are variables in functions global by default or do I have to set them that way?

use a seesion or cookie to do this.....

But The settings for the height are to be done by an admin as they are settings for a plugins size. Cookies an sessions are for users only right?

Did you grab the variable from the database first? You need to ask the database for the data before you can use it. You have to grab it for every page that wants to use the variable.

ahh ok. Is there anyway that I can do this with a very short amount of code? Because I will be calling many variables from the database.
Thank you

ahh ok. Is there anyway that I can do this with a very short amount of code? Because I will be calling many variables from the database.
Thank you

That depends on your database. A few lines will usually do the trick.

// open mysql connection

$row = mysql_fetch_array(mysql_query('SELECT column FROM table'));
$column = $row['column'];

Thanks alot..
But I have messed something up and the Database I thought was created isnt actually there.
I used the code

<?php
/* Runs when plugin is activated */
register_activation_hook(__FILE__,'hello_world_install'); 

function hello_world_install() {
/* Creates new database field */
add_option("hello_world_data", 'Default', '', 'yes');
}


?>

Mine just isnt called hello world. Am I supposed to use this code as it is? Or am I supposed to remove the first section?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.