richarro1234 Posted September 11, 2007 Share Posted September 11, 2007 ... i need your help again. i have this piece of code tat is meant to get the id from the address bar and show the relevant info from the database. It works on my other pages, but it doesnt work on this one, the code has been copied over and it still doesnt work. it doesnt even show the empty grid where the text is meant to be. i cant find the problem maybe someone on here can. Here is the code: <? require("header.php")?> <? include("data.php"); //include("funktioner.php"); mysql_connect($server,$anvandare, $losen); mysql_select_db($databas); $cid = $_GET['id']; ?> <? $query = mysql_query("SELECT * from recipes WHERE id = $cid"); while ($rec = mysql_fetch_array($query)) { ?> <center> <?=$note?></center> <br> <div align="left"> <table border="1" cellpadding="0" cellspacing="1" style="border-collapse: collapse" width="95%" id="AutoNumber1" bordercolor="#000000" bgcolor="#252525"> <tr> <td width="95%"> <center> <center> <div align="center"> <center> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#5D6765" width="75%" id="AutoNumber1" bgcolor="#131313"> <tr> <td width="100%" bgcolor="#000000" align="center"><font size="2"><b>All Recipes</b></font></td> </tr> <tr> <td width="100%"><br> <div align="left"> <center> <table bgcolor=333333 width=50%> <tr> <td width=50% class=trnext> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="25%" align="center">Name: </td> <td width="100%"><?=$rec['name']?></td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="25%" align="center">Ingrediants: </td> <td width="100%"><?=$rec['ingrediants']?></td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="100%" align="center">Method: </td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="100%"><?=$rec['method']?></td> </tr> </table> </td> </tr> </table> </center> </div><BR><BR> </td> </tr> </table> </center> </div> <?}?> Thanks Rich Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted September 11, 2007 Share Posted September 11, 2007 Trun on all error reporting. Will this give you an error of some type? First of all, I don't understand why you use the short php tags, "<? ?>". There is NO reason to ever use them. If you don't know why you might have to check it out on google. This causes the code thing you inserted in to NOT highlight the code. Which IS annoying LIKE this. Quote Link to comment Share on other sites More sharing options...
AdRock Posted September 11, 2007 Share Posted September 11, 2007 What are these? <?=$note?> <?=$rec['name']?> <?=$rec['ingrediants']?> <?=$rec['method']?> If you want to display these values if they are in the database you need to echo them <?php echo $rec['method']; ?> I've tidied up the code slightly but you should try validating you HTML cos i'm sure some of it's depricated <?php require("header.php"); include("data.php"); //include("funktioner.php"); mysql_connect($server,$anvandare, $losen); mysql_select_db($databas); $cid = $_GET['id']; $query = mysql_query("SELECT * from recipes WHERE id = '$cid'"); while ($rec = mysql_fetch_array($query)) { ?> <center> <?php =$note ?></center> <br> <div align="left"> <table border="1" cellpadding="0" cellspacing="1" style="border-collapse: collapse" width="95%" id="AutoNumber1" bordercolor="#000000" bgcolor="#252525"> <tr> <td width="95%"> <center> <center> <div align="center"> <center> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#5D6765" width="75%" id="AutoNumber1" bgcolor="#131313"> <tr> <td width="100%" bgcolor="#000000" align="center"><font size="2"><b>All Recipes</b></font></td> </tr> <tr> <td width="100%"><br> <div align="left"> <center> <table bgcolor=333333 width=50%> <tr> <td width=50% class=trnext> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="25%" align="center">Name: </td> <td width="100%"><?php echo $rec['name']; ?></td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="25%" align="center">Ingrediants: </td> <td width="100%"><?php echo $rec['ingrediants']; ?></td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="100%" align="center">Method: </td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="100%"><?php echo $rec['method']; ?></td> </tr> </table> </td> </tr> </table> </center> </div><BR><BR> </td> </tr> </table> </center> </div> <?php } ?> Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted September 11, 2007 Share Posted September 11, 2007 adrock you are wrong the <?=$note?> <?=$rec['name']?> <?=$rec['ingrediants']?> <?=$rec['method']?> Are short php tags to echo variables. You need to set a special setting on your server to use them. I WILL REPEAT, DO NOT USE THOSE OR <? ?> Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted September 11, 2007 Author Share Posted September 11, 2007 <?php require("header.php"); include("data.php"); //include("funktioner.php"); mysql_connect($server,$anvandare, $losen); mysql_select_db($databas); $cid = $_GET['id']; $query = mysql_query("SELECT * from recipes WHERE id = '$cid'"); while ($rec = mysql_fetch_array($query)) { ?> <center> <?php =$note ?></center> <br> <div align="left"> <table border="1" cellpadding="0" cellspacing="1" style="border-collapse: collapse" width="95%" id="AutoNumber1" bordercolor="#000000" bgcolor="#252525"> <tr> <td width="95%"> <center> <center> <div align="center"> <center> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#5D6765" width="75%" id="AutoNumber1" bgcolor="#131313"> <tr> <td width="100%" bgcolor="#000000" align="center"><font size="2"><b>All Recipes</b></font></td> </tr> <tr> <td width="100%"><br> <div align="left"> <center> <table bgcolor=333333 width=50%> <tr> <td width=50% class=trnext> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="25%" align="center">Name: </td> <td width="100%"><?php echo $rec['name']; ?></td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="25%" align="center">Ingrediants: </td> <td width="100%"><?php echo $rec['ingrediants']; ?></td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="100%" align="center">Method: </td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#252525" width="100%" id="AutoNumber12"> <tr> <td width="100%"><?php echo $rec['method']; ?></td> </tr> </table> </td> </tr> </table> </center> </div><BR><BR> </td> </tr> </table> </center> </div> <?php } ?> Hey i tried your code and to start with it came up with an error sayin " Parse error: syntax error, unexpected '=' in D:\wamp\www\mum\recipe.php on line 14 " so i got rid of the <?php =$note ?> and that got rid of the msg, but it still didnt show up any of the results. Thanks Rich Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 11, 2007 Share Posted September 11, 2007 I would bet monney that there is a problem with one of your database commands. You should add an OR DIE clause to each to verify they are working correctly: <?php mysql_connect($server,$anvandare, $losen) OR die (mysql_erro()); mysql_select_db($databas OR die (mysql_erro()); $cid = $_GET['id']; $query = mysql_query("SELECT * from recipes WHERE id = $cid OR die (mysql_erro()); ?> You also should verify that $_GET['id'] actually has a value and does not contain sql code. Otherwise you are leaving yourself open for hacking Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted September 11, 2007 Author Share Posted September 11, 2007 just tried your code and i got this msg. "Parse error: syntax error, unexpected ';' in D:\wamp\www\mum\recipe.php on line 5" Thanks Rich Quote Link to comment Share on other sites More sharing options...
Aeglos Posted September 11, 2007 Share Posted September 11, 2007 The closing double quote is missing at the mysql_query() statement in mjdamato's code. Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted September 11, 2007 Author Share Posted September 11, 2007 Parse error: syntax error, unexpected T_STRING in D:\wamp\www\mum\recipe.php on line 13 Thanks Rich Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 try <?php $link = mysql_connect($server,$anvandare, $losen); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($databas);//corrected (yet missing an "e") if (!$db_selected) { die ("Can't use selected Database: " . mysql_error()); } $cid = (int)$_GET['id']; //added a basic filter(i assume this is a int) $query = mysql_query("SELECT * from recipes WHERE id = $cid") OR die(mysql_error());//corrected ?> EDIT: updated error handlering (easier to read i hope) of course you can use mysql_connect($server,$anvandare, $losen) or die(mysql_error()); as used on the "mysql_query" line.. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 11, 2007 Share Posted September 11, 2007 just tried your code and i got this msg. "Parse error: syntax error, unexpected ';' in D:\wamp\www\mum\recipe.php on line 5" Thanks Rich My signature states "I do not always test the code I provide, so there may be some syntax errors.". MadTechie has a similar statement. Unless you are asking us to write all the code for you (in which case you should be posting in the Freelancing forum) you should be able to correct those errors yourself. If you can't find and fix a simple syntax error then I highly suggest you read up on the basics. I don't mean that as a put down or snide remark. But, knowing proper syntax will allow you to solve 90% of any problems you encounter. Those are the easiest however. Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted September 11, 2007 Author Share Posted September 11, 2007 hey, i tried your code but it still doesnt show anything up on the page. here is the link that it is supposed to show up on. http://lilysretreat.richsprivatesite.com/recipe.php?id=1 Thats the link and this is what it is supposed to show. http://lilysretreat.richsprivatesite.com/recipelist.php I added it on there just so i can show you what it is meant to show up when using id 1. I had sorted the code but i didnt read your sig so i didnt see it. i only posted it so you knew there was a syntax error (im sure you dont care that there is a syntax error, but i didnt think of that this morning either). Thanks Rich Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted September 11, 2007 Author Share Posted September 11, 2007 (couldnt find the edit button) After abit of looking around through the code again and re-organising and changing of the database it finally works. Thanks to everyone who helped me find the problem. Thanks Rich P.S sorry i couldnt find the edit button. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 11, 2007 Share Posted September 11, 2007 Ok, found your problem. The id of that recipe is 2 not 1! You were apparently using the wrong input. Here is the corrected link: http://lilysretreat.richsprivatesite.com/recipe.php?id=2 Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted September 11, 2007 Author Share Posted September 11, 2007 Oh dear, i could have saved myself alot of time if i had just looked t the databse, but i was certain that there was no other info prior to me making the database. I feel so silly lol. Thanks Rich 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.