www.webdeveloper.com
Results 1 to 4 of 4

Thread: help please with PHP

  1. #1
    Join Date
    Apr 2012
    Posts
    7

    help please with PHP

    could you have a look at the code below and tell me if this is correct, becuase it connect with the server but it does not update the database.

    <?php
    //This sets the database connection
    $db_host = "mysql_";
    $db_username = "";
    $db_password = "";
    $db_database = "";
    $db = mysql_connect ($db_host, $db_username, $db_password);
    Mysql_select_db($db_database, $db);

    //This checks for the values
    if(isset($_POST["txtRunnerID"]) &&
    (isset($_POST["txtEventID"]) &&
    (isset($_POST["txtDateID"]) &&
    (isset($_POST["txtFinishTimeID"]) &&
    (isset($_POST["txtPositionID"])
    (isset($_POST["txtCategoryID"]) &&
    (isset($_POST["txtAgeGradeID"]) &&
    (isset($_POST["txtPersonalBestID"]){

    //Set variable names
    $RunnerID = $_POST['txtRunnerID'];
    $EventID = $_POST['txtEventID'];
    $Date = $_POST['txtDateID'];
    $FinishTime = $_POST['txtFinishTimeID'];
    $Position = $_POST['txtPositionID'];
    $Category = $_POST['txtCategoryID'];
    $AgeGrade = $_POST['txtAgeGradeID'];
    $PersonalBest = $_POST['txtPersonalBestID'];

    //Insert values into Results table
    $query = "INSERT INTO Results
    (txtRunnerID, txtEventID, txtDateID, txtFinishTimeID, txtPositionID, txtCategoryID, txtAgeGradeID, txtPersonalBestID) VALUES ('$RunnerID','$EventID','$Date', '$FinishTime','$Position', '$CategoryID', '$AgeGrade', '$PersonalBest')";
    mysql_query($query);
    ?>

  2. #2
    Join Date
    May 2012
    Posts
    37
    There's a few things you can do on your own to track down the error.

    Do all the $_POST variables have values? If any are not set, your code doesn't run the query. Check with:

    PHP Code:
    print_r($_POST); 
    If it's getting to the query, add:

    PHP Code:
    mysql_query($query) or die(mysql_error()); 
    To see what the error is.

    You could also echo the $query string to see what it looks like populated and before it executes. There might be something MySQL doesn't like about '$var'. Maybe try,
    PHP Code:
    VALUES ('" .  $var . "'
    ...notice the single/double quotes.

    It looks like you might be missing some ")" and the closing "}" for your IF condition... though that would give you a parse error.

    And on a side not in reagards to security, you should be sanitizing any post/get variables before putting them directly in your query - especially since you're using the old mysql drivers.

  3. #3
    Join Date
    May 2012
    Posts
    4
    Thanks for Sharing...

    PHP is one of the fastest growing web scripting languages on the Internet today, and for good reason.

  4. #4
    Join Date
    Apr 2012
    Posts
    7
    thanks for your help.

    z

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles