CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    141

    insert query failed.. only when online

    hi...

    i've a php code which works perfectly when it's on my localhost apache server... but when i uploaded it onto my server on the internet.. it gives an error... here's the partial code:

    Code:
    <?PHP
    
    $name = addslashes($_POST['name']);
    $crimeType = addslashes($_POST['crimeType']);
    $crimeDesc = addslashes($_POST['crimeDesc']);
    $crimeLocationTown = addslashes($_POST['crimeLocationTown']);
    $crimeLocationState = addslashes($_POST['crimeLocationState']);
    $locationLatLng = addslashes($_POST['locationLatLng']);
    
    echo $name;
    echo $crimeType;
    echo $crimeDesc;
    echo $crimeLocationTown;
    echo $crimeLocationState;
    echo $locationLatLng;
    
    //set the database connection variables
    $dbHost = "localhost";
    $dbUser = "test";
    $dbPass = "testtest";
    $dbDatabase = "testdb";
      
    //$reportDate = date("Y-m-d");
    //connect to the database
    $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
    mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
    
    $query ="insert into userReport (reportPerson,crimeType,crimeDesc,crimeLocationTown,crimeLocationState,locationLatLng) values 
    ('$name','$crimeType','$crimeDesc','$crimeLocationTown','$crimeLocationState','$locationLatLng')";
    
    mysql_query($query) or die('Error, insert query failed');
    
    
    echo 'data inserted';
       
      
    
    ?>
    if it's on my local server, it will return 'data inserted'. but if i put it on my hosting, it will return 'insert query failed'. my other php page which also go insert query works well, but not this page. is it possible if I mis-constructed the mysqsl table on my hosting? but i've triple check the table and it's the same as the mysql table on my pc.

    please help. thanks a lot
    Last edited by imin; February 18th, 2008 at 01:13 AM.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: insert query failed.. only when online

    Your connection string will be different on your hosted server rather than the localhost. Your mysql_connect() is most likely failing for this reason.

    You might want to edit your previous post and remove the vital information (username and password).
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2005
    Posts
    141

    Re: insert query failed.. only when online

    Quote Originally Posted by PeejAvery
    Your connection string will be different on your hosted server rather than the localhost. Your mysql_connect() is most likely failing for this reason.

    You might want to edit your previous post and remove the vital information (username and password).
    Thanks for replying. But the problem is not with the connection string, as the same string works for other page. But i've found (?) the problem; it's actually because my table name supposed to be all lowercase. When I change the table name to lowercase, the query works. But one thing puzzled me, after that, I tried changing the table name to lowercase and uppercase (like beforee), it still works..huhuhu.. .anyway the good thing is the problem doesn't appear again (for the time being)

    thanks for your notice on editing the crucial db information

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured