/    Sign up×
Community /Pin to ProfileBookmark

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);
?>

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@g0dzuki99May 18.2012 — 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:

[code=php]print_r($_POST);[/code]

If it's getting to the query, add:

[code=php]mysql_query($query) or die(mysql_error());[/code]
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,
[code=php]VALUES ('" . $var . "')[/code]
...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.
Copy linkTweet thisAlerts:
@cheochiMay 21.2012 — Thanks for Sharing...

PHP is one of the fastest growing web scripting languages on the Internet today, and for good reason.
Copy linkTweet thisAlerts:
@zakariyyaauthorMay 28.2012 — thanks for your help.

z
×

Success!

Help @zakariyya spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...