Jump to content

Insert query not working: Pls respond as soon as possible


bhaumik_shah

Recommended Posts

The given query is not working, it is echoing "You are doomed". so don't know hwat is the bug.

 

<?php
    
    session_start();
     $host = 'localhost';
     $db = 'cramis_2012';
     $user = 'root';
     $pass = '';
     $conn=mysql_connect($host,$user,$pass);
     if(!$conn)
     { echo "Connection problem";}
     @mysql_select_db($db,$conn) or die(" Unable to select");
    
    
    
      

    //Include database connection details
    //include("_opener_db.php");
    
    //Array to store validation errors
    $errmsg_arr = array();
    
    //Validation error flag
    $errflag = false;
    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

    $department=clean($_POST['department']);
    $area=clean($_POST['area']);
    $update=clean($_POST['update']);
    
    
    $query = "INSERT INTO updates (Area,Department,Update) VALUES ('$area','$department','$update')";
    
    $result=mysql_query($query,$conn);
    
    if($result){
    
        echo "Query sucessful";
        header("location:http://localhost:3333/cramis_2012/lect/app/index.php");
        exit();
    
    
    }
    else{
        die(" You are Doomed");
    }
    mysql_close();
?>

The database pic too.

 

 

 

 

 

 

 

 

 

 

 

 

 

I know this is now solved but ... for better error reporting you should do something like this - 

$result = mysql_query($query,$conn) or die( '<h1>You are doomed!</h1><p>'.mysql_error().'</p>' );

Then you'll actually know what's going wrong instead of seeing your generic error message.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.