473,749 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems passing a hidden variable

40 New Member
I'm pretty new to PHP and MySQL. I have managed to create a form that inserts data to MySQL and to create a form to search the DB. Now here is my problem. I am unsuccessful coding a hidden variable in an update page. Here is what I have:

search_ir.php (this page searches the DB and lists incident_id's found. User then enters the incident_id of the row to update):

Expand|Select|Wrap|Line Numbers
  1. ....
  2. <FORM METHOD="POST" ACTION="edit_ir.php">
  3. <h3>Enter the Incident ID for the Report You Need to Edit:</h3>
  4. <table border="0" cellpadding="0">
  5. <tr>
  6. <td><INPUT TYPE=TEXT NAME="incident_id" VALUE="" SIZE=6 MAXLENGTH=6></td>
  7. <td><INPUT TYPE=SUBMIT VALUE="Edit"></td>
  8. <td><INPUT TYPE=RESET VALUE="Reset"></td>
  9. </tr>
  10. </table>
  11. </FORM>
  12. ....
  13.  
edit_ir.php (this page receives the incident_id entered above and displays the data - some of the data has been completed, but other fields are inputted on this page to then update the row in the db on submit):

Expand|Select|Wrap|Line Numbers
  1. ...
  2. <?php
  3. $db = mysql_connect("localhost", "root", "no2nt"); mysql_select_db("etest",$db);
  4. $result = mysql_query("SELECT * FROM jos_incidents_combined WHERE incident_id = '$_REQUEST[incident_id]'",$db);
  5.     while ($myrow = mysql_fetch_array($result))
  6.     {
  7.     echo $myrow["incident_id"];
  8. ...
  9. <FORM NAME = "rm_edit_ir" METHOD="POST" ACTION="ir_updated.php">
  10. ...
  11. <INPUT TYPE=HIDDEN NAME="incident_id" VALUE="<?php echo $_REQUEST[incident_id]; ?>">
  12. <INPUT TYPE=SUBMIT VALUE="Submit Form" >
  13.  
  14. <INPUT TYPE=RESET VALUE="Reset Form">
  15. </FORM>
  16. ...
  17.  
ir_updated.php (updates the db with the data from above code):

Expand|Select|Wrap|Line Numbers
  1. ...
  2. $sql = "UPDATE jos_incidents_combined SET
  3.         assess_ortho        = '$_REQUEST[assess_ortho]',
  4.         rescore_morse       = '$_REQUEST[rescore_morse]'
  5.         WHERE incident_id = '$_REQUEST[incident_id]'";
  6. ...
  7.  
  8.  
In ir_updated.php, I get the error:
"Notice: Use of undefined constant incident_id - assumed \'incident_id\' in /usr/local/php_classes/edit_ir.php on line 238"

line 238 in edit_ir.php is this:
Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE=HIDDEN NAME="incident_id" VALUE="<?php echo $_REQUEST[incident_id]; ?>">
  2.  
Should I be passing something else instead of ="<?php echo $_REQUEST[incident_id]; ?>, or am I not referring to the variable properly?

TIA,

jej1216
May 31 '07 #1
4 2314
pbmods
5,821 Recognized Expert Expert
Should I be passing something else instead of ="<?php echo $_REQUEST[incident_id]; ?>, or am I not referring to the variable properly?
You're getting this notice because you didn't put 'incident_id' in quotes. When you use an unquoted string literal, PHP first checks to see if there is a constant by that name. Now granted, it's unlikely that the next version of PHP is going to have an incident_id constant, but just to be on the safe side (and to get rid of that notice, you should do this instead [note the quotes around incident_id]):

Expand|Select|Wrap|Line Numbers
  1. <?php echo $_REQUEST['incident_id']; ?>
  2.  
May 31 '07 #2
jej1216
40 New Member
You're getting this notice because you didn't put 'incident_id' in quotes. When you use an unquoted string literal, PHP first checks to see if there is a constant by that name. Now granted, it's unlikely that the next version of PHP is going to have an incident_id constant, but just to be on the safe side (and to get rid of that notice, you should do this instead [note the quotes around incident_id]):

Expand|Select|Wrap|Line Numbers
  1. <?php echo $_REQUEST['incident_id']; ?>
  2.  
Thanks! I figured it was some small but huge code error on my part!
Just so I understand your explanation, though --- by not using the single quotes I was confusing PHP? It seems from the notice I got that PHP assumed the correct value. But, the update failed until I followed your code correction. Also, once I was in ir_updated.php, the update sql had to not use the single quotes - I guess at that point it was then a constant????
May 31 '07 #3
pbmods
5,821 Recognized Expert Expert
Thanks! I figured it was some small but huge code error on my part!
Just so I understand your explanation, though --- by not using the single quotes I was confusing PHP? It seems from the notice I got that PHP assumed the correct value. But, the update failed until I followed your code correction. Also, once I was in ir_updated.php, the update sql had to not use the single quotes - I guess at that point it was then a constant????
When you used $_POST[incident_id], PHP first looked for a constant named 'incident_id'. When it didn't find that, it used the literal 'incident_id' instead.

Suppose you did this instead:

Expand|Select|Wrap|Line Numbers
  1. define('incident_id', 5);
  2.  
  3. $array = array(
  4.     incident_id => 10,
  5.     'incident_id' => 99
  6. );
  7.  
  8. print($array[incident_id] . ' / ' . $array['incident_id']);
  9.  
The above code would output "10 / 99".

Things get a little confusing when you use array keys in strings, but that's outside the scope of this post. For more information, take a look at the PHP manual.
May 31 '07 #4
jej1216
40 New Member
Thanks for the help - I really appreciate it. Hopefully, in the near future, my posts will be for more complex issues rather than for newbee mistakes.
May 31 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5942
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page contains: <?php $_SESSION = ""; $_SESSION = "";
1
7785
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION = ""; echo "<form method='POST' action='login.php'>
6
7094
by: veganeater | last post by:
Hi Everyone, I was wondering if there was a way to pass a variable to a popup window. The purpose is make it so when a user clicks on a specific region/link of the glossary page, a popup opens with the related description. This is done and is obviously not a concern. However, now I would like to make it so the corresponding row becomes highlighted (changes background colour via DOM). I imagine it can be done, but I'm at a loss for...
0
1550
by: Mirovk | last post by:
Hello Agn, 1.- Being at the a.asp I refresh the page and session variables using a JavaScript function: { simbolo = window.document.frmdir.simbolo.value; window.location.href="checkout_gastos.asp?refresh=1&bono="+bono+"&simbolo="+simbolo; }
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.