willwill100 Posted March 14, 2006 Share Posted March 14, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/ Share on other sites More sharing options...
shocker-z Posted March 14, 2006 Share Posted March 14, 2006 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) Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17427 Share on other sites More sharing options...
keeB Posted March 14, 2006 Share Posted March 14, 2006 [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! :) Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17506 Share on other sites More sharing options...
willwill100 Posted March 15, 2006 Author Share Posted March 15, 2006 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 34with 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?? Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17855 Share on other sites More sharing options...
shocker-z Posted March 15, 2006 Share Posted March 15, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17860 Share on other sites More sharing options...
willwill100 Posted March 15, 2006 Author Share Posted March 15, 2006 sorted! thanx. is there any reason that it works like that or is it just a random feature?? Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17863 Share on other sites More sharing options...
shocker-z Posted March 15, 2006 Share Posted March 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17875 Share on other sites More sharing options...
willwill100 Posted March 16, 2006 Author Share Posted March 16, 2006 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 30i 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!?!?! Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18095 Share on other sites More sharing options...
willwill100 Posted March 16, 2006 Author Share Posted March 16, 2006 no1?? please could someone give me a hand; it is much needed, lol!! Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18132 Share on other sites More sharing options...
kenrbnsn Posted March 16, 2006 Share Posted March 16, 2006 Is the line quoted in the error message (line 30) the line you showed in your code snippet?Ken Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18143 Share on other sites More sharing options...
txmedic03 Posted March 17, 2006 Share Posted March 17, 2006 Variables inside of single quotes are not processed properly as far as I am aware. "SELECT * FROM `table` WHERE `column_name` ='".$variable."'" Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18258 Share on other sites More sharing options...
kenrbnsn Posted March 17, 2006 Share Posted March 17, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18264 Share on other sites More sharing options...
txmedic03 Posted March 17, 2006 Share Posted March 17, 2006 Learn something new everyday. :-) Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18289 Share on other sites More sharing options...
Barand Posted March 17, 2006 Share Posted March 17, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18302 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.