2017-07-21 4 views
-2

formulaire qui envoie des données dans le fichier php est donnée ci-dessous:Rien ne se passe lorsque vous appuyez sur le bouton UPDATE. Utilisation d'instructions préparées

<center> 
<form action="update.php" method="post"> 
<fieldset style="width:50%"><legend>Please do the required changes</legend><br> 
<label for="Name">Name :<br></label><input name="name" type="text" size="20" maxlength="40" value="<?php echo $data2[Name]?>"><br> 
<label for="CNIC">CNIC :<br></label><input name="cnic" type="text" size="20" maxlength="15" value="<?php echo $data2[CNIC]?>"><br> 
<label for="Date">Booking Date :<br></label><input name="booking-date" type="date" size="20" value="<?php echo $data2[Date]?>"><br> 

<!-- <label for="Ocassion">Ocassion :<br></label> --> 
<label for="Ocassion">Ocassion :<br></label><input name="ocassion" type="text" size="20" maxlength="15" value="<?php echo $data2[Ocassion]?>"><br> 

<label for="Address">Address :<br></label><input name="address" type="text" size="20" maxlength="11" value="<?php echo $data2[Address]?>"><br> 

<label for="Phone Number">Phone Number :<br></label><input name="phone-no" type="text" size="20" maxlength="11" value="<?php echo $data2[Phone_No]?>"><br> 
<label for="Bride Mobile">Bride Mobile :<br></label><input name="bride-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Bride_Mobile]?>"><br> 
<label for="Groom Mobile">Groom Mobile :<br></label><input name="groom-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Groom_Mobile]?>"><br> 
<label for="Family Mobile">Family Mobile :<br></label><input name="family-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Family_Mobile]?>"><br> 
<label for="Email">Email :<br></label><input name="email" type="text" size="20" maxlength="30" value="<?php echo $data2[EMail]?>"><br> 
<label for="Who may I Thank for Refering You?">Who may I Thank for Refering You? :<br></label><input name="refering" type="text" size="20" maxlength="40" value="<?php echo $data2[Referring]?>"><br> 
<label for="Do you provide consent to share images on our official web page">Do you provide consent to share images on our official web page? :<br><br></label><input type="radio" name="share" <?php echo ($data2[Share]=='Yes')?'checked':'' ?> value="Yes">Yes<br> 
<input type="radio" name="share" <?php echo ($data2[Share]=='No')?'checked':'' ?> value="No">No<br><br> 
<label for="If yes, with Identity">If yes, with Identity? :<br><br></label><input type="radio" name="permission" <?php echo ($data2[Permission]=='Yes')?'checked':'' ?> value="Yes">Yes<br> 
<input type="radio" name="permission" <?php echo ($data2[Permission]=='No')?'checked':'' ?> value="No">No<br><br> 
<!-- To center the button i'm embedding the buttons in a paragraph with an id as well. the id is used for CSS in head --> 
<p id="btn"> 
<input type="submit" value="Update Record" name="submit_display_data_form" style="font-size:16px"></p> 
</fieldset> 
</form> 
</center> 
</body> 
</html> 

Le fichier php est:

<?php error_reporting(0); 
$server="localhost"; 
$user="root"; 
$password=""; 
$database="camouflage_studio"; 

$con = mysqli_connect($server,$user,$password,$database); 
if (mysqli_connect_errno()) 
    { 
    echo "Connection Error: " . mysqli_connect_error(); 
    } 
// Updation 
$stmt = $con->prepare("UPDATE 'personal_detail' SET Name = ?, CNIC = ?, Date = ?, Ocassion = ?, Address = ?, Phone_No = ?, Bride_Mobile = ?, Groom_Mobile = ?, Family_Mobile = ?, EMail = ?, Referring = ?, Share = ?, Permission = ? WHERE CNIC = ?"); 

$stmt->bind_param('ssssssiiissss', $_POST['name'], $_POST['cnic'], $_POST['booking-date'], $_POST['ocassion'], $_POST['address'], $_POST['phone-no'], $_POST['bride-mobile'], $_POST['groom-mobile'], $_POST['family-mobile'], $_POST['email'], $_POST['refering'], $_POST['share'], $_POST['permission'], $_POST['cnic']); 

if(mysqli_stmt_execute($stmt)) 
{ 
echo '<script language="javascript" type="text/javascript"> 
       alert("Record Updated Successfully"); 
       window.location = "admin.php"; 
     </script>'; 
} 
else 
echo "Prepare Error: ",$con->error;  //remove $con->error before making ONLINE THE CODE. 

$stmt->close(); 
$con->close(); 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<title>Record Updation</title> 
</head> 

<body> 
</body> 
</html> 

Le problème est que quand j'appuyez sur la touche RECORD UPDATE afin que la mise à jour Fichier .php ouvert dans le navigateur et rien ne se passe. Aucune erreur ne s'affiche ni aucune mise à jour d'enregistrement.

+0

Désolé, quelle instruction exécutez-vous $ stmt ou $ sel_sql ?? –

+0

Si vous utilisez des instructions préparées (ce qui est implicite à partir de votre code, mais pas le cas), utilisez-les correctement. –

+0

Oh, désolé, c'est définitivement $ sel_sql. –

Répondre

0

2 choses, Date est une fonction de mot réservé mysql. Afin de transmettre ce mot comme un nom de col, vous devez envelopper en arrière. problème est que les apostrophes inverses seconde sont `non '(notez la diffrence?)

$stmt = $con->prepare("UPDATE `personal_detail` SET `Name` = ?, `CNIC` = ?, `Date` = ?, `Ocassion` = ?, `Address` = ?, `Phone_No` = ?, `Bride_Mobile` = ?, `Groom_Mobile` = ?, `Family_Mobile` = ?, `EMail` = ?, `Referring` = ?, `Share` = ?, `Permission` = ? WHERE `CNIC` = ?"); 

Laissez-moi savoir comment celui-ci va

Aussi, utilisez stmt- $> erreur afin de suivre les erreurs SQL si une

+0

laissez-moi vérifier. –

+0

Quelque chose ne va pas ... Mise à jour de la requête non exécutée! :(J'ai fait comme vous guidé –

+0

«bonne pratique» et «$ _POST» dans SQL ne vont pas ensemble – chris85