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.
//This sets the database connection
$db_host = "mysql_";
$db_username = "";
$db_password = "";
$db_database = "";
$db = mysql_connect ($db_host, $db_username, $db_password);
//This checks for the values
//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')";
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:
If it's getting to the query, add:
To see what the error is.
mysql_query($query) or die(mysql_error());
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,
...notice the single/double quotes.
VALUES ('" . $var . "')
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.
Thanks for Sharing...
PHP is one of the fastest growing web scripting languages on the Internet today, and for good reason.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)