Reputation: 47
I can't update the data in my database, but it shows that the data is key in successfully,also i have several errors, but i don't how to to correct them, as i'm new to php..please help me out.
My firstform.php :
<?php
session_start();
include 'connect.php';
$query = mysql_query("SELECT *FROM firstform WHERE $id='$_SESSION[manager_name]'");
while($row = mysql_fetch_assoc($query))
{
$manager =$row['manager_name'];
$evaluator =$row['evaluator_name'];
$outlet =$row['outlet_location'];
$date =$row['date'];
$day =$row['day'];
$timein =$row['time_in'];
$timeout =$row['time_out'];
$overall=$row['overall'];
$quality=$row['quality'];
$service=$row['service'];
$cleanliness=$row['cleanliness'];
}
?>
This is my updatefirstform.php :
<?php
//error_reporting(0);
include'connect.php';
session_start();
$manager =$_POST['manager_name'];
$evaluator =$_POST['evaluator_name'];
$outlet =$_POST['outlet_location'];
$date =$_POST['date'];
$day =$_POST['day'];
$timein =$_POST['time_in'];
$timeout =$_POST['time_out'];
$overall=$_POST['overall'];
$quality=$_POST['quality'];
$service=$_POST['service'];
$cleanliness=$_POST['cleanliness'];
mysql_query("UPDATE firstform SET id ='$id' manager_name='$manager', evaluator_name ='$evaluator',outlet_location='$outlet',date='$date',day='$day',time_in ='$timein',time_out='$timeout',overall='$overall',quality='$quality',service='$service',cleanliness='$cleanliness' WHERE $id ='$_SESSION[manager_name]'");
echo ("<SCRIPT LANGUAGE ='JavaScript'>
window.alert ('Data are Sucessfully Updated!')
window.location.href ='secondform.php'
</SCRIPT>");
?>
The errors:
Errors :Notice: Undefined variable: manager in C:\xampp\htdocs\marrybrown_clean\firstform.php on line 4
Notice: Undefined index: manager_name in C:\xampp\htdocs\marrybrown_clean\firstform.php on line 4
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\marrybrown_clean\firstform.php on line 6
Upvotes: 0
Views: 68
Reputation: 47
i have edited my firstform.php :
<?php
session_start();
include 'connect.php';
$query = mysql_query("SELECT * FROM firstform $id ='$_SESSION[user_id]'");
while($row = mysqli_fetch_assoc($query))
{
$id=$row['user_id'];
$manager =$row['manager_name'];
$evaluator =$row['evaluator_name'];
$outlet =$row['outlet_location'];
$date =$row['date'];
$day =$row['day'];
$timein =$row['time_in'];
$timeout =$row['time_out'];
$overall=$row['overall'];
$quality=$row['quality'];
$service=$row['service'];
$cleanliness=$row['cleanliness'];
}
?>
and also my updatefirstform.php :
<?php
//error_reporting(0);
include'connect.php';
session_start();
if(isset($_POST['submit'])) {
$id=mysqli_real_escape_string($_POST['user_id']);
$manager =mysqli_real_escape_string($_POST['manager_name']);
$evaluator =mysqli_real_escape_string($_POST['evaluator_name']);
$outlet =mysqli_real_escape_string($_POST['outlet_location']);
$date =mysqli_real_escape_string($_POST['date']);
$day =mysqli_real_escape_string($_POST['day']);
$timein =mysqli_real_escape_string($_POST['time_in']);
$timeout =mysqli_real_escape_string($_POST['time_out']);
$overall=mysqli_real_escape_string($_POST['overall']);
$quality=mysqli_real_escape_string($_POST['quality']);
$service=mysqli_real_escape_string($_POST['service']);
$cleanliness=mysqli_real_escape_string($_POST['cleanliness']);
mysqli_query("UPDATE firstform SET manager_name='$manager', evaluator_name ='$evaluator',outlet_location='$outlet',date='$date',day='$day',time_in ='$timein',time_out='$timeout',overall='$overall',quality='$quality',service='$service',cleanliness='$cleanliness' WHERE $id ='$_SESSION[user_id]'");
}
if (isset($_GET['submit'])) {
echo ("<SCRIPT LANGUAGE ='JavaScript'>
window.alert ('Data are Sucessfully Updated!')
window.location.href ='secondform.php'
</SCRIPT>");
}
?>
<?php
mysql_close($connection);
?>
and i'm getting this error again, how to fix it?
Notice: Undefined variable: id in C:\xampp\htdocs\marrybrown_clean\firstform.php on line 5
Notice: Undefined index: user_id in C:\xampp\htdocs\marrybrown_clean\firstform.php on line 5
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\marrybrown_clean\firstform.php on line 6
also each my data in my form shows undefined variable like :
<br /><b>Notice</b>: Undefined variable: manager in <b>C:\xampp\htdocs\marrybrown_clean\firstform.php</b> on line <b>139</b><br />
i think my form is okay, but why is it showing error? if i take the id away, how to start my session by manager name only?
This would be my form :
<h2><font size ="5">Pre Evaluation Checklist</font></h2>
<form action="updatefirstform.php" method="post">
<div class="form_settings">
<p><input class ="input" type ="hidden" name="user_id" value ="<?php echo $id; ?>" /> </p>
<p><span>Manager on Duty :</span><input type="manager" id="manager_name" name="manager_name" value="<?php echo $manager;?>" /></p>
<p><span>Evaluator's Name :</span><input type="evaluator_name" name="evaluator_name" value="<?php echo $evaluator;?>" /></p>
<p><span>Outlet Location :</span><input type="outlet_location" name="outlet_location" value="<?php echo $outlet;?>"/></p>
<p><span>Date :</span><input type="date" name="date" value="<?php echo $date;?>" /></p>
<p><span>Day :</span><input type="day" name="day" value="<?php echo $day;?>" /></p>
<p><span>Time In :</span><input type="timein" name="time_in" value="<?php echo $timein;?>" /></p>
<p><span>Time Out :</span><input type="timeout" name="time_out" value="<?php echo $timeout;?>" /></p>
<table width="100%" height="79" border-spacing:0;>
<tr><th width="15%">Overall </th><th width="15%">Quality</th><th width="15%">Service </th><th width="15%"> Cleanliness </th></tr>
<tr><td><input type="overall" name="overall" value ="<?php echo $overall;?>"/></td><td><input type="overall" name="quality" value="<?php echo$quality;?>"/> </td><td><input type="service" name="service" value ="<?php echo $service;?>"/></td><td><input type="cleanliness" name="cleanliness" value="<?php echo $cleanliness;?>"/></td></tr>
</table>
Upvotes: 0
Reputation: 5991
You forgot ,
after setting the ID. And why $id
instead of id
in your update condition? What is the value of your $id
by the way? It should look like this:
mysql_query("UPDATE firstform SET id ='$id',
manager_name='$manager',
evaluator_name ='$evaluator',
outlet_location='$outlet',
date='$date',
day='$day',
time_in ='$timein',
time_out='$timeout',
overall='$overall',
quality='$quality',
service='$service',
cleanliness='$cleanliness'
WHERE id = '$_SESSION[manager_name]'");
Same with your SELECT statement:
$query = mysql_query("SELECT * FROM firstform WHERE id = '".$_SESSION['manager_name']."'");
Use also *_real_escape_string
before binding a variable to your query.
$manager = mysql_real_escape_string($_POST['manager_name']);
// ^^ do this for the rest of your passed-on variables
You should also consider using mysqli_*
rather than the deprecated mysql_*
.
Upvotes: 1
Reputation: 722
At first, manager_name post data cannot from your update form, please check it.
After that use it
mysql_query("UPDATE firstform SET id ='$id', manager_name='$manager', evaluator_name ='$evaluator', outlet_location='$outlet', date='$date', day='$day', time_in ='$timein', time_out='$timeout', overall='$overall', quality='$quality', service='$service', cleanliness='$cleanliness' WHERE $id ='$_SESSION[manager_name]'");
Upvotes: 0
Reputation: 1247
mysql_query("SELECT * FROM firstform WHERE $id='".$_SESSION["manager_name"]."'");
Same problem in the Update
Upvotes: 0