Jump to content

Kiciana

New Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Kiciana

  1. ok sorry, thought it would return the error and display it, it's a help thread so thx for pointing that out. 

     

    So appareantly the problem is the $_GET parameter that i pass, error: Integrity constraint violation: 1048 Column 'appID' cannot be null

     

     I assume the parameter i pass in URL disappears after submission? At least it looks so, it's passed just fine and after I click submit button I get that error and there is no id in the URL

  2. Hi

     

    I'm trying to post and validate a form but it doesn't seem to work and it doean't display any errors

     

    Here's the code

    <?php 
    	include("config.php");
    	session_start();
    ?>
    <?php
    	// define variables and initialize with empty values
    	$rateErr = $comErr = "";
    	$rating = $comment = "";
    
    	 
    	if ($_SERVER["REQUEST_METHOD"] == "POST") {
    		if ($_POST["rating"] == "") {
    			$rateErr = "Rate the app";
    		}
    		else {
    			$rating= $_POST["rating"];
    		}
    	 
    		if (empty($_POST["comment"])) {
    			$comErr = "Missing";
    		}
    		else {
    			$comment = $_POST["comment"];
    		}
    	 if ($rateErr == "" && $comErr == "") {
    			try {
    				$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
    				$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    				$sql = "INSERT INTO reviews (rating, content, appID, user) VALUES(:rating, :comment, :appID, :username)";
    				
    				$stmt = $con->prepare( $sql );
    				$stmt->bindValue( ":rating", $rating);
    				$stmt->bindValue( ":comment", $comment);
    				$stmt->bindValue( ":appID", $_GET['id']);
    				$stmt->bindValue( ":username", $_SESSION['username']);
    				$stmt->execute();
    				return "Submitted successfully";
    			}catch( PDOException $e ) {
    				return $e->getMessage();
    			}
    			}
    	}
    
    ?>
    
    <html>
    	<head>
    	</head>
    	<body>
    <form method="POST"
     action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    <select name="rating">
     <option value=""></option>
     <option value="1">1</option>
     <option value="2">2</option>
     <option value="3">3</option>
     <option value="4">4</option>
     <option value="5">5</option>
    </select>
    <span class="error"><?php echo $rateErr;?></span>
    <br />
    <textarea rows="4" cols="50" name="comment"  value="<?php echo htmlspecialchars($comment);?>">
    
    Enter text here...</textarea>
    <span class="error"><?php echo $comErr;?></span>
    <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>
    
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.