KillerBeeZ Posted May 29, 2012 Share Posted May 29, 2012 been looking over this script, which is part of a larger script, and so far I can't figure out why it is not saving the data to the sql database. It seems like some small stupid thing I'm overlooking but if so I cannot seem to find it... it should take 4 values, manipulate them, then average them out and save the result to sql, that result (there are 10 passes to this script) is then added upon itself until in the end there are a few fairly large numbers. This is for a racing game $residual1 2 3 and 4 all do end up with data, the problem is its not stacking due to the fact that its not saving to sql <? $residual1 = mysql_result($resultd,0,"s1-1st"); $residual2 = mysql_result($resultd,0,"s1-2nd"); $residual3 = mysql_result($resultd,0,"s1-3rd"); $residual4 = mysql_result($resultd,0,"s1-4th"); $powcal1 = ($car1stat_pow - (($tpow) - 15) + rand(1, 30)); $hancal1 = ($car1stat_han - (($than) - 15) + rand(1, 30)); $acccal1 = ($car1stat_acc - (($tacc) - 15) + rand(1, 30)); $brkcal1 = ($car1stat_brk - (($tbrk) - 15) + rand(1, 30)); $totcal1 = (($powcal1 + $hancal1 + $acccal1 + $brkcal1) / 4); $residual1 = ($residual1 + $totcal1); $resid1 = "UPDATE racedata SET s1-1st = '$residual1' "; mysql_query($resid1); $powcal2 = ($car2stat_pow - (($tpow) - 15) + rand(1, 30)); $hancal2 = ($car2stat_han - (($than) - 15) + rand(1, 30)); $acccal2 = ($car2stat_acc - (($tacc) - 15) + rand(1, 30)); $brkcal2 = ($car2stat_brk - (($tbrk) - 15) + rand(1, 30)); $totcal2 = (($powcal2 + $hancal2 + $acccal2 + $brkcal2) / 4); $residual2 = ($residual2 + $totcal2); $resid2 = "UPDATE racedata SET s1-2nd = '$residual2' "; mysql_query($resid2); $powcal3 = ($car3stat_pow - (($tpow) - 15) + rand(1, 30)); $hancal3 = ($car3stat_han - (($than) - 15) + rand(1, 30)); $acccal3 = ($car3stat_acc - (($tacc) - 15) + rand(1, 30)); $brkcal3 = ($car3stat_brk - (($tbrk) - 15) + rand(1, 30)); $totcal3 = (($powcal3 + $hancal3 + $acccal3 + $brkcal3) / 4); $residual3 = ($residual3 + $totcal3); $resid3 = "UPDATE racedata SET s1-3rd = '$residual3' "; mysql_query($resid3); $powcal4 = ($car4stat_pow - (($tpow) - 15) + rand(1, 30)); $hancal4 = ($car4stat_han - (($than) - 15) + rand(1, 30)); $acccal4 = ($car4stat_acc - (($tacc) - 15) + rand(1, 30)); $brkcal4 = ($car4stat_brk - (($tbrk) - 15) + rand(1, 30)); $totcal4 = (($powcal4 + $hancal4 + $acccal4 + $brkcal4) / 4); $residual4 = ($residual4 + $totcal4); $resid4 = "UPDATE racedata SET s1-4th = '$residual4' "; mysql_query($resid4); ?> Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/ Share on other sites More sharing options...
livethedead Posted May 29, 2012 Share Posted May 29, 2012 $resid3 = "UPDATE racedata SET s1-3rd = '{$residual3}' "; You need to concatenate your variables within the query {} else its just a string. Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349666 Share on other sites More sharing options...
KillerBeeZ Posted May 29, 2012 Author Share Posted May 29, 2012 please help me understand why that one has to be like that but this one works just fine? $querytimer1 = "UPDATE races SET rtimer = '$rtimer' WHERE track = '$Track' "; Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349669 Share on other sites More sharing options...
livethedead Posted May 29, 2012 Share Posted May 29, 2012 All your variables within your queries need to be concatenated. Whats being stored in your database is the literal string "$whatever". You're query string is no different from a normal string if you want to think of it like that. x = "blah"; echo "something = '$x' somethingelse"; //returns something = '$x' somethingelse echo "something = {$x} somethingelse"; //returns something = blah somethingelse; //you can also concatenate like this echo "blah" . $someVar . "blah blah"; //both work Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349674 Share on other sites More sharing options...
Pikachu2000 Posted May 30, 2012 Share Posted May 30, 2012 The variable in the query string is just fine the way it's posted in the OP. I suspect the problem is being caused by the hyphens in your field names being interpreted as mathematical operators. Add or die( mysql_error() ) to the query execution and see what errors are returned. Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349685 Share on other sites More sharing options...
KillerBeeZ Posted May 30, 2012 Author Share Posted May 30, 2012 I saw that last night but the board was down or something and couldn't post. I just removed the - in the whole darn thing. Curious though, could I also just use an escape \? such as $residual1 = mysql_result($resultd,0,"s1\-1st"); Also, on another note, I'm trying to insert an image where the url is stored in sql. $qcar1image = "SELECT image FROM cars WHERE year = '$a1yr' AND make = '$a1mk' AND model = '$a1md'"; $car1image = mysql_query($qcar1image); getting that old Resource id #13 and such errors. All the variables are filled with the correct data so it makes me think I have a syntax error Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349888 Share on other sites More sharing options...
KillerBeeZ Posted May 30, 2012 Author Share Posted May 30, 2012 ok it might be that the url has a - in it. I need to leave it like it is however, is there a way in php to call that url as it is without any kind of need for escape or changing the images? http://www.ctlinx.com/piwigo/upload/2012/05/24/20120524171350-684011fb.jpg I cannot ask the people entering in the data to use a \ in the address, they won't understand in C# you could do this with @ I think Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349924 Share on other sites More sharing options...
KillerBeeZ Posted May 30, 2012 Author Share Posted May 30, 2012 took the - out of the image, tested it and its the same, so thats not it... any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349940 Share on other sites More sharing options...
Pikachu2000 Posted May 30, 2012 Share Posted May 30, 2012 You're going to need to post more of the code. The less context, the harder it is to figure out. Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349948 Share on other sites More sharing options...
KillerBeeZ Posted May 30, 2012 Author Share Posted May 30, 2012 there are over 800 lines of code in several files... what parts do you think I should post? Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349953 Share on other sites More sharing options...
Pikachu2000 Posted May 31, 2012 Share Posted May 31, 2012 You'll have to figure out what parts are relevant to the problem, and post them. Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349983 Share on other sites More sharing options...
KillerBeeZ Posted May 31, 2012 Author Share Posted May 31, 2012 I'll try This is the section of the race engine file in question <table width="100%" border="1" cellspacing="2" cellpadding="2"> <tr> <th><div align="center">Rank</div></th> <th><div align="center">Image</div></th> <th>Player, Car, Score</th> </tr> <tr> <? $qcar1image = "SELECT image FROM cars WHERE year = '$a1yr' AND make = '$a1mk' AND model = '$a1md'"; $qcar2image = "SELECT image FROM cars WHERE year = '$a2yr' AND make = '$a2mk' AND model = '$a2md'"; $qcar3image = "SELECT image FROM cars WHERE year = '$a3yr' AND make = '$a3mk' AND model = '$a3md'"; $qcar4image = "SELECT image FROM cars WHERE year = '$a4yr' AND make = '$a4mk' AND model = '$a4md'"; $car1image = mysql_query($qcar1image); $car2image = mysql_query($qcar2image); $car3image = mysql_query($qcar3image); $car4image = mysql_query($qcar4image); $ranks = array("<div align=\"center\"><img src=\"$car1image\"width=\"50\" height=\"50\"></div></p></td><td>$car1player in the $a1yr $a1mk $a1md" => "$residual1", "<div align=\"center\"><img src=\"$car2image\"width=\"50\" height=\"50\"></div></p></td><td>$car2player in the $a2yr $a2mk $a2md" => "$residual2", "<div align=\"center\"><img src=\"$car3image\"width=\"50\" height=\"50\"></div></p></td><td>$car3player in the $a3yr $a3mk $a3md" => "$residual3", "<div align=\"center\"><img src=\"$car4image\"width=\"50\" height=\"50\"></div></p></td><td>$car4player in the $a4yr $a4mk $a4md" => "$residual4"); arsort($ranks); $ri = 1; foreach ($ranks as $key => $val) { echo "</tr><td><div align=\"center\">$ri</div></td>"; echo "<td>$key = $val\n</td><tr>"; $ri++; } mysql_close(); ?> </tr> </table> I know there is a better way to get the sql data than to use 4 different queries, but this is only a draft while I learn php. My native language is C# and never got around to working with sql. I will clean up the code once it is working properly. This is the row from the sql database I'm trying to call (I apologize, I will likely never get it to line up correctly on here) year make model class cost image description bodytrim horsepower topspeed cd height width weight hwympg citympg pow han acc brk acnt 2003 Dodge Grand Caravan SE fwd D 4550 http://www.ctlinx.com/piwigo/upload/2012/05/24/201... a mini van with a good bit of acceleration and pow... Van 180 109 0.35 68.9 78.6 3991 24 17 50 30 65 14 KillerBeeZ This is the section that calls the data from yet another sql database that is needed in order to know which car to select... $co = 0; $car1player = mysql_result($resultr,$co,"player"); $car1vin = mysql_result($resultr,$co,"vin"); $car1stat_pow = mysql_result($resultr,$co,"totpow"); $car1stat_han = mysql_result($resultr,$co,"tothan"); $car1stat_acc = mysql_result($resultr,$co,"totacc"); $car1stat_brk = mysql_result($resultr,$co,"totbrk"); $a1yr = mysql_result($resultr,$co,"year"); $a1mk = mysql_result($resultr,$co,"make"); $a1md = mysql_result($resultr,$co,"model"); all of that gets its data from this row in sql player vin year make model engine-vin trans-vin weightmod-vin aero-vin totpow tothan totacc totbrk KillerBeeZ 1234567890 2000 Dodge Grand Caravan SE fwd oem12345 oem12345 oem12345 12345 50 30 87 14 If I forgot something just let me know and I'll add it too. There really is a lot of code to go over Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1349988 Share on other sites More sharing options...
KillerBeeZ Posted June 2, 2012 Author Share Posted June 2, 2012 http://www.ctlinx.com/org/panprix/races/raceengine.php this is the test page I made to debug this issue... if that helps at all. The race will start when the pending race hits the current time and the page will refresh every minute (or refresh manually) The images of the cars are entered manually but you will see the (resource id #**) error in the line below the pending races and above the current race (if a current race is active) will look like "Resource id #19 , 2000 , Dodge , Grand Caravan SE fwd " when a race is current or "Resource id #13 , , , " when its not active. I'd really like to find the answer to this, I know you guys (and gals) are busy and have better things to do than help others solve their problems, but I'd be very grateful for any insight you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1350459 Share on other sites More sharing options...
Pikachu2000 Posted June 2, 2012 Share Posted June 2, 2012 You're trying to echo a query result resource, which is what you get from mysql_query(). You need to fetch the data from the result resource with one of the mysql_fetch_*() functions, such as mysql_fetch_assoc. Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1350472 Share on other sites More sharing options...
KillerBeeZ Posted June 3, 2012 Author Share Posted June 3, 2012 it took me a while to figure it out but I got it, thank you very much you are extremely helpful Quote Link to comment https://forums.phpfreaks.com/topic/263354-update-sql-php-troubleshooting/#findComment-1350761 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.