如何在同一页面上提交和编辑paritcular id数据库中的数据

时间:2016-05-21 15:42:01

标签: php jquery mysql

晚上好,大家......

我正在使用php表单使用以下代码提交数据库中的学生数据...

    <?php

if(isset($_POST['submit1']))
{
$a1=mysql_real_escape_string($_POST['a1']);
$a2=mysql_real_escape_string($_POST['a2']);
$a3=mysql_real_escape_string($_POST['a3']);
$a=mysql_real_escape_string($_POST['a']);
$a4=mysql_real_escape_string($_POST['a4']);
$a5=mysql_real_escape_string($_POST['a5']);
$a6=mysql_real_escape_string($_POST['a6']);
$color=mysql_real_escape_string($_POST['color']);
$date=mysql_real_escape_string($_POST['date']);
$query1=mysql_query("insert into student_table values('','$a1','$a2','$a3','$a','$a4','$a5','$a6','$color','$date')");

if($query1)
{
echo "Open Updated Successfully";
}
}
?>

<div class="RECORD" align="center"><font color="red" size="4">! STUDENT RESULTS !</font><div class="HEADLINES">! Live Result !<br>
<font color="yellow"><?php

$query1 = "SELECT CONCAT(a1,a2,a3,' - ',a,' - ',a4,a5,a6) FROM student_table ORDER BY id DESC
LIMIT 1;";
$result = mysql_query($query1);
$data = mysql_fetch_array($result);

echo $data[0];

?></font></div><hr>

<form method="post" action="" autocomplete="off">
DATE:<input type="text" name="date" size="6" align="absmiddle" value="<?php
$current_dayname = date("l");

echo $date = date("d/m/y",strtotime('monday this week')).' <br>to<br> '.date("d/m/y",strtotime("sunday this week"));  
?>">
<br><br>Open: 
<input type="text" name="a1" size="1" value="<?php echo $query2['a1']; ?>">
<input type="text" name="a2" size="1" value="<?php echo $query2['a2']; ?>">
<input type="text" name="a3" size="1" value="<?php echo $query2['a3']; ?>"> - 
<input type="text" name="a" size="2" value="<?php echo $query2['a']; ?>">
<input type="submit" name="submit1">
</form>

    <?php

$query1 = "SELECT id FROM student_table ORDER BY id DESC
LIMIT 1;";
$result = mysql_query($query1);
$data = mysql_fetch_array($result);


    ?>

现在通过使用上面的代码,它显示了所需的结果....

但我想再添加一个结果和之前的结果,由于这个我必须要求上面结果的编辑页面,所需的编辑页面代码在下面......

<?php

if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['submit2']))
{
$a1=$_POST['a1'];
$a2=$_POST['a2'];
$a3=$_POST['a3'];
$a=$_POST['a'];
$a4=$_POST['a4'];
$a5=$_POST['a5'];
$a6=$_POST['a6'];
$color=$_POST['color'];
$date=$_POST['date'];
$query3=mysql_query("update student_table set a1='$a1', a2='$a2', a3='$a3', a='$a', a4='$a4', a5='$a5', a6='$a6', color='$color', date='$date' where id='$id'");
if($query3)
{
echo "</br> Close Updated Successfully";
}
}
$query1=mysql_query("select * from student_table where id='$id'");
$query2=mysql_fetch_array($query1);
?>

<form method="post" action="" autocomplete="off">

<input type="text" name="a4" size="1" value="<?php echo $query2['a4']; ?>">
<input type="text" name="a5" size="1" value="<?php echo $query2['a5']; ?>">
<input type="text" name="a6" size="1" value="<?php echo $query2['a6']; ?>">
<input type="text" name="a" size="2" value="<?php echo $query2['a']; ?>"><select type="text"  name="color" value="<?php echo $query2['color']; ?>"> <option value="#000000">Black</option><option value="#FF0000">Red</option></select>
<input type="submit" name="submit2"><br>
<div style="background:black; color:black; font-size:1px">DATE:<input type="text" name="date" size="5" align="absmiddle" value="<?php
$current_dayname = date("l");

echo $date = date("d/m/y",strtotime('monday this week')).' <br>to<br> '.date("d/m/y",strtotime("sunday this week"));  
?>"><input type="text" name="a1" size="1" value="<?php echo $query2['a1']; ?>">
<input type="text" name="a2" size="1" value="<?php echo $query2['a2']; ?>">
    <input type="text" name="a3" size="1" value="<?php echo $query2['a3']; ?>"></div>


</form>

<?php
}
?>

现在我的问题是......是否可以同时提交学生号码,并可以选择在同一页面上添加一个与之前结果条目的可编辑功能相同的结果......

请参考下图...

enter image description here

任何人都可以帮助我,使用可编辑选项

在同一页面上执行这两项功能

0 个答案:

没有答案