Jump to content

quick sql question


willwill100

Recommended Posts

[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! :)
Link to comment
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??
Link to comment
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?
Link to comment
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.
Link to comment
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!?!?!
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.