/    Sign up×
Community /Pin to ProfileBookmark

Having some trouble

[code=php]$trlocation = $_POST[location];
$locno = $_POST[locno];
$traid = $_POST[traid];
$type = $_POST[type];
$owner = $_POST[owner];
$notes = $_POST[notes];
$username = $_SESSION[username];
$filename = $uploadFilename;

$db->query(“INSERT INTO uploads (Location, Locno, Traid, Date, Type, Owner, Notes, author, filename)
VALUES (‘$trlocation’,’$locno’,’$traid’, now(), ‘$type’,’$owner’, ‘$notes’, ‘$username’,’$filename’)”);[/code]

This is the part of an upload script where it adds the upload form data into the database. The file is uploaded, but it doesn’t add the data.

I cant seem to find a decent validator. Can someone point out if ive made some kind of awful error.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SyncUpSolutionsDec 05.2010 — Post the code of the $db class.
Copy linkTweet thisAlerts:
@eval_BadCode_Dec 05.2010 — I'm not entirely sure you can do this:

$trlocation = $_POST[location];

I think you need quotations inside of the array like this:

$trlocation = $_POST['location'];

Another thing to point out is that if it's not working, then it's probably going to give you an error... turn error reporting on if it isn't.

I don't think you can have a column name be a keyword so this:

Date... doesn't make sense.

$uploadFilename isn't declared anywhere (show the whole script).

$db->query could mean any number of things, is the $db object documented?

Here is a validation script for your query:

Replace $link with your sql connection variable (most people call it $con or $link).
[code=php]
echo mysql_errno($link) . ": " . mysql_error($link). "n";
[/code]

Put it behind your query. If its working you'll get "0: 0" for output.

Depending on your trust relationship with your users, you may also want to validate the variables before you execute a query that uses them (type cast).

Those are the only things I would change.
Copy linkTweet thisAlerts:
@Not_to_mentionauthorDec 06.2010 — It isnt returning an error, and i know that $db and $uploadFilename work.Ill check the others. Thanks!
×

Success!

Help @Not_to_mention 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,
)...