0

I keep getting

Server error The website encountered an error while retrieving https://www.website.com/update.php?FName=asdd&PHONE=4444444444. It may be down for maintenance or configured incorrectly.

<?php

    $FName = $_POST['FName'];
    $LName = $_POST['LName'];
    $PHON = $_POST['PHON'];

    //connect
    $dbh=mysql_connect ("localhost", "username", "password") or die ('ERROR!');
    mysql_select_db ("user_Client"); 

    $query = "INSERT INTO ClientTable (ID, FName, LName, PHON) VALUES 
                ('NULL','".$FName."','".$LName."','".$PHON."')";

    mysql_query($query) or die ('Error updating Daatabase');
    echo "Database Update with:" .$FName. " " .$LName. " " .$PHON. ;
?>

I don't know what's the problem here. I followed instructions from here http://teamtutorials.com/web-development-tutorials/php-tutorials/inserting-data-into-a-mysql-database-using-php#.UEiSQY3iajk If it helps - I'm using cPanel from Josthost.

Here is the form:

<html>
        <head>
                <title></title>
        </head>

        <body>
                <form method="post" action="update.php">
                        First Name:<br/>
                        <input type="text" name="FName" size="30" /><br/>
                        Last Name:<br/>
                        <input type="text" name="LName" size="30" /><br/>
                        Phone:<br/>
                        <input type="text" name="PHON" size="12" /><br/>
                        <input type="submit" value="Update Database"/>
                </form>
        </body>
</html>
11
  • 1
    Please, don't use mysql_* functions for new code. They are no longer maintained and the community has begun the deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you can't decide, try this article. If you care to learn, here is good PDO tutorial. Commented Sep 6, 2012 at 12:42
  • Is ID set to allow nulls? What does your schema look like? Commented Sep 6, 2012 at 12:43
  • I'm sorry but I can't understand what does SQL has to do with a 404? Commented Sep 6, 2012 at 12:44
  • @Mihai Iorga: Don't assume that he/she has access to latest and greatest PHP. It may be that they are working on a legacy system. Commented Sep 6, 2012 at 12:44
  • Probably not the cause of your error, but you're setting $FNLame and trying to use $LName other places. Lots of other errors too though... Commented Sep 6, 2012 at 12:44

5 Answers 5

2

Please use PDO because mysql_* functions are deprecated ..

For your problem, you use $_GET and not $_POST, also you misspelled your variables ($FNLame):

$db = new PDO('mysql:host=localhost;dbname=user_Client;charset=UTF-8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

$FName = $_GET['FName'];
$LName = $_GET['LName'];
$PHON = $_GET['PHON'];

$stmt = $db->prepare("INSERT INTO `ClientTable`(ID, FName, LName, PHON) VALUES (0,:FName,:LName,:PHON)");
$stmt->execute(array(':FName' => $FName, ':LName' => $LName, ':PHON' => $PHON));

echo "Database Update with:" .$FName. " " .$LName. " " .$PHON;
Sign up to request clarification or add additional context in comments.

1 Comment

Server error The website encountered an error while retrieving website.co/update.php. It may be down for maintenance or configured incorrectly.
1

Your last statement is wrong:

echo "Database Update with:" .$FName. " " .$LName. " " .$PHON. ;

Should be (without the last dot):

echo "Database Update with:" .$FName. " " .$LName. " " .$PHON ;

If you look in the error log of your webserver, you'll be able to see the error. Another idea could be to turn on errors in PHP in either php.ini or with ini_set("display_errors", 1);. Make sure you only do that on your development system though.

2 Comments

See the other answers for that. Use $_REQUEST['PHONE'] instead of $_POST['PHON']
Also, don't write 'NULL' in the ID field. If it is auto-increment, just don't refer to it: $query = "INSERT INTO ClientTable (FName, LName, PHON) VALUES ('".$FName."','".$LName."','".$PHON."')";
1

you are checking $_POST['PHON'], while in Query string you are passing

https://www.website.com/update.php?FName=asdd&PHONE=4444444444.

Please correct PHONE first. then check

and get it like

$_GET['PHONE']

or

$_REQUEST['PHONE']

1 Comment

Also, it should be get, not post.
1

May be sql error due to quotes (' or ""). To avoid this, you can use something like

    $FName = mysql_real_escape_string($_POST['FName']);
    $FNLame = mysql_real_escape_string($_POST['FLame']);
    $PHON = $_POST['PHON'];

Comments

0

is your username and password correct? default for the majority of localhost is root and no password

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.