0

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

Edited by Acids: n/a

4
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by ko ko
0

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.

0

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?

0

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?

0

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.

0

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

0

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'];
0

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?

Edited by Acids: wrong code copied.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.