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): -
....
-
<FORM METHOD="POST" ACTION="edit_ir.php">
-
<h3>Enter the Incident ID for the Report You Need to Edit:</h3>
-
<table border="0" cellpadding="0">
-
<tr>
-
<td><INPUT TYPE=TEXT NAME="incident_id" VALUE="" SIZE=6 MAXLENGTH=6></td>
-
<td><INPUT TYPE=SUBMIT VALUE="Edit"></td>
-
<td><INPUT TYPE=RESET VALUE="Reset"></td>
-
</tr>
-
</table>
-
</FORM>
-
....
-
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): -
...
-
<?php
-
$db = mysql_connect("localhost", "root", "no2nt"); mysql_select_db("etest",$db);
-
$result = mysql_query("SELECT * FROM jos_incidents_combined WHERE incident_id = '$_REQUEST[incident_id]'",$db);
-
while ($myrow = mysql_fetch_array($result))
-
{
-
echo $myrow["incident_id"];
-
...
-
<FORM NAME = "rm_edit_ir" METHOD="POST" ACTION="ir_updated.php">
-
...
-
<INPUT TYPE=HIDDEN NAME="incident_id" VALUE="<?php echo $_REQUEST[incident_id]; ?>">
-
<INPUT TYPE=SUBMIT VALUE="Submit Form" >
-
-
<INPUT TYPE=RESET VALUE="Reset Form">
-
</FORM>
-
...
-
ir_updated.php (updates the db with the data from above code): -
...
-
$sql = "UPDATE jos_incidents_combined SET
-
assess_ortho = '$_REQUEST[assess_ortho]',
-
rescore_morse = '$_REQUEST[rescore_morse]'
-
WHERE incident_id = '$_REQUEST[incident_id]'";
-
...
-
-
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: -
<INPUT TYPE=HIDDEN NAME="incident_id" VALUE="<?php echo $_REQUEST[incident_id]; ?>">
-
Should I be passing something else instead of ="<?php echo $_REQUEST[incident_id]; ?>, or am I not referring to the variable properly?
TIA,
jej1216
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]): -
<?php echo $_REQUEST['incident_id']; ?>
-
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]): -
<?php echo $_REQUEST['incident_id']; ?>
-
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????
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: -
define('incident_id', 5);
-
-
$array = array(
-
incident_id => 10,
-
'incident_id' => 99
-
);
-
-
print($array[incident_id] . ' / ' . $array['incident_id']);
-
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 = "";
|
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'>
|
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...
|
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;
}
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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();...
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |