私はテーブルを持って、私は情報を追加または更新する2つのボタンを追加しました。PHPでライブ検証
私は "記述"フィールドで妥当性検査を行いたいと思います。**あなたは文字を書くことができ、255文字未満です。 「名前」フィールドでは、50文字未満しか書き込めません。いずれにしても、私は「SAVE」または「ADD」ボタンをクリックすることはできません(すべてが正しい限り、ボタンはロックされています)。 また、ページには、各フィールドのエラーを(実際にはボタンをクリックする前に)表示する必要があります。
<?php include('connect.php');
$error="";
if(isset($_POST['btnsave']))
{
$career_id=$_POST['carrera'];
$name=$_POST['txtname'];
$description=$_POST['txtdescription'];
$hourss=$_POST['txthours'];
if($_POST['txtid']=="0")
{
$a_sql=mysql_query("INSERT INTO subjects VALUES('','$career_id','$name','$description','$hourss')");
if($a_sql)
{
header("location:index.php");//
}
}else{
echo "Update";
}
}
$sqlm = mysql_query("SELECT * FROM careers");
$options = "";
while($result = mysql_fetch_array($sqlm)){
$options .= "<option value='".$result['id']."'>".$result['name']."</option>";
}
?>
<h2 align="center">ADD NEW SUBJECT</h2>
<form method="Post">
<table align="center">
<tr>
<td>Career:</td>
<td><select name='carrera'><?php echo $options; ?></select><input type="hidden" name="txtid" value="0" /></td>
</tr>
<tr>
<td>Name:</td>
<td><input type='text' name='txtname'/></td>
</tr>
<tr>
<td>Description:</td>
<td><input type='text' name='txtdesription'/></td>
</tr>
<tr>
<td>Hours:</td>
<td>
<select name='txthours'/>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="2">2 (two)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="4">4 (our)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="6">6 (six)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="8">8 (eight)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="10">10 (ten)</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type='submit' value=save name='btnsave'/></td>
</tr>
</table>
</form>
そして、別のコードは、テーブル内の情報を更新:テーブルinformationin新しいを追加するとき
ここでは、私のコードです
<?php include('connect.php');
$error="";
if(isset($_GET['edit']))
{
$ident=$_GET['iden'];
$row=mysql_query("SELECT * FROM subjects WHERE id=$ident");
$st_row=mysql_fetch_array($row);
}
?>
<h2 align="center">UPDATE SUBJECT</h2>
<form method="Post" action=''>
<table align="center">
<tr>
<td>Career:</td>
<td><input type='text' name='txtcarreras_id' value="<?PHP echo $st_row['career'] ?>"/></td>
</tr>
<tr>
<td>Name:</td>
<td><input type='text' name='txtnombre' value="<?PHP echo $st_row['name'] ?>"/></td>
</tr>
<tr>
<td>Description:</td>
<td><input type='text' name='txtdescripcion' value="<?PHP echo $st_row['description'] ?>"/></td>
</tr>
<tr>
<td>Hours:</td>
<td><input type='text' name='txtcarga_horaria' value="<?PHP echo $st_row['hours'] ?>"/></td>
</tr>
<tr>
<td></td>
<td><input type='submit' value="save" name='btnsave'/></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['btnsave']))
{
$career_id=$_POST['txtcarreras_id'];
$name=$_POST['txtnombre'];
$description=$_POST['txtdescripcion'];
$hours=$_POST['txtcarga_horaria'];
$a_sql=mysql_query("UPDATE materias SET career='$career_id', name='$name', description='$description', hours='$hours' WHERE id='$ident'");
if($a_sql)
{
header("location:index.php");
}
}
?>
私が何をするかわかりませんdo:S
新しいコードを書いているなら、** _ please_は 'mysql_ *'関数**を使わないでください。彼らは古くて壊れていて、PHP 5.5では廃止されました(セキュリティアップデートをもはや受け取っていなくなっています)、PHP 7では完全に削除されました。['PDO'](https://secure.php.net/manual /en/book.pdo.php)または['mysqli_ *'](https://secure.php.net/manual/en/book.mysqli.php)を_prepared statements_と_parameter binding_で置き換えてください。詳細については、http://stackoverflow.com/q/12859942/354577を参照してください。 – Chris
あなたの質問は読みにくいです。太字、斜体、またはすべての大文字を不必要に使用しないでください。あなたが叫んでいるように見えます。 – Chris
phpはこの質問には必要ありません。これは最低限の質問ではHTML5の検証であり、要求されたページ上の振る舞いを考慮すると、javascript/jqueryの質問になる可能性が高くなります。あなたはこのトピックを研究しましたか?類似の投稿のためにSOを検索しましたか? – mickmackusa