I've got the sessions working to display the child information, I now want to be able to edit that information and update the database. I've tried every youtube video and website but nothing uses $_SESSION they all use $_POST.
我已经让会话工作以显示子信息,我现在希望能够编辑该信息并更新数据库。我已经尝试过每个youtube视频和网站但没有使用$ _SESSION他们都使用$ _POST。
<div class="post">
<h1 class="title">Child Details: </h1>
<p class="title"><img src=" <?php echo "".$_SESSION['sourcepath']; ?>"
</p>
<p class="title"><?php echo "".$_SESSION['ChildID']; ?></p>
<table style="width: 100%">
<tr>
<td style="width: 106px">Name</td>
<td style="width: 252px"><?php echo "".$_SESSION ['Firstname']; ?> <?php echo "".$_SESSION['Surname']; ?></td>
<td style="width: 94px">School</td>
<td><form method="post">
<br />
<textarea name="School" cols="20" rows="5"><?php echo "".$_SESSION['School']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Date of Birth</td>
<td><?php echo "".$_SESSION['DateOfBirth']; ?></td>
<td style="width: 94px">English</td>
<td><form method="post">
<br />
<textarea name="English" cols="20" rows="5"><?php echo "".$_SESSION['English']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Age</td>
<td><?php echo "".$_SESSION['Age']; ?>;</td>
<td style="width: 94px">Science</td>
<td><form method="post">
<br />
<textarea name="Science" cols="20" rows="5"><?php echo "".$_SESSION['Science']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Address</td>
<td><form method="post">
<br />
<textarea name="Address" cols="20" style="height: 89px"><?php echo "".$_SESSION['Address']; ?></textarea></form>
</td>
<td style="width: 94px">Maths</td>
<td><form method="post">
<br />
<textarea name="Maths" cols="20" rows="5"><?php echo "".$_SESSION['Maths']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Postcode:</td>
<td><?php echo "".$_SESSION['PostCode']; ?>;</td>
<td style="width: 94px">Homework</td>
<td><form method="post">
<br />
<textarea name="Homework" cols="20" rows="5"><?php echo "".$_SESSION['Homework']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Contact Number</td>
<td><form method="post">
<textarea name="ContactNumber" cols="20" rows="2"><?php echo "".$_SESSION['ContactNumber']; ?></textarea></form>
</td>
<td style="width: 94px">Additional</td>
<td><form method="post">
<br />
<textarea name="Additional" cols="20" rows="8"><?php echo "".$_SESSION['Additional']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Mother Name</td>
<td><?php echo "".$_SESSION['MotherName']; ?></td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px"> </td>
<td> </td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px">Last Update</td>
<td><?php echo "".$_SESSION['TimeStamp']; ?></td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px"> </td>
<td> </td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px">
</td>
<td>
<form method="post" action="updatetest.php">
<input type="hidden" name="id" value="<?php echo $_SESSION['ChildID']; ?>"/>
<input name="Submit" type="submit" value="Update" /></form>
</td>
<?php session_start(); ?>
<?php
$connect = mysql_connect("127.0.0.1" , "root" , "") or die ("Couldnt connect to database");
mysql_select_db("travellerfile") or die ("couldnt find the database");
$School = $_SESSION['School'];
$Maths = $_SESSION['Maths'];
$English = $_SESSION['English'];
$Science = $_SESSION['Science'];
$Homework = $_SESSION['Homework'];
$Additional = $_SESSION['Additional'];
$id = $_SESSION['ChildID'];
$q = "SELECT * FROM child WHERE ChildID = $_SESSION[ChildID]";
$result = mysql_query($q);
$person = mysql_fetch_array($result);
$u = "UPDATE child SET Maths= '$_SESSION['Maths']', Science= '$_SESSION['Science']';
?>
4 个解决方案
#1
1
$_SESSION['School'] = $_POST['School'];
$School = $_SESSION['School'];
Somewhere you'll have to declare that $_SESSION['School'] contains the value of the Textarea with the name 'School'. You can't just expect PHP to put POST variables into SESSION variables
在某个地方你必须声明$ _SESSION ['School']包含名称为'School'的Textarea的值。您不能仅仅期望PHP将POST变量放入SESSION变量中
#2
1
For example:
例如:
$_SESSION['ChildID'] = 5;
<form method="post" action="updatetest.php">
<input type="hidden" name="id" value="<?php echo $_SESSION['ChildID']; ?>"/>
<input name="Submit" type="submit" value="Update" /></form>
This will post you:
这将发布给你:
$_POST['id'] = 5;
So:
所以:
UPDATE table SET col = $_POST['id'];
#3
0
Update $_SESSION
end grab $_POST
for database;
为数据库更新$ _SESSION end grab $ _POST;
...
$School = $_['School'] = $_POST['School'];
$Maths = $_SESSION['Maths'] = $_POST['Maths'];
$English = $_SESSION['English'] = $_POST['English'];
$Science = $_SESSION['Science'] = $_POST['Science'];
$Homework = $_SESSION['Homework'] = $_POST['Homework'];
$Additional = $_SESSION['Additional'] = $_POST['Additional'];
$id = $_SESSION['ChildID'];
...
#4
0
Both $_POST
and $_SESSION
are merely arrays. The only thing that makes them special is that they are global. So, if you have code that works for $_POST
, just substitute in the corresponding $_SESSION
values.
$ _POST和$ _SESSION都只是数组。使它们与众不同的唯一因素是它们是全球性的。因此,如果您的代码适用于$ _POST,则只需替换相应的$ _SESSION值。
What your real issue is, is that you are submitting a form. Forms can submit using get
or post
methods. There is no session
method. So your values are arriving at your php script in the $_POST
variable. You could then copy them to the $_SESSION
variable before running your update, but there's really no good reason to. The only reason they would need to be in $_SESSION
is so that they can be output if the form needs to be re-displayed with the submitted values.
您真正的问题是,您提交的是表格。表单可以使用get或post方法提交。没有会话方法。因此,您的值将在$ _POST变量中到达您的php脚本。然后,您可以在运行更新之前将它们复制到$ _SESSION变量,但实际上并没有充分的理由。他们需要在$ _SESSION中的唯一原因是,如果需要使用提交的值重新显示表单,则可以输出它们。
#1
1
$_SESSION['School'] = $_POST['School'];
$School = $_SESSION['School'];
Somewhere you'll have to declare that $_SESSION['School'] contains the value of the Textarea with the name 'School'. You can't just expect PHP to put POST variables into SESSION variables
在某个地方你必须声明$ _SESSION ['School']包含名称为'School'的Textarea的值。您不能仅仅期望PHP将POST变量放入SESSION变量中
#2
1
For example:
例如:
$_SESSION['ChildID'] = 5;
<form method="post" action="updatetest.php">
<input type="hidden" name="id" value="<?php echo $_SESSION['ChildID']; ?>"/>
<input name="Submit" type="submit" value="Update" /></form>
This will post you:
这将发布给你:
$_POST['id'] = 5;
So:
所以:
UPDATE table SET col = $_POST['id'];
#3
0
Update $_SESSION
end grab $_POST
for database;
为数据库更新$ _SESSION end grab $ _POST;
...
$School = $_['School'] = $_POST['School'];
$Maths = $_SESSION['Maths'] = $_POST['Maths'];
$English = $_SESSION['English'] = $_POST['English'];
$Science = $_SESSION['Science'] = $_POST['Science'];
$Homework = $_SESSION['Homework'] = $_POST['Homework'];
$Additional = $_SESSION['Additional'] = $_POST['Additional'];
$id = $_SESSION['ChildID'];
...
#4
0
Both $_POST
and $_SESSION
are merely arrays. The only thing that makes them special is that they are global. So, if you have code that works for $_POST
, just substitute in the corresponding $_SESSION
values.
$ _POST和$ _SESSION都只是数组。使它们与众不同的唯一因素是它们是全球性的。因此,如果您的代码适用于$ _POST,则只需替换相应的$ _SESSION值。
What your real issue is, is that you are submitting a form. Forms can submit using get
or post
methods. There is no session
method. So your values are arriving at your php script in the $_POST
variable. You could then copy them to the $_SESSION
variable before running your update, but there's really no good reason to. The only reason they would need to be in $_SESSION
is so that they can be output if the form needs to be re-displayed with the submitted values.
您真正的问题是,您提交的是表格。表单可以使用get或post方法提交。没有会话方法。因此,您的值将在$ _POST变量中到达您的php脚本。然后,您可以在运行更新之前将它们复制到$ _SESSION变量,但实际上并没有充分的理由。他们需要在$ _SESSION中的唯一原因是,如果需要使用提交的值重新显示表单,则可以输出它们。