1

Last Week working all correctly but today i get this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''Mees'')' at line 1' in /www/data08/users/i/itsiim.planet.ee/htdocs/progemine/system/lisa.php:47 Stack trace: #0 /www/data08/users/i/itsiim.planet.ee/htdocs/progemine/system/lisa.php(47): PDOStatement->execute(Array) #1 {main} thrown in /www/data08/users/i/itsiim.planet.ee/htdocs/progemine/system/lisa.php on line 47

PHP Code here

    <?php 
    require 'conf/db.php';
    if ( !empty($_POST)) {
        // keep track validation errors
        $nimiError = null;
        $emailError = null;
        $mobiilError = null;
        $suguError = null;

        // keep track post values
        $nimi = $_POST['nimi'];
        $email = $_POST['email'];
        $mobiil = $_POST['mobiil'];
        $sugu = $_POST['sugu'];

        // validate input
        $valid = true;
        if (empty($nimi)) {
            $nimiError = 'Palun sisesta nimi';
            $valid = false;
        }

        if (empty($email)) {
            $emailError = 'Palun sisesta e-mail';
            $valid = false;
        } else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
            $emailError = 'Palun sisesta korrektne e-mail';
            $valid = false;
        }

        if (empty($mobiil)) {
            $mobiilError = 'Palun sisesta mobiili number';
            $valid = false;
        }

        if (empty($sugu)) {
            $suguError = 'Palun vali sugu';
            $valid = false;
        }

        // insert data
        if ($valid) {
            $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "INSERT INTO kliendid (nimi,email,mobiil,sugu) values(?, ?, ?, ?')";
            $q = $pdo->prepare($sql);
            $q->execute(array($nimi,$email,$mobiil,$sugu));
            Database::disconnect();
            header("Location: index.php");
        }
    }
?>
<!DOCTYPE html>
<html lang="et">
<head>
    <meta charset="utf-8">
    <title>Klientide andmed by Siim Aarmaa IS-13</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<body>
    <div class="container">

                <div class="col-md-6 col-md-offset-3">
                    <div class="row">
                        <h3>Lisa uus klient</h3>
                    </div>

                    <form class="form-horizontal" action="lisa.php" method="post">
                      <div class="form-group <?php echo !empty($nimiError)?'error':'';?>">
                        <label class="col-sm-2 control-label">Nimi</label>
                        <div class="controls">
                            <input name="nimi" type="text"  placeholder="Nimi" value="<?php echo !empty($nimi)?$nimi:'';?>">
                            <?php if (!empty($nimiError)): ?>
                                <span class="help-block"><?php echo $nimiError;?></span>
                            <?php endif; ?>
                        </div>
                      </div>
                      <div class="form-group <?php echo !empty($emailError)?'error':'';?>">
                        <label class="col-sm-2 control-label">E-mail</label>
                        <div class="controls">
                            <input name="email" type="text" placeholder="E-mail" value="<?php echo !empty($email)?$email:'';?>">
                            <?php if (!empty($emailError)): ?>
                                <span class="help-block"><?php echo $emailError;?></span>
                            <?php endif;?>
                        </div>
                      </div>
                      <div class="form-group <?php echo !empty($mobiilError)?'error':'';?>">
                        <label class="col-sm-2 control-label">Mobiili number</label>
                        <div class="controls">
                            <input name="mobiil" type="text"  placeholder="Mobiili number" value="<?php echo !empty($mobiil)?$mobiil:'';?>">
                            <?php if (!empty($mobiilError)): ?>
                                <span class="help-block"><?php echo $mobiilError;?></span>
                            <?php endif;?>
                        </div>
                      </div>
                      <div class="form-group <?php echo !empty($suguError)?'error':'';?>">
                        <label class="col-sm-2 control-label">Sugu</label>
                        <div class="controls">
                            <input name="sugu" type="radio" value="<?php echo !empty($mees)?$mees:'Mees';?>">Mees
                            <input name="sugu" type="radio" value="<?php echo !empty($naine)?$naine:'Naine';?>">Naine
                            <?php if (!empty($suguError)): ?>
                                <span class="help-block"><?php echo $suguError;?></span>
                            <?php endif;?>
                        </div>
                      <div class="form-group">
                          <button type="submit" class="btn btn-success">Lisa klient</button>
                          <a class="btn btn-default" href="index.php">Tagasi</a>
                        </div>
                    </form>
                </div>
    </div> <!-- /container -->
  </body>
</html>`enter code here`
1
  • 1
    ...values(?, ?, ?, ?') It looks like you have a single-quote that shouldn't be there. Commented Jan 21, 2016 at 18:21

1 Answer 1

3

You have a syntax error, a exta single quote in your query:

 $sql = "INSERT INTO kliendid (nimi,email,mobiil,sugu) values(?, ?, ?, ?')";
                                                                        ^

Change it to:

 $sql = "INSERT INTO kliendid (nimi,email,mobiil,sugu) values(?, ?, ?, ?)";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.