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.

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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