简体   繁体   中英

When I am trying to run the code it gives error

I am trying to run the code in Jupyter notebook but it shows error SyntaxError: 'break' outside loop

import cv2
import sys
cpt=0
vidStream=cv2.VideoCapture(0)
while True:
    ret,frame=vidStream.read()
cv2.imshow("Test Frame", frame)    
cv2.imwrite(r"E:\Face_Detection_Project\Test_images\0\image%04i.jpg" %cpt,frame)
cpt +=1
if cv2.waitKey(10)==ord('q'):
    break

Break should be inside the while loop. to be inside, you need to add indentation, like this:

import cv2
import sys
cpt=0
vidStream=cv2.VideoCapture(0)
while True:
    ret,frame=vidStream.read()
    cv2.imshow("Test Frame", frame)    
    cv2.imwrite(r"E:\Face_Detection_Project\Test_images\0\image%04i.jpg" %cpt,frame)
    cpt +=1
    if cv2.waitKey(10)==ord('q'):
        break

break is used to break off from a loop. Outside a loop, break statement has no scope. You should put it inside the while loop. Read the break documentation for more information.

<?php
if (isset($_POST["submit"])){
    include 'config.php'; 


   $name = mysql_real_escape_string($conn, $_POST["name"]);
   $email = mysql_real_escape_string($conn, $_POST["email"]);   
   $password = mysql_real_escape_string($conn, $_POST["password"]);
   $cpassword = mysql_real_escape_string($conn, $_POST["cpassword"]);  
   $roles = mysql_real_escape_string($conn, $_POST["roles"]);
   $roles_used = 0;

   if (mysql_num_rows(mysqli_query($conn, "SELECT * FROM users WHERE email='{$email}'")) > 0){
        echo "<script> alert('{$email} - This email is already used.');</script>";
   } else {
        if ($password === $cpassword){
                $sql = "INSERT INTO users (name, email, password, roles, roles_used) VALUES ('{$name}', '{$email}', '{$password}', '{$roles}', '{$roles_used}')";
                $result = mysql_query($conn, $sql);

                if ($result){
                        header("Location: login.html");

                }else{
                    echo "<script>Error: ".$sql.mysql_error($conn)." </script>";    
                }
        }else{
                echo "<script>alert('Passwords do not match.');</script>";
        }
   }
}

?>

 


<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <meta https-equiv="X-UA-Compatible" content="IE-edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <title> MySugar Diabetes Management </title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
        <div class="main">
        <div class="navbar">
        <h2 class="logoo"> MY SUGAR : Diabetes Management System </h2>
    <div class="wrapper">
        <h2 class="title"> Register Account </h2>
        <form class="form" action="" method="post">                   
                <div class="input-field">
                        <label for="name" class="input-label"> Full Name</label>
                        <input type="name" id="name" name="name" class="input" placeholder="Enter your full name" required>
                </div>
                <div class="input-field">
                       <label for="email" class="input-label"> Email</label>
                        <input type="email" name="email" id="email" class="input" placeholder="Enter your Email" required>
                </div>
                <div class="input-field">
                        <label for="password" class="input-label"> Password</label>
                        <input id="password" type="password" class="input" name="password" placeholder="Enter your Password" required>
                </div>
                <div class="input-field">
                        <label for="cpassword" class="input-label">Confirm Password</label>
                        <input id="password" name="cpassword" type="password" class="input" placeholder="Confirm your Password" required>
                </div>
                <div class="input-field">
                        <label for="limit" class="input-label"> Select role</label>
                        <select id="limit" name="roles" class="input" required>
                                <option value="1"> Admin </option>
                                 <option value="2"> Patient </option>
                                  <option value="3"> Doctor </option>
                          </select>
                </div>
                        <button name="submit" class="btn"> Sign Up </button>        
                <p> Already have an account? <a href="login.html"> Log in </a></p>
        </div>
        </form>
</body>
</html> 

I am trying to run this code but on localhost it just comes back as the lines of code. What might be the issue?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM