Davie33 Posted March 1, 2015 Share Posted March 1, 2015 (edited) Hi guys hoping you can help with this code of mine. I seem to be getting an error ,i know its the query but tried a few to fix it without joy. <?php $catcheck = yasDB_select("SELECT `name` FROM `categories` WHERE `id` = " . $row['category']); $catname = $catcheck->fetch_array(MYSQLI_ASSOC); if ($setting['seo']=='yes') { ?> <a href="<?php echo $setting['siteurl'];?>category/<?php echo $row['category'];?>/1.html" title="<?php echo ucfirst($catname['name']);?>"><?php echo ucfirst($catname['name']);?></a> <?php } else { ?> <a href="<?php echo $setting['siteurl'];?>index.php?act=cat&id=<?php echo $row['category'];?>" title="<?php echo ucfirst($catname['name']);?>"><?php echo ucfirst($catname['name']);?></a> <?php } ?> this is the line thats causing the error. $catcheck = yasDB_select("SELECT `name` FROM `categories` WHERE `id` = " . $row['category']); error Error No: 0 - MySQL error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Query: "SELECT `name` FROM `categories` WHERE `id` = " #0 /public_html/arcade/templates/minix_25/game.php(236): yasDB_select('SELECT `name` F...') #2 {main} Edited March 1, 2015 by Davie33 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 1, 2015 Share Posted March 1, 2015 $row['category'] is used in your query to return records from your table where the id matches. Problem is $row['category'] is not populating the query with a value as shown in the error message (query highlighted in red) Error No: 0 - MySQL error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Query: "SELECT `name` FROM `categories` WHERE `id` = " <-- no value provide for id resulting in the error above #0 /public_html/arcade/templates/minix_25/game.php(236): yasDB_select('SELECT `name` F...') #2 {main} Wherw is $row['category'] defined? Are you sure that is the correct variable to use in the query? Quote Link to comment Share on other sites More sharing options...
Davie33 Posted March 1, 2015 Author Share Posted March 1, 2015 (edited) It not my code i had it made for me that's why i posted on here for help am kinda lost with it. Sry am not an expert on php . How can i fix it ?. Edited March 1, 2015 by Davie33 Quote Link to comment Share on other sites More sharing options...
maxxd Posted March 1, 2015 Share Posted March 1, 2015 What's the surrounding code? Given the variable name $row, it's possible the code is trying to run the select query inside a loop, which isn't a good idea. If that is what's actually happening, you're probably going to want to rework the initial query to use a join in order to bring back the entire record set with a single call to the database. Quote Link to comment Share on other sites More sharing options...
Davie33 Posted March 1, 2015 Author Share Posted March 1, 2015 (edited) Hi what am looking for is when i go to the game page that code above is to give the name of the category the game is from. For some reason the code does work but still give out the error as thats whats on my site atm is that code. Check my link below then go to the main game page on any game you will see the name of the cat the game is from. Edited March 1, 2015 by Davie33 Quote Link to comment Share on other sites More sharing options...
maxxd Posted March 1, 2015 Share Posted March 1, 2015 Right, and that's why we're asking you to supply the surrounding code. $row['category'] either isn't being set, or it's being set incorrectly. However, without the surrounding code, there's no way to tell where, how, or why. Quote Link to comment Share on other sites More sharing options...
Davie33 Posted March 1, 2015 Author Share Posted March 1, 2015 Am not to sure but i think this has solved it. <?php $catcheck = yasDB_select("SELECT `name` FROM `categories` WHERE `id` = " . $row['category']); $catname = $catcheck->fetch_array(MYSQLI_ASSOC); if ($id = $row['category']) { if ($setting['seo']=='yes') { ?> <a href="<?php echo $setting['siteurl'];?>category/<?php echo $row['category'];?>/1.html" onMouseover="showhint('<b><?php echo ucfirst($catname['name']);?></b>',this, event, 'auto')"><?php echo ucfirst($catname['name']);?></a> <?php } else { ?> <a href="<?php echo $setting['siteurl'];?>index.php?act=cat&id=<?php echo $row['category'];?>" onMouseover="showhint('<b><?php echo ucfirst($catname['name']);?></b>',this, event, 'auto')"><?php echo ucfirst($catname['name']);?></a> <?php } } ?> Quote Link to comment Share on other sites More sharing options...
Davie33 Posted March 1, 2015 Author Share Posted March 1, 2015 Fook me i already fixed it on another file thanks guys for the help anyway. I really thought i had lost the file that i fixed . Quote Link to comment 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.