This is what I did so far but my code is not updating the database, no error showing, nothing, but it's not working. Please help me, I really need it and I'm new to php
.
这是我到目前为止所做的,但我的代码没有更新数据库,没有错误显示,没有,但它不起作用。请帮助我,我真的需要它,我是php的新手。
Basically what I am trying to do is to show the id
name and firstname of each one on the database, and the teacher has to put the notes for each one.
基本上我想要做的是在数据库上显示每个人的id名称和名字,老师必须为每个人写下笔记。
<?php
include('config.php');
?>
<html>
<head>
<title>crypto </title>
</head>
<body>
<h1>crypto !</h1>
<h2>Entrez les données demandées :</h2>
<table>
<div class="content">
<form action="crypto.php" method="post">
<div class="center">
<td class="left"> <?php mysql_query ( ' select id from etudient_l2'); ?></td>
<td class="left"> <?php mysql_query ( ' select nom from etudient_l2'); ?> </td>
<td class="left"> <?php mysql_query ( ' select prenom from etudient_l2'); ?> </td>
<label for="test1">test1</label><input type="text" name="test1" value="<?php if(isset($_POST['test1'])); ?>" /><br />
<label for="test2">test2</label><input type="text" name="test2" value="<?php if(isset($_POST['test2'])); ?>" /><br />
<label for="participation">participation</label><input type="text" name="participation" value="<?php if(isset($_POST['participation'])); ?>" /><br />
<label for="examen">Examen</label><input type="text" name="examen" value="<?php if(isset($_POST['examen'])); ?>" /><br />
<input type="submit" value="Envoyer" />
</div>
</form>
</div>
</table>
<?php
if(isset($_POST['test1'], $_POST['test2'], $_POST['participation'], $_POST['examen']) )
{
//On récupère les valeurs entrées par l'utilisateur :
$test1=$_POST['test1'];
$test2=$_POST['test2'];
$participation=$_POST['participation'];
$examen=$_POST['examen'];
$result=mysql_query('select * from etudient_l2');
$num_rows=mysql_num_rows($result);
echo "$num_rows";
for($i=1; $i<= $num_rows ; $i++)
{
$sql = "UPDATE etudient_l2 SET test1_res='$test1',test2_res='$test2',participation_res='$participation',examen_ res='$examen' where id='$i'";
}
// on ferme la connexion
mysql_close();
>
<?php
}
?>
</body>
</html>
1 个解决方案
#1
just correcting your code first change your HTML like below
只需更正您的代码,首先更改您的HTML,如下所示
<label for="test1">test1</label>
<input type="text" name="test1" value="<?php if(!empty($_POST['test1'])){echo $_POST['test1'];} ?>" />
<br />
<label for="test2">test2</label>
<input type="text" name="test2" value="<?php if(!empty($_POST['test2'])){ echo $_POST['test2'];} ?>" />
<br />
<label for="participation">participation</label>
<input type="text" name="participation" value="<?php if(!empty($_POST['participation'])){ echo $_POST['participation'];} ?>" />
<br />
<label for="examen">Examen</label>
<input type="text" name="examen" value="<?php if(!empty($_POST['examen'])){ echo $_POST['examen'];} ?>" />
<br />
<input type="submit" value="Envoyer" name="submit" />
than change some php code like below
比改变一些像下面的PHP代码
<?php if(isset($_POST['submit']))
{
$test1=$_POST['test1'];
$test2=$_POST['test2'];
$participation=$_POST['participation'];
$examen=$_POST['examen'];
$result=mysql_query("select * from etudient_l2");
$num_rows=mysql_num_rows($result);
echo $num_rows;
for($i=1; $i<=$num_rows;$i++)
{
$sql =mysql_query("UPDATE `etudient_l2` SET `test1_res`='".$test1."',`test2_res`='".$test2."',`participation_res`='".$participation."',`examen_res`='".$examen."' where `id`='".$i."'");
}
// on ferme la connexion
mysql_close();
}
?>
Rest is in your hand i don't take the guarantee based on your code again i am just correcting you.
休息是在你手中我不再根据你的代码采取保证我只是纠正你。
To help you during testing:
在测试期间帮助您:
Add error reporting to the top of your file(s) which will help find errors.
将错误报告添加到文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
旁注:错误报告应该只在暂存中完成,而不是生产。
- Also add
or die(mysql_error())
tomysql_query()
.
还要添加或死(mysql_error())到mysql_query()。
#1
just correcting your code first change your HTML like below
只需更正您的代码,首先更改您的HTML,如下所示
<label for="test1">test1</label>
<input type="text" name="test1" value="<?php if(!empty($_POST['test1'])){echo $_POST['test1'];} ?>" />
<br />
<label for="test2">test2</label>
<input type="text" name="test2" value="<?php if(!empty($_POST['test2'])){ echo $_POST['test2'];} ?>" />
<br />
<label for="participation">participation</label>
<input type="text" name="participation" value="<?php if(!empty($_POST['participation'])){ echo $_POST['participation'];} ?>" />
<br />
<label for="examen">Examen</label>
<input type="text" name="examen" value="<?php if(!empty($_POST['examen'])){ echo $_POST['examen'];} ?>" />
<br />
<input type="submit" value="Envoyer" name="submit" />
than change some php code like below
比改变一些像下面的PHP代码
<?php if(isset($_POST['submit']))
{
$test1=$_POST['test1'];
$test2=$_POST['test2'];
$participation=$_POST['participation'];
$examen=$_POST['examen'];
$result=mysql_query("select * from etudient_l2");
$num_rows=mysql_num_rows($result);
echo $num_rows;
for($i=1; $i<=$num_rows;$i++)
{
$sql =mysql_query("UPDATE `etudient_l2` SET `test1_res`='".$test1."',`test2_res`='".$test2."',`participation_res`='".$participation."',`examen_res`='".$examen."' where `id`='".$i."'");
}
// on ferme la connexion
mysql_close();
}
?>
Rest is in your hand i don't take the guarantee based on your code again i am just correcting you.
休息是在你手中我不再根据你的代码采取保证我只是纠正你。
To help you during testing:
在测试期间帮助您:
Add error reporting to the top of your file(s) which will help find errors.
将错误报告添加到文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
旁注:错误报告应该只在暂存中完成,而不是生产。
- Also add
or die(mysql_error())
tomysql_query()
.
还要添加或死(mysql_error())到mysql_query()。