Php+javascript
ray_loubayi
Messages postés
11
Statut
Membre
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour,
j'aimerais bien que vous m'aidé, voici mon pb, jai fais une page php ou jai inclu du java script mais bisaremnt rien ne marche je vais posté les codes pour voir si klk1 pt m'aporté de l'aide
php+html:
<?php $title = $_SESSION['title'];
if ($_POST['submit'] == "submit") //add student
//make connection
$host = "localhost";
$user = "root";
$password = "";
$dbname = "isa";
$dsn = "mysql:host=localhost; dbname=isa";
$dbh = new PDO($dsn, $user, $password);
{
//declare variables
$title = $_POST['title'];
$lfname = $_POST['lfname'];
$mname = $_POST['mname'];
$llname = $_POST['llname'];
$sid = $_POST['sid'];
$sfname = $_POST['sfname'];
$smname = $_POST['smname'];
$slname = $_POST['slname'];
$mcode = $_POST['mcode'];
$grade = $_POST['grade'];
//add data into the database
$query = "INSERT INTO info
(
title,
lfname,
mname,
llname,
sid,
sfname,
smname,
slname,
mcode,
grade
)
VALUES
(
'$title',
'$lfname',
'$mname',
'$llname',
'$sid',
'$sfname',
'$smname',
'$slnam',
'$mcode',
'$grade'
)";
//File to write details to
$filename = 'student.csv';
//Records to be writen
$records = "$title,$lfname,$mname,$llname,$sid,$sfname,$smname,$slname,$mcode, $grade\r";
//Open file in append mode
$openfile = fopen($filename, "a") or die ("could not open the $filename file");
//Write to file now
$written = fwrite($openfile, $records) or die ("could not write to the $filenale file");
//Close the file
fclose($openfile) or die ("could not close the $openfile file");
$db = mysql_connect($host,$user,$password) or die("Unable to connect to database");
@mysql_select_db("$dbname",$db) or die("Unable to select
database $dbname");
$mes = "<div style='height:30px;padding:10px; border:1px solid green; padding-top:5px; margin-bottom:10px; padding-left:2px; font-size:10px; background-color:#DDF7DD; margin-top:24px'>
<p style='padding:2px; margin-top:0; margin-bottom:10px; font-size:12px'>
<img src='../img/ok.png' style='vertical-align: middle; '> <the <student has been add.</p>
</div>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
</head>
<script type="text/javascript" src="script.js" language="javascript"></script>
<body>
<form id="form1" name="form1" method="post" action="index.php" enctype="multipart/form-data" onsubmit="validateFormOnSubmit(this)">
<table width="372" height="433" border="1" align="center">
<tr>
<td colspan="2" align="center" bgcolor="#66FFFF">Lecturer Details</td>
</tr>
<tr>
<td width="165">Title:</td>
<td width="191"><label for="title"></label>
<select name="title" id="title">
<option>Mr</option>
<option selected="selected">Ms</option>
<option>Miss</option>
<option>Doctor</option>
<option>Professor</option>
</select></td>
</tr>
<tr>
<td >First Name:</td>
<td><label for="lfname"></label>
<input type="text" name="lfname" id="lfname" /></td>
</tr>
<tr>
<td>Middle Name:</td>
<td><label for="mname"></label>
<input name="mname" type="text" id="mname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><label for="llname"></label>
<input type="text" name="llname" id="llname" /></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#66FFFF">Student Records</td>
</tr>
<tr>
<td>Student ID:</td>
<td><label for="sid"></label>
<input name="sid" type="text" id="sid" maxlength="7" /></td>
</tr>
<tr>
<td>First Name:</td>
<td><label for="sfname"></label>
<input type="text" name="sfname" id="sfname" /></td>
</tr>
<tr>
<td>Middle Name:</td>
<td><label for="smname"></label>
<input type="text" name="smname" id="smname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><label for="smcode"></label>
<label for="slname"></label>
<input type="text" name="slname" id="slname" /></td>
</tr>
<tr>
<td>Model Code:</td>
<td><label for="smcode"></label>
<input type="text" name="smcode" id="smcode" /></td>
</tr>
<tr>
<td>Grade:</td>
<td><label for="sgrade"></label>
<input type="text" name="sgrade" id="sgrade" /></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#66FFFF"><input type="submit" name="Submit" id="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
javascript
function validateFormOnSubmit(theForm)
{
var reason = "";
reason += validatelfname(theForm.lfname);
reason += validatemname(theForm.mname);
reason += validatellname(theForm.llname);
reason += validatesid(theForm.sid);
reason += validatesfname(theForm.sfname);
reason += validatesmname(theForm.smname);
reason += validateslname(theForm.slname);
reason += validatemcode(theForm.mcode);
reason += validategrade(theForm.grade);
}
if (reason != "") {
alert("Please feel all the form:\n" + reason);
return false;
}
return true;
}
function validatelfname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter your First name .\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >20{
fld.style.background = 'Yellow';
error = "frist name cannot have more than 20caracters.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validatemname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter the middle name please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegal caracters.\n";
else {
fld.style.background = 'white';
}
return error;
}
function validatellname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter your last name please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegal caracters.\n";
else {
fld.style.background = 'white';
}
return error;
}
function validatesid(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter the student ID please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "the ID have illegal caraters.\n";
} else if (stripped.length >7 {
fld.style.background = 'Yellow';
error = "too much.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validatelfname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter your First name .\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >20{
fld.style.background = 'Yellow';
error = "frist name cannot have more than 20caracters.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validatelsmname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter your First middle name.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >20{
fld.style.background = 'Yellow';
error = "frist name cannot have more than 20caracters.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validateslname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter your last name please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegal caracters.\n";
else {
fld.style.background = 'white';
}
return error;
}
function validatelmcode(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter the modul code.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >6 {
fld.style.background = 'Yellow';
error = "three letters and three digits please.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validategrade(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter the modul code.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >100 {
fld.style.background = 'Yellow';
error = ".\n";
}
else {
fld.style.background = 'white';
}
return error;
}
pouvez vous m'aidé merci!!
j'aimerais bien que vous m'aidé, voici mon pb, jai fais une page php ou jai inclu du java script mais bisaremnt rien ne marche je vais posté les codes pour voir si klk1 pt m'aporté de l'aide
php+html:
<?php $title = $_SESSION['title'];
if ($_POST['submit'] == "submit") //add student
//make connection
$host = "localhost";
$user = "root";
$password = "";
$dbname = "isa";
$dsn = "mysql:host=localhost; dbname=isa";
$dbh = new PDO($dsn, $user, $password);
{
//declare variables
$title = $_POST['title'];
$lfname = $_POST['lfname'];
$mname = $_POST['mname'];
$llname = $_POST['llname'];
$sid = $_POST['sid'];
$sfname = $_POST['sfname'];
$smname = $_POST['smname'];
$slname = $_POST['slname'];
$mcode = $_POST['mcode'];
$grade = $_POST['grade'];
//add data into the database
$query = "INSERT INTO info
(
title,
lfname,
mname,
llname,
sid,
sfname,
smname,
slname,
mcode,
grade
)
VALUES
(
'$title',
'$lfname',
'$mname',
'$llname',
'$sid',
'$sfname',
'$smname',
'$slnam',
'$mcode',
'$grade'
)";
//File to write details to
$filename = 'student.csv';
//Records to be writen
$records = "$title,$lfname,$mname,$llname,$sid,$sfname,$smname,$slname,$mcode, $grade\r";
//Open file in append mode
$openfile = fopen($filename, "a") or die ("could not open the $filename file");
//Write to file now
$written = fwrite($openfile, $records) or die ("could not write to the $filenale file");
//Close the file
fclose($openfile) or die ("could not close the $openfile file");
$db = mysql_connect($host,$user,$password) or die("Unable to connect to database");
@mysql_select_db("$dbname",$db) or die("Unable to select
database $dbname");
$mes = "<div style='height:30px;padding:10px; border:1px solid green; padding-top:5px; margin-bottom:10px; padding-left:2px; font-size:10px; background-color:#DDF7DD; margin-top:24px'>
<p style='padding:2px; margin-top:0; margin-bottom:10px; font-size:12px'>
<img src='../img/ok.png' style='vertical-align: middle; '> <the <student has been add.</p>
</div>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
</head>
<script type="text/javascript" src="script.js" language="javascript"></script>
<body>
<form id="form1" name="form1" method="post" action="index.php" enctype="multipart/form-data" onsubmit="validateFormOnSubmit(this)">
<table width="372" height="433" border="1" align="center">
<tr>
<td colspan="2" align="center" bgcolor="#66FFFF">Lecturer Details</td>
</tr>
<tr>
<td width="165">Title:</td>
<td width="191"><label for="title"></label>
<select name="title" id="title">
<option>Mr</option>
<option selected="selected">Ms</option>
<option>Miss</option>
<option>Doctor</option>
<option>Professor</option>
</select></td>
</tr>
<tr>
<td >First Name:</td>
<td><label for="lfname"></label>
<input type="text" name="lfname" id="lfname" /></td>
</tr>
<tr>
<td>Middle Name:</td>
<td><label for="mname"></label>
<input name="mname" type="text" id="mname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><label for="llname"></label>
<input type="text" name="llname" id="llname" /></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#66FFFF">Student Records</td>
</tr>
<tr>
<td>Student ID:</td>
<td><label for="sid"></label>
<input name="sid" type="text" id="sid" maxlength="7" /></td>
</tr>
<tr>
<td>First Name:</td>
<td><label for="sfname"></label>
<input type="text" name="sfname" id="sfname" /></td>
</tr>
<tr>
<td>Middle Name:</td>
<td><label for="smname"></label>
<input type="text" name="smname" id="smname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><label for="smcode"></label>
<label for="slname"></label>
<input type="text" name="slname" id="slname" /></td>
</tr>
<tr>
<td>Model Code:</td>
<td><label for="smcode"></label>
<input type="text" name="smcode" id="smcode" /></td>
</tr>
<tr>
<td>Grade:</td>
<td><label for="sgrade"></label>
<input type="text" name="sgrade" id="sgrade" /></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#66FFFF"><input type="submit" name="Submit" id="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
javascript
function validateFormOnSubmit(theForm)
{
var reason = "";
reason += validatelfname(theForm.lfname);
reason += validatemname(theForm.mname);
reason += validatellname(theForm.llname);
reason += validatesid(theForm.sid);
reason += validatesfname(theForm.sfname);
reason += validatesmname(theForm.smname);
reason += validateslname(theForm.slname);
reason += validatemcode(theForm.mcode);
reason += validategrade(theForm.grade);
}
if (reason != "") {
alert("Please feel all the form:\n" + reason);
return false;
}
return true;
}
function validatelfname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter your First name .\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >20{
fld.style.background = 'Yellow';
error = "frist name cannot have more than 20caracters.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validatemname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter the middle name please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegal caracters.\n";
else {
fld.style.background = 'white';
}
return error;
}
function validatellname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter your last name please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegal caracters.\n";
else {
fld.style.background = 'white';
}
return error;
}
function validatesid(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter the student ID please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "the ID have illegal caraters.\n";
} else if (stripped.length >7 {
fld.style.background = 'Yellow';
error = "too much.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validatelfname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter your First name .\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >20{
fld.style.background = 'Yellow';
error = "frist name cannot have more than 20caracters.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validatelsmname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter your First middle name.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >20{
fld.style.background = 'Yellow';
error = "frist name cannot have more than 20caracters.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validateslname(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "Enter your last name please.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegal caracters.\n";
else {
fld.style.background = 'white';
}
return error;
}
function validatelmcode(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter the modul code.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >6 {
fld.style.background = 'Yellow';
error = "three letters and three digits please.\n";
}
else {
fld.style.background = 'white';
}
return error;
}
function validategrade(fld) {
var error = "";
var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "enter the modul code.\n";
} else if (isNaN(parseInt(stripped))) {
error = "illegals caracters.\n";
} else if (stripped.length >100 {
fld.style.background = 'Yellow';
error = ".\n";
}
else {
fld.style.background = 'white';
}
return error;
}
pouvez vous m'aidé merci!!
A voir également:
- Php+javascript
- Easy php - Télécharger - Divers Web & Internet
- Telecharger javascript - Télécharger - Langages
- Expert php pinterest - Télécharger - Langages
- Javascript echo ✓ - Forum PHP
- A javascript error occurred in the main process - Forum Handicap / Accessibilté