简体   繁体   中英

php script works offline but doesn't work online

LIVE SAMPLE this is my sample live website

The Problem is my code for a "Contact-Us" works fine when i use it offline(wampserver) but when i upload it to my cpanel it doesnt work... i tried almost everything but the alert just sends me the "connection failed" the Connection.php works fine i can connect to the database, the problem seems to be in the INSERT statement. i don't see any problems in my code, because my other "registration" form works just fine online see my sample website. there's no error problem on my code because i already cheked the error log:

图像是我在网上的错误日志。里面没有问题。。

    <?php 

include_once 'Connection.php';

if(isset($_POST['btn-index']))
{
 $first_name = $_POST['first_name'];
 $email = $_POST['email'];
 $contact = $_POST['contact'];
 $subject = $_POST['subject'];
 $message = $_POST['workarea'];


$first_name = stripslashes($_REQUEST['first_name']);
$first_name = mysqli_real_escape_string($conn,$first_name);

$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($conn,$email);

$contact = stripslashes($_REQUEST['contact']);
$contact = mysqli_real_escape_string($conn,$contact);

$subject = stripslashes($_REQUEST['subject']);
$subject = mysqli_real_escape_string($conn,$subject);

$message = stripslashes($_REQUEST['workarea']);
$message = mysqli_real_escape_string($conn,$message);

$sql = "INSERT INTO `inquiry` (First_Name,Email,Contact,Subj,Message)
VALUES('$first_name','$email','$contact','$subject','$message')";

if($conn->query($sql) === TRUE)
        {
            ?>
            <script>
            alert('Records Submitted!');
            window.location.href='index.php#parent_contacts';
            </script>
            <?php
        }
        else
        {
            ?>
            <script>
            alert('Connection Failed...');
            window.location.href='index.php#parent_contacts';
            </script>
            <?php
        }
$conn->close();
}

//---------FOR ABOUT-US.PHP-------------------------
if(isset($_POST['btn-contact']))
{
 $name = $_POST['name'];
 $email = $_POST['email'];
 $contact = $_POST['contact'];
 $subject = $_POST['subject'];
 $message = $_POST['message'];


$name = stripslashes($_REQUEST['name']);
$name = mysqli_real_escape_string($conn,$name);

$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($conn,$email);

$contact = stripslashes($_REQUEST['contact']);
$contact = mysqli_real_escape_string($conn,$contact);

$subject = stripslashes($_REQUEST['subject']);
$subject = mysqli_real_escape_string($conn,$subject);

$message = stripslashes($_REQUEST['message']);
$message = mysqli_real_escape_string($conn,$message);

$sql = "INSERT INTO `inquiry` (First_Name,Email,Contact,Subj,Message)
VALUES('$name','$email','$contact','$subject','$message')";

if($conn->query($sql) === TRUE)
        {
            ?>
            <script>
            alert('Records Submitted!');
            window.location.href='Contact-Us.php';
            </script>
            <?php
        }
        else
        {
            ?>
            <script>
            alert('Connection Failed...');
            window.location.href='Contact-Us.php';
            </script>
            <?php
        }
$conn->close();
}

?>

I finally fixed my problem after re writing my codes. turns out the problem was on my SQL Table.. the rows doesn't have collation and all rows turned into "int" didnt know what triggers it on godaddy myphpAdmin but it works fine on my wamp when using my local

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