PHP - Define Variable In Form.
Hi , how I can save something into form?
I mean , insert something in variable and than insert it into value in the form so when i send the form the value will be send too. I also want that it will be can not change. for example : <input name="email" value="a@s.d"/> but this example can be change if you insert something else. thanks , Mor. Similar TutorialsAs you can see here I have the following code Code: [Select] <?php session_start(); session_register('hazard2'); //INITIALIZE ERROR VARIABLES $errorFound = false; $errorIcon['hazard2'] = ''; if (isset($_POST['submitbutton'])) { //SET SESSION VARIABLES $_SESSION['hazard2'] = $_POST['hazard2']; //TEST FORM INFORMATION if(count($_POST['hazard2']) != 3) { $errorFound = true; $errorIcon['hazard2'] = 'Error Question 2'; } //IF NO ERRORS WERE FOUND, CONTINUE PROCESSING if (!$errorFound) { header( "Location: hazardresult.php" ); } } ?> It's lazy I know, but the script is on a file called hazard2.php, is there anyway to have all of the hazard2's in the code come from the file name. So when I make hazard3, I don't have to change all the hazard2's to hazard3's Thank you I have 2 file names, which are uploaded, stored in the variable $files. I want to be able to assign a variable to each file name. What's the best way of doing it?? I want to be able to insert each file into a mysql database on the same line but in different fields. Here is a sample part of my code: Code: [Select] var_dump($files); print_r(array_slice(array($files),0)); //I want to split this into 2 variables. One for each file name??????? list($file1)=$files; //insert the values/filenames into mysql fields "itm_pic_name & itm_pic_name2" $mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME); $this->execSQL("INSERT INTO itm_pic_detail(itm_pic_name,itm_pic_name2,itm_pic_type, itm_pic_size) VALUES (?,?,?,?)", array('ssss',$file1,$file1,$type, $size),true); I would really like some input. : what I am trying to accomplish is for the user to select the state they wish, hit submit. At this point another form should show asking which county based on the state they picked, then hit search. At this point, I'm having an issue having the state variable being passed to the 2nd form also having the state they selected stay selected. <?php $default = "Step 1. Pick Your State"; $select = "<option name='statebox'>$default</option>"; echo "<br/><form method='POST' action=".$_SERVER['PHP_SELF']." >"; echo "<select name='search'>"; echo "$select"; /////////////////////////////////////////////////////////////// //Connect to the database include_once 'phpforms/connect.php'; $sql = mysql_query("SELECT * FROM states"); while($row = mysql_fetch_array($sql)){ $state = $row['states']; echo "<option name='statebox'>$state</option>"; }//End While /////////////////////////////////////////////////////////////// echo "</select>"; echo "<input align='left' type='submit' name='stateboxbutton' value='Ok'> "; echo "</form>"; echo "</td>"; echo "<td>"; if(isset($_POST['stateboxbutton'])){ $statesearch = $_POST['statebox']; $selected = $_POST['statebox']; $select = "<option name='statebox'>$selected</option>"; echo "<br/><form action='../search-results.php' method='POST'>"; echo "<select name='search'>"; echo "<option name='default'>Step 2. Pick Your County</option>"; /////////////////////////////////////////////////////////////// //Connect to the database include_once 'phpforms/connect.php'; $sql = mysql_query("SELECT * FROM counties WHERE state LIKE '$statesearch'"); while($row = mysql_fetch_array($sql)){ $co = $row['counties']; echo "<option name='county'>$co</option>"; }//End While /////////////////////////////////////////////////////////////// echo "</select>"; echo "<input align='left' type='submit' name='button' value='Search'> "; echo "</form>"; }else{ }//End Else ?> Hi, I have an html form in "send.htm" that sends data to "retrieve.php" with the following structu send.htm: Code: [Select] <html> <body> <form method="post" action="retrieve.php" <select id='select' name='select' > <option>option1</option> <option>option2</option> <option>option3</option> <option>etc...</option> </select> <input type="submit"> </form> </body> </html> retrieve.php: Code: [Select] <?php $selectedoption = $_POST['select']; print" <html> <body> <select id='select' name='select' > <option>option1</option> <option>option2</option> <option>option3</option> <option>etc...</option> </select> </body> </html> "; ?> How do I specify that the select menu in retrieve.php should have the option selected that was chosen from the select menu in send.htm? I'm guessing this is probably quite straightforward, but I can't quite work it out. Please help! Thanks. Been looking to see if anyone has published something like this. I have a number of projects coming up which entail creating input form pages using PHP. Some of these are quite large as to the number of entries, pages etc.. and the worst part is that I know in advance that they most likely will want to change/add to the form after I am done. So rather than coding them physically in the code, I want to define the form elements in an array that I can store in a database/flat file and when the page loads, read from the array to construct the form output. I don't have any issues with dealing with the database or even using arrays, but I have not been able to come up with an array setup that works. Has anyone done this and would care to share the structure they used. Everything that I find on the net is basically sites that want to host the form, but this will be in a non-Internet accessible site so that is not an option. In many cases, variable have to be explicitly defined for whatever reason. However, often it is not required for a simple web page script. Yet, even in those cases, if a variable is NOT explicitly defined, the web server error log (example: my_domain.com-error_log) will rack up a lot of entries such as this: Quote [Fri Dec 31 01:31:43 2010] [error] [client 123.123.123.123] PHP Notice: Undefined variable: some_variable_name in /home/my_domain/public_html/some_page.php on line 6 A busy site could result in large error logs... What is considered "best practice"? Should all variables always be explicitly defined with the var key word? Hi all, I was reading a bit in the manual about the defined function. Since i have seen it being used quite a lot to disallow direct access. But one of the comments made me think if there are any alternatives to get the same. it's this comment: http://www.php.net/manual/en/function.defined.php#89886 If i read it correct it tells that defined() seems to be pretty slow. I was thinking, if that is the case what are the alternatives... Does anyone know how to interpret this comment and if there are alternatives? I am not yet a guru tofully understand the results. cheers! I have at the very top of my web page the following. Not inside any function in case that would have a scope issue. Define ('GROUP', '1'); Define ('ROUNDOF16', '2'); Define ('QUARTERFINAL', '3'); Define ('SEMIFINAL', '4'); Define ('FINAL', '5'); Lower down I have if($Round == 5) This works but this if($Round == FINAL) has error Parse error: syntax error, unexpected T_FINAL in ....... I thought this was correct ! im having a problem getting this code to work...i know it may not make sence why i would do this but it is for a larger script...is there any reason why it wont echo please? define ('TEST_VAR', 'hello'); $var = "TEST"; echo {$var}_VAR; Ive got a simple function that's counting percentages of the results, and what I want is when the first line does $variable / 100 - to go on 2 decimals(ex. 0.72142141 what I want is to write 0.72). Code: [Select] function postotak(){ $p = $bodovi / 100; $postotak = $p * 100; im doing it wrong can some one help me ? , thanks { Code: [Select] define('userlevel'( 9="admin" , 1="guest"));} Imagine a site programmed using full OOP. Where would you store information like this: $companyName = "ABC Ltd"; $companyPhone = "02476 999 999"; $companyAddress etc... Would you just define them in the public scope? (and use global or pass them in when needed??) Is there a better way? They will be needed in more places than just a navigation bar and would be needed by more than one class. i tried googling but didnt really know how to "google it" as i cant think of a short phrase that best describes it.. but i want to chance the database setting of "localhost" in my php script to another websites database how do i acheive this? Hi, I have the define(); function where i need to put the variable for directory name which is relative ... How to do that ... Code: [Select] <?php if (TARGET_PLATFORM == FILE_SYSTEM_PLATFORM) { /** * if FILE_SYSTEM_PLATFORM is selected as TARGET_PLATFORM, * then assign root folder adress to FILE_ROOT macro */ define("FILE_ROOT", "$diro"); } public function __construct($fileRoot) { if (is_dir($fileRoot)) { $this->fileRoot = $fileRoot; //if ($this->fileRoot[strlen($this->fileRoot) - 1] != '/' ) { // $this->fileRoot .= '/'; //} } else { die($fileRoot .' is not a directory '); } } ?> When i go with this, it says this: " 'dir name ' is not a directory". But I need the variable for this to work as I want to. Does anyone have an idea? To make it clear, this is only the small part of code, which is a part of the directory root for the directory tree. My goal was to create a constant that could be included on the pages, that no matter where it was located in the structure, would be able to find the template files, css, images, etc. using the following code: Code: [Select] if($_SERVER['HTTP_HOST'] == "localhost"){ define('SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('SITEPATH', $_SERVER['DOCUMENT_ROOT']); define('CSS', $_SERVER['DOCUMENT_ROOT'] . '/css/'); define('IMAGES', $_SERVER['DOCUMENT_ROOT'] . '/images/'); } else{ define('SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('SITEPATH', $_SERVER['DOCUMENT_ROOT']); define('TEMPLATE', $_SERVER['DOCUMENT_ROOT'] . '/incs/template/'); define('CSS', $_SERVER['DOCUMENT_ROOT'] . '/css/'); define('IMAGES', $_SERVER['DOCUMENT_ROOT'] . '/images/'); } I put the above in a variables.php file that is in the includes folder (named incs) and I call it using the typical include statement. The problem is that when I use the constant to grab the CSS file, its not working when using: Code: [Select] <link rel="stylesheet" href="<?php echo CSS . "template.css" ?>" type="text/css" media="screen" /> I can view the page source and it has the path right, but I cannot figure out how to get it to actually pull in the css file. I know the echo command is not correct, at least I dont think it is, but have not been able to figure out any other way. Also, is there a better way to define the constants to the file locations and have it automatically detect whether its on the test server or production and then be able to reference those locations no matter where it is in the structure? How come I cannot do this? define('IMG_EXT', array("jpg", "jpeg", "png", "gif", "bmp", "tif"), true); I am trying to use absolute path across my project excluding the domain as of now and I am trying to do it as follows: Code: [Select] define('root', '/php_projects/myproject/'); // The Standard Data $path = "path.php"; $connectvars = "connectvars.php"; // The CSS Styles $reset_css = root . "view/reset.css"; $style_css = root . "view/style.css"; This works so far, the only problem I am having is that it is producing a notice. And my question is, how can I get rid of the notice? The notice is this one: Code: [Select] Notice: Constant root already defined in C:\xampp\htdocs\php_projects\myproject\path.php on line 3 Why does the notice get produced in first place? I never defined it twice, as it states. I would like to know how to use an underscore in a define function like this example below. Code: [Select] /** The name of the database for WordPress */ define('DB_NAME', 'Database_name'); /** MySQL database username */ define('DB_USER', 'User_name'); /** MySQL database password */ define('DB_PASSWORD', 'password_here'); /** MySQL hostname */ define('DB_HOST', 'Dtabase_host'); Any help appreciated and thanks in advance. <HTML> <?php $arr = array("sue" => "betsy", "frank" => "marge"); ?> </HTML> This produces the following HTML page: "betsy", "frank" => "marge"); Its like when I use the => to make my associative array, the code thinks I'm closing the php codeblock and then just prints the rest of it to the screen... I'm being told I have an undefined variable. Similar to sumUsagekWH (in the code below) there are other placeholders called sumUsageKHW, sumUsageWKWp, sumUsageWKWi and so on. Each script of code looks similar to below where the 'totalUsage' is added into sumUsageKHW, sumUsageKHE and so on. All references are highlighted red below to make it easier to follow.
So, if I am only using these sumUsagesXXXX's as placeholders for the following post....
<input name="electric_charge_total" type="hidden" id="electric_charge_total" value="<?php echo number_format($basic_charge + ($sumUsageKWH * $energy_charge) + ($sumUsageWKWp * $peak_rate) + ($sumUsageWKWi * $intermediate_rate) + ( ($sumUsageWKW+$sumUsageWEW) * $base_rate),"2"); ?>" align="right"/>
how to I define them in PHP?
Based on the code below, they are only used as a way to introduce totalUsage ( it looks silly the way it was done, but later the code will be expanded so it makes sense). What I mean is that totalUsage is being entered (in the below case) into sumUsageKWH from the $sumUsageKWH += $row[totalUsage]
Notice: Undefined variable: sumUsageKWH in C:\xampp1\htdocs\Utrack\invoice.php on line 73
<?php $sql = ";WITH TOTAL_KWH_WINTER AS ( SELECT CONVERT(VARCHAR(10),cdate,111)AS trans_date, datepart(hh, cdate) as trans_hour, comm_id, MIN((total_energy_a+total_energy_b+total_energy_c)/100) AS minUsage, MAX((total_energy_a+total_energy_b+total_energy_c)/100) AS maxUsage, meter_multiplier FROM [radiogates].[dbo].[purge_data] LEFT OUTER JOIN [radiogates].[dbo].[ops_invoice] on [radiogates].[dbo].[purge_data].[comm_id] = [radiogates].[dbo].[ops_invoice].[meter_id] where comm_id='$comm_id'and meter_multiplier is not null group by comm_id, CONVERT(VARCHAR(10),cdate,111), datepart(hh, cdate), meter_multiplier ) SELECT *, datepart(weekday, trans_date) as trans_date_day, datepart(month, trans_date) as trans_date_month, ((maxUsage - minUsage)*meter_multiplier) as totalUsage FROM TOTAL_KWH_WINTER where datepart(weekday, trans_date) IN ('1', '2', '3', '4', '5', '6', '7') AND DATEPART(MONTH, trans_date) IN ('10','11','12','1','2','3','4') and trans_date BETWEEN '$startdate2 00:00:01' AND '$enddate2 24:00:00' "; $query = sqlsrv_query($conn, $sql); if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)) { $sumUsageKWH += $row[totalUsage];}sqlsrv_free_stmt($query);?> |