Jump to content

[SOLVED] can you spot the error? My INSERT query isn't working!


PHP_Idiot

Recommended Posts

Can anyone spot the error here?

 

The connection is open, and the Print statement shows me that everything is there, but it won't upload to the database.

 

Would be really gratefull for a solution.

 

for ($PN = 1; $PN <= $_POST['PlayerNo']; $PN++) 
{
 ${"MembershipNo$PN"} = $_POST["MembershipNo$PN"];
 ${"Position$PN"} = $_POST["Position$PN"];

$query2 = "INSERT into Results values (`ResultID`, `VenueID`, `MembershipNo`, `Date`, `Position`) VALUES('NULL', '$Venue', '${"MembershipNo$PN"}', '$Date', '${"Position$PN"}')";
$result = mysql_query($con, $db, $query2);

print("$query2");						
}

Well 'NULL' should be NULL (without the quotes) if you want a NULL value rather than a string containing the word NULL.

 

Not sure what you're trying to do with ${"MembershipNo$PN"} $_POST["MembershipNo$PN"] ${"Position$PN"} and $_POST["Position$PN"] but they don't look right to me. However, if your print shows what you expect to see, I assume they're not a problem.

 

unfortunately changing the 'Null' to Null didn't help in getting it into the DB, although it was still a valid comment so thanks for pointing it out.

 

Can you see any other reason why it wouldn't work!

 

PS There is no reported error message jackpf :P

Check the syntax for mysql_query()

I don't use mySQL myself, but looking at the manual the syntax is

resource mysql_query ( string $query [, resource $link_identifier ] )

One mandatory parameter, and a second optional parameter:

 

You're passing three parameters that don't look as though they're in the right order.

$result = mysql_query($con, $db, $query2);

 

 

Yes thanks for that jackpf, I did add it and as I said nothing was reported.

 

Then I re-read the manual and realised I'd added it incorrectly ran it again it found the problem (a really obvious one too) and it's now all fixed :D

 

I'd love to be all miffed at you for your not so polite initial response...but you were correct and I as the name suggests am a php idiot... but learning (not exactely fast, but learning non the less).

 

Thanks for all the responses it is finally working :D :D

 

No need to apologise.

 

Learnt another several new things today, I just sometimes get the feeling I'm learning them in the wrong order...ah well sire MUST be live by tuesday so it's a 'good enough, move on' strategy at the moment.

 

One day I'll get time to straighten things out and learn the 'right' way to do it :D

Yeah, well lesson of the day: always use the mysql_error() function with anything mysql related. Honestly, it's the most useful tool for debugging.

 

And yeah, I know what you mean. I "finished" my site months ago, but I'm still recoding it, improving it and adding new stuff. I recently learnt about classes and stuff, so I'm trying to implement them now :D fun fun fun

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.