fomalhaut
Member
- Messages
- 107
- Reaction score
- 0
- Points
- 16
Hello.
I want use prepare statement for a mysql insert statement but I have the following error :
[highlight]Parse error: syntax error, unexpected ':' in C:\xampp\htdocs\fomalhaut\gesUtil.php on line 2[/highlight]
I don't understand really how do I link this $dbh with my database which would already connected ?!
Thank you for your help.
I want use prepare statement for a mysql insert statement but I have the following error :
[highlight]Parse error: syntax error, unexpected ':' in C:\xampp\htdocs\fomalhaut\gesUtil.php on line 2[/highlight]
I don't understand really how do I link this $dbh with my database which would already connected ?!
PHP:
<?php session_start();
$ins = $dbh->prepare("INSERT INTO ayant-droit (utilisateur, upass, service, creation, limite, RV) VALUES(?, ?, ?, ?, ?, ?)");
$ins->bindParam(1, $utilAGerer);
$ins->bindParam(2, $paAgerer1);
$ins->bindParam(3, $servAGerer);
$ins->bindParam(4, $creDateAGerer);
$ins->bindParam(5, $revDateAGerer);
$ins->bindParam(6, $RV);
?>
<html><head><title>Gestion du mot de passe</title>
<link rel=stylesheet href="Fomalhaut.css" type="text/css">
</head>
<body>
<div class="flot"><center>
<form action="gesUtil.php" method="post">
<fieldset><legend>Création d'un utilisateur</legend>
Utilisateur :<br /><input type="text" name="utilAGerer" maxlength="15" value="<?php echo $utilAGerer; ?>" /><br />
Mot de Passe :<br /><input type="password" name="passAGerer1" maxlength="15" /><br />
Vérification du Mot de Passe :<br /><input type="password" name="passAGerer2" maxlength="15" /><br />
Service :<br /><input type="text" name="servAGerer" maxlength="3" value="000" /><br />
Date de création :<br /><input type="text" name="creDateAGerer" maxlength="19" value="<?php echo date("Y-m-d H:i:s"); ?>" /><br />
Date de révocation :<br /><input type="text" name="revDateAGerer" maxlength="19" value="<?php echo "2032-12-31 23:59:59" ?>" /><br />
<input type="submit" name="submit" />
</fieldset>
</form></center>
</div>
<?php
$ut=$_SESSION['util']; // le nom de l'utilisateur est passé de page en page par $_SESSION['util']
//This code runs if the form has been submitted
if (isset($_POST['submit'])) {
//This makes sure they did not leave any fields blank
if (!$_POST['utilAGerer'] | !safe($_POST['passAGerer1']) | !safe($_POST['passAGerer2']) | !$_POST['servAGerer'] | !$_POST['creDateAGerer'] | !$_POST['revDateAGerer']) {
die('Il faut remplir tous les champs !'); }
$utilAGerer = $_POST['utilAGerer'];
$paAGerer1 = safe($_POST['passAGerer1']);
$paAGerer2 = safe($_POST['passAGerer2']);
$servAGerer = $_POST['servAGerer'];
$creDateAGerer = $_POST['creDateAGerer'];
$revDateAGerer = $_POST['revDateAGerer'];
// this makes sure both passwords entered match
if ($paAGerer1 != $paAGerer2) {
die('Vous devez entrer deux fois le <b>même nouveau mot de passe</b> !'); }
//on se connecte à la database
$con = mysql_connect("localhost", "user**", "pw**");
$db = "jyc_ayantdroit";
if (!$con) {die('Connection impossible : ' . mysql_error());}
mysql_select_db($db, $con);
// on regarde si l'utilisateur à gérer existe
$check = mysql_query("SELECT * FROM ayant_droit WHERE utilisateur = '" . $utilAGerer . "'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//si l'utilisateur n'existe pas, on le crée
if ($check2 = 0) {
$RV = rand(******);
$passtowrite = hash('******', $RV . $utilAGerer . $paAGerer1);
$ins->execute();
echo 'Création effectuée';
}
else {
echo ('maj non encore développée : seulement pour création nouveaux utilisateurs.');
}
}
?>
<br /><a href="index.php">Retour au menu</a>
</body>
</html>