ERROR :- Undefined variable: raw While Transfering data between 2 pages [duplicate]
This question already has an answer here:
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
27 answers
manageleavetype.php
Below code is my first file page I want to redirect this page form content into next file code edit.php. I want want to update the data from the next page.
<form action="" method="POST">
<tr>
<td><?php echo $type; ?></td>
<td><?php echo $des; ?></td>
<td><?php echo $time; ?></td>
<input type="hidden" name="hid" value="<?php echo $id; ?>">
<input type="hidden" name="htype" value="<?php echo $type; ?>">
<input type="hidden" name="hdes" value="<?php echo $des; ?>">
<td><input type="submit" name="del" value="DELETE">
<input type="submit" name="update" value="UPDATE">
</td></form></tr>
edit.php
This file except the code from above file and update the data that is received into MySQL database
<?php
require 'config.php';
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
if (isset($_POST['update'])) {
$nwtype = $_POST['ltype'];
$nwdes = $_POST['ldes'];
$que = "UPDATE leavetype SET leavetype='$nwtype',description='$nwdes' WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
if ($exe) {
header("location:manageleavetype.php");
}
}
?>
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo $raw['description']; ?>">
<input type="submit" name="update" value="Update">
</form>
When I run this program following error is coming:
Notice: Undefined variable: raw in C:wamp64wwweLeaveSystemedit.php on line 31
php html mysql wamp
marked as duplicate by Dharman, John Conde
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 21 at 2:28
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
27 answers
manageleavetype.php
Below code is my first file page I want to redirect this page form content into next file code edit.php. I want want to update the data from the next page.
<form action="" method="POST">
<tr>
<td><?php echo $type; ?></td>
<td><?php echo $des; ?></td>
<td><?php echo $time; ?></td>
<input type="hidden" name="hid" value="<?php echo $id; ?>">
<input type="hidden" name="htype" value="<?php echo $type; ?>">
<input type="hidden" name="hdes" value="<?php echo $des; ?>">
<td><input type="submit" name="del" value="DELETE">
<input type="submit" name="update" value="UPDATE">
</td></form></tr>
edit.php
This file except the code from above file and update the data that is received into MySQL database
<?php
require 'config.php';
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
if (isset($_POST['update'])) {
$nwtype = $_POST['ltype'];
$nwdes = $_POST['ldes'];
$que = "UPDATE leavetype SET leavetype='$nwtype',description='$nwdes' WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
if ($exe) {
header("location:manageleavetype.php");
}
}
?>
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo $raw['description']; ?>">
<input type="submit" name="update" value="Update">
</form>
When I run this program following error is coming:
Notice: Undefined variable: raw in C:wamp64wwweLeaveSystemedit.php on line 31
php html mysql wamp
marked as duplicate by Dharman, John Conde
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 21 at 2:28
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.
– Dharman
Jan 20 at 12:17
add a comment |
This question already has an answer here:
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
27 answers
manageleavetype.php
Below code is my first file page I want to redirect this page form content into next file code edit.php. I want want to update the data from the next page.
<form action="" method="POST">
<tr>
<td><?php echo $type; ?></td>
<td><?php echo $des; ?></td>
<td><?php echo $time; ?></td>
<input type="hidden" name="hid" value="<?php echo $id; ?>">
<input type="hidden" name="htype" value="<?php echo $type; ?>">
<input type="hidden" name="hdes" value="<?php echo $des; ?>">
<td><input type="submit" name="del" value="DELETE">
<input type="submit" name="update" value="UPDATE">
</td></form></tr>
edit.php
This file except the code from above file and update the data that is received into MySQL database
<?php
require 'config.php';
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
if (isset($_POST['update'])) {
$nwtype = $_POST['ltype'];
$nwdes = $_POST['ldes'];
$que = "UPDATE leavetype SET leavetype='$nwtype',description='$nwdes' WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
if ($exe) {
header("location:manageleavetype.php");
}
}
?>
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo $raw['description']; ?>">
<input type="submit" name="update" value="Update">
</form>
When I run this program following error is coming:
Notice: Undefined variable: raw in C:wamp64wwweLeaveSystemedit.php on line 31
php html mysql wamp
This question already has an answer here:
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
27 answers
manageleavetype.php
Below code is my first file page I want to redirect this page form content into next file code edit.php. I want want to update the data from the next page.
<form action="" method="POST">
<tr>
<td><?php echo $type; ?></td>
<td><?php echo $des; ?></td>
<td><?php echo $time; ?></td>
<input type="hidden" name="hid" value="<?php echo $id; ?>">
<input type="hidden" name="htype" value="<?php echo $type; ?>">
<input type="hidden" name="hdes" value="<?php echo $des; ?>">
<td><input type="submit" name="del" value="DELETE">
<input type="submit" name="update" value="UPDATE">
</td></form></tr>
edit.php
This file except the code from above file and update the data that is received into MySQL database
<?php
require 'config.php';
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
if (isset($_POST['update'])) {
$nwtype = $_POST['ltype'];
$nwdes = $_POST['ldes'];
$que = "UPDATE leavetype SET leavetype='$nwtype',description='$nwdes' WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
if ($exe) {
header("location:manageleavetype.php");
}
}
?>
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo $raw['description']; ?>">
<input type="submit" name="update" value="Update">
</form>
When I run this program following error is coming:
Notice: Undefined variable: raw in C:wamp64wwweLeaveSystemedit.php on line 31
This question already has an answer here:
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
27 answers
php html mysql wamp
php html mysql wamp
edited Jan 20 at 12:14
Dharman
5,19662553
5,19662553
asked Jan 20 at 12:11
Sabir HalaSabir Hala
1
1
marked as duplicate by Dharman, John Conde
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 21 at 2:28
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Dharman, John Conde
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 21 at 2:28
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.
– Dharman
Jan 20 at 12:17
add a comment |
Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.
– Dharman
Jan 20 at 12:17
Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.
– Dharman
Jan 20 at 12:17
Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.
– Dharman
Jan 20 at 12:17
add a comment |
2 Answers
2
active
oldest
votes
When you only define variables within an if
block, you risk getting that error. In your case you define $raw
only when update
is posted:
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
But you access that variable unconditionally in the HTML generation part, like here:
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
So you have a few options:
Put the HTML generation part also in such an
if
block. Then you need to have another part in your code where you generate output for when noupdate
is posted.Define default values for those variables. For example
$raw = ['leavetype' => 'something', 'description' => 'default description']
.
add a comment |
You can simply solve this issue by using the isset() function to avoid undefined variable issue.
Try below:
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo (isset($raw['leavetype']) ? $raw['leavetype'] : '');?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo (isset($raw['description']) ? $raw['description'] : ''); ?>">
<input type="submit" name="update" value="Update">
</form>
I assume that the form block should appear for both Update and Insert.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you only define variables within an if
block, you risk getting that error. In your case you define $raw
only when update
is posted:
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
But you access that variable unconditionally in the HTML generation part, like here:
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
So you have a few options:
Put the HTML generation part also in such an
if
block. Then you need to have another part in your code where you generate output for when noupdate
is posted.Define default values for those variables. For example
$raw = ['leavetype' => 'something', 'description' => 'default description']
.
add a comment |
When you only define variables within an if
block, you risk getting that error. In your case you define $raw
only when update
is posted:
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
But you access that variable unconditionally in the HTML generation part, like here:
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
So you have a few options:
Put the HTML generation part also in such an
if
block. Then you need to have another part in your code where you generate output for when noupdate
is posted.Define default values for those variables. For example
$raw = ['leavetype' => 'something', 'description' => 'default description']
.
add a comment |
When you only define variables within an if
block, you risk getting that error. In your case you define $raw
only when update
is posted:
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
But you access that variable unconditionally in the HTML generation part, like here:
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
So you have a few options:
Put the HTML generation part also in such an
if
block. Then you need to have another part in your code where you generate output for when noupdate
is posted.Define default values for those variables. For example
$raw = ['leavetype' => 'something', 'description' => 'default description']
.
When you only define variables within an if
block, you risk getting that error. In your case you define $raw
only when update
is posted:
if (isset($_POST['update'])) {
$eid = $_POST['hid'];
$que = "SELECT * FROM leavetype WHERE id='$eid'";
$exe = mysqli_query($conn, $que);
$raw = mysqli_fetch_array($exe);
}
But you access that variable unconditionally in the HTML generation part, like here:
<input type="text" name="ltype" value="<?php echo $raw['leavetype']; ?>">
So you have a few options:
Put the HTML generation part also in such an
if
block. Then you need to have another part in your code where you generate output for when noupdate
is posted.Define default values for those variables. For example
$raw = ['leavetype' => 'something', 'description' => 'default description']
.
answered Jan 20 at 13:34
trincottrincot
123k1587120
123k1587120
add a comment |
add a comment |
You can simply solve this issue by using the isset() function to avoid undefined variable issue.
Try below:
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo (isset($raw['leavetype']) ? $raw['leavetype'] : '');?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo (isset($raw['description']) ? $raw['description'] : ''); ?>">
<input type="submit" name="update" value="Update">
</form>
I assume that the form block should appear for both Update and Insert.
add a comment |
You can simply solve this issue by using the isset() function to avoid undefined variable issue.
Try below:
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo (isset($raw['leavetype']) ? $raw['leavetype'] : '');?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo (isset($raw['description']) ? $raw['description'] : ''); ?>">
<input type="submit" name="update" value="Update">
</form>
I assume that the form block should appear for both Update and Insert.
add a comment |
You can simply solve this issue by using the isset() function to avoid undefined variable issue.
Try below:
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo (isset($raw['leavetype']) ? $raw['leavetype'] : '');?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo (isset($raw['description']) ? $raw['description'] : ''); ?>">
<input type="submit" name="update" value="Update">
</form>
I assume that the form block should appear for both Update and Insert.
You can simply solve this issue by using the isset() function to avoid undefined variable issue.
Try below:
<form method="POST">
<label>Leave Type</label>
<input type="text" name="ltype" value="<?php echo (isset($raw['leavetype']) ? $raw['leavetype'] : '');?>">
<label>Description</label>
<input type="text" name="ldes" value="<?php echo (isset($raw['description']) ? $raw['description'] : ''); ?>">
<input type="submit" name="update" value="Update">
</form>
I assume that the form block should appear for both Update and Insert.
answered Jan 20 at 13:48
Praneeth NidarshanPraneeth Nidarshan
1,426919
1,426919
add a comment |
add a comment |
Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.
– Dharman
Jan 20 at 12:17