Jump to content

Archived

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

willwill100

quick sql question

Recommended Posts

is this code valid? because it is rejected with a mysql error

[code]
$sssn = "INSERT INTO '$comp' ('Position') VALUES ('$score') WHERE 'Sail Number' = '$bnum'";
[/code]

if not what is wrong?

thanx

Share this post


Link to post
Share on other sites
I think your looking for

[code]
$sssn = "INSERT INTO `$comp` (`Position`) VALUES ('$score') WHERE `Sail Number` = '$bnum'";
[/code]

are you sure u have a field with a space in in your table? (Sail Number)

Share this post


Link to post
Share on other sites
[code]
$debug = true;
$sssn = "INSERT INTO `$comp` (`Position`) VALUES ('$score') WHERE `Sail Number` = '$bnum'";
if($debug) print $sssn;

mysql_query($sssn) or die ("Unable to insert: " . mysql_error());
[/code]

Replace this code with yours.. and post the output! :)

Share this post


Link to post
Share on other sites
thanx for the debugging help guyys but ive worked out that the problem was much earlier in the program!

i keep getting the error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Will\My Documents\xampp\htdocs\sailing\rescalc.php on line 34

with this code below:

[code]$comp = $_REQUEST['comp'];
$snum = $_REQUEST['sailnum'];
$time = $_REQUEST['time'];

$result = mysql_fetch_array("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'");
[/code]

i would ideally like to stick the first name and last name into separate variables, how can i do this??

Share this post


Link to post
Share on other sites
[code]$comp = $_REQUEST['comp'];
$snum = $_REQUEST['sailnum'];
$time = $_REQUEST['time'];

$result = mysql_fetch_array("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'");[/code]

Can you run the query straight inside the fetch array??? try this

[code]$comp = $_REQUEST['comp'];
$snum = $_REQUEST['sailnum'];
$time = $_REQUEST['time'];
$query=mysql_query("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'");
$result = mysql_fetch_array($query);[/code]


That work better?

Share this post


Link to post
Share on other sites
well i *think* you could run...

$result = mysql_fetch_array(mysql_query("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'"));

The reason it wasn't working the way you did it is because you had not rean a query you was masicaly just doin mysql_fetch_array on the text/string "SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'" instead of on the query results.

Share this post


Link to post
Share on other sites
im having a similar problem again:

this is the code concerned:
[code]
$q= "SELECT * FROM `temp` ORDER BY `score` ASC";
$result = mysql_query ($q) or die('Problem with query: ' . $q . '<br />' . mysql_error());
$count = 1;
while ($row = mysql_fetch_assoc($result)){
$nom=$row['Name'];     

$query = "UPDATE `temp` SET `Position` = '$count' WHERE `name`='$nom'";
$result = mysql_query($query);

$count = $count + 1;
}
[/code]

i get the error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Will\My Documents\xampp\htdocs\sailing\handicapcalc.php on line 30

i would have thought that because i was calling the "fetch_array" from a query this time it would have worked but obviously not. Any help!?!?!

Share this post


Link to post
Share on other sites
Is the line quoted in the error message (line 30) the line you showed in your code snippet?

Ken

Share this post


Link to post
Share on other sites
Variables inside of single quotes are not processed properly as far as I am aware. "SELECT * FROM `table` WHERE `column_name` ='".$variable."'"

Share this post


Link to post
Share on other sites
Actually, in this case:
[code]<?php $query = "UPDATE `temp` SET `Position` = '$count' WHERE `name`='$nom'"; ?>[/code]
the variable is really inside the double quotes and do get translated.
You can prove it for yourself bu putting an [code]<?php echo $query; ?>[/code] on the next line.

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=355702:date=Mar 16 2006, 10:17 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 16 2006, 10:17 PM) [snapback]355702[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Is the line quoted in the error message (line 30) the line you showed in your code snippet?

Ken
[/quote]

As the error message concerns "mysql_fetch_array" and the snippet uses "mysql_fetch_assoc" then I think ken's question is very relevant.

Share this post


Link to post
Share on other sites

×

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.