Jump to content


Photo

quick sql question


  • Please log in to reply
13 replies to this topic

#1 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 14 March 2006 - 04:36 PM

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

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

if not what is wrong?

thanx

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 14 March 2006 - 05:20 PM

I think your looking for

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

are you sure u have a field with a space in in your table? (Sail Number)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 14 March 2006 - 08:11 PM

$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());

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

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#4 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 15 March 2006 - 04:47 PM

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:

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

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

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

#5 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 15 March 2006 - 05:02 PM

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

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

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

$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);


That work better?
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#6 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 15 March 2006 - 05:12 PM

sorted! thanx.

is there any reason that it works like that or is it just a random feature??

#7 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 15 March 2006 - 05:37 PM

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.
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#8 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 March 2006 - 07:46 PM

im having a similar problem again:

this is the code concerned:
$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;
}

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!?!?!

#9 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 March 2006 - 09:53 PM

no1?? please could someone give me a hand; it is much needed, lol!!

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 March 2006 - 10:17 PM

Is the line quoted in the error message (line 30) the line you showed in your code snippet?

Ken

#11 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 17 March 2006 - 05:33 AM

Variables inside of single quotes are not processed properly as far as I am aware. "SELECT * FROM `table` WHERE `column_name` ='".$variable."'"

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#12 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 05:52 AM

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

Ken

#13 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 17 March 2006 - 07:55 AM

Learn something new everyday. :-)

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#14 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 17 March 2006 - 10:04 AM

[!--quoteo(post=355702:date=Mar 16 2006, 10:17 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 16 2006, 10:17 PM) View Post[/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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users