Jump to content

fife

Members
  • Posts

    381
  • Joined

  • Last visited

Everything posted by fife

  1. Hi I have a question about a function someone gae to me. When Im inserting data into the database from a form I always follow the same format. for example let say I have name, description number... if(isset($_POST['submit_member'])){ //trim $name = trim($_POST['name']); $description = trim($_POST['description']); $number = trim($_POST['number']); //check for errors $errors = array(); if(empty($name)) { $errors[] = "Please enter a name"; } if(empty($description)) { $errors[] = "Please enter a description"; } //mysql_real_escape_string! $name = mysql_real_escape_string($name); $description = mysql_real_escape_string($description ); $number = mysql_real_escape_string($number); then the insert into the database here ...... now if you have a lot of fields you will be repeating yourself constantly. On this basis my friend gave me this code... foreach ($_POST as $key => $value) { $$key=trim(mysql_real_escape_string(($value)); } The first question is... is my friend right and should it be written this way. The second question is what would the the data come out like eg $_POST['name']; $_POST['description']; Would they come out like.... $name $description ??????
  2. I see. I have now changed the code so the loop is kept separate. Still its still not working. I know there is less than 4 results from a count. I now have an if statement and a separate query for the more button. My if statement seems to be printing the more button even though the result of the query is less than 4. <?php for($i = 0; ($ClubDetails1 = mysql_fetch_assoc($ClubDetails)) && $i < 2; $i++ ){ ?> <tr> <th scope="col"></th> <th scope="col"><?php echo $ClubDetails1['name']; ?></th> <?php } $qMyClubA = mysql_query("SELECT memberID FROM clubs WHERE memberID =".$User['memberID'].""); $num = mysql_fetch_array($qMyClubA); if (count($num)>4) { "<th scope=\"col\"><a href=\"index.php\"> More </a> </th>"; } else{ echo" ";} ?>
  3. I thought that might be the case. The thing is im trying to limit the amount to 2 but at the same time if the total count is greater than 2 in the first place to echo a more button. Ive even tried; <?php for($i = 0; ($ClubDetails1 = mysql_fetch_assoc($ClubDetails)) && $i < 2; $i++ ){ ?> <tr> <th scope="col"></th> <th scope="col"><?php echo $ClubDetails1['name']; ?></th> <?php for($i = 0; ($ClubDetails1 = mysql_fetch_assoc($ClubDetails)) && $i > 2; $i++ ) { echo "<th scope=\"col\"><a href=\"index.php\"> More </a> </th>"; } ?> </tr> <?php } ?> But obviously its not working either. What do I need to read about to do this or does anybody know of any examples I can learn from?
  4. I have a while loop that works fine but when I add an if condition within the loop it does not echo the if condition. I'm trying to echo an extra row in the table if the number of clubs returned is > 2 <?php for($i = 0; ($ClubDetails1 = mysql_fetch_assoc($ClubDetails)) && $i < 2; $i++){ ?> <tr> <th scope="col"></th> <th scope="col"><?php echo $ClubDetails1['name']; ?></th> <?php if ($i > 2) { echo "<th scope=\"col\"><a href=\"club_page.php\"> More </a> </th>"; } ?> </tr> <?php } ?>
  5. cool ok thank you for the advise. Both of you. I will change the way I do that from now on.
  6. can you explain please?
  7. Skepsis Thank you it works. The table is album not albums so your changes to my code were correct
  8. infact im wrong. If i try to echo echo $AlbumNameq = mysql_query("SELECT * FROM albums WHERE id = '{$row_rs_images['album']}'"); $AlbumName = mysql_fetch_array($AlbumNameq); nothing happens
  9. basically i have a photo table. With in that table there is an album ID. Im passing that on to the query to return the album name to display that as no one wants to see the id.
  10. still the query comes back empty The $row_image loops perfectly but the $AlbumName is just blank. Ive echoed bother the queries and they are working. Its just once it loops it seems to ignore the $AlbumName
  11. I dont get any errors. It runs through the loop fine for all items called $row_image but ignores the $AlbumName. It just leaves it blank.
  12. I have a loop which works fine but before the loop I run a query which I store as $AlbumName From this array and within the loop I want to echo $AlbumName['album_name']; but obvisouly its not working. Can somebody please show me how to do it? <?php $qImage = "SELECT * FROM photos"; $rImage = mysql_query($qImage); $Array = mysql_fetch_array($rImage); $qAlbumName = "SELECT * FROM albums WHERE id =".$Array['album'].""; $rAlbumName = mysql_query($qAlbumName); $AlbumName = mysql_fetch_array($rAlbumName); while ($row_images = mysql_fetch_assoc($rImage) ) { ?> <?php echo $row_images['id']; echo $row_images['name']; echo $row_images['photo_description']; echo $AlbumName['album_name']; } ?>
  13. actual I didnt ask the whole question there. I ment with mulitple uploads from one script.
  14. Hi does anybody know of any good image uploader tuts out there for the beginner?
  15. I have a select field in my join form which allows users to select one of my speicifed counties. In the table the county is link to a country. I am trying to echo in a select statement a loop of all the available counties in england. here is the code <?php $qGetCounty = "SELECT * FROM Counties"; $rGetCounty = mysql_query($qGetCounty); echo " <select name=\"County\"> <optgroup label=\"England\"> "; while ($county = mysql_fetch_assoc($rGetCounty)){ if($county['country']=='England') { echo " <option value= '{$county['county']}'>{$county['county']}</option> "; }} echo " <optgroup label=\"Wales\"> "; while ($county=='Wales'){ echo " <option value= '{$county['county']}'>{$county['county']}</option> "; } echo " <optgroup label=\"Scotland\"> "; while ($county=='Scotland'){ echo " <option value= '{$county['county']}'>{$county['county']}</option> "; } echo " </select> " ; ?> It is not erroring but also it is not worlking correctly. It shows all the counties in England and both the labels for scotland and wales but does not show any counties in these two areas. I am new to loops so do not know how to fix this. I have tried changing the line while ($county=='Wales') to while ($county = mysql_fetch_assoc($rGetCounty)) But this makes no difference
  16. I see. I really need to think about this then
  17. yes thats exactly what im trying to do. My database is set up correctly but I think I explained myselt wrong. Im looking for a tut for entering numerous entries into one field i a database ie in a book store 1 member can have many books so in the database you would have member_id = 001 name = dave book_isbn = 012, 013, 014; From here you could single out book 013 if you needed to. I need to know the code for entering new book_isbn's without deleteing others. I have heard something about explode but never used it. I would very much like to learn how to do this so what code do I need to look at?
  18. OK i'll try and explain this as best I can. I have members of my site and activities on my site. Each have thier own ID and are in their own table. member = 000001 activity = 000001 Now in a new table called running_activities I have the following fields. ID = 000001 memberID = 000001 activity = 000001, 000002, 000003 etc A member can be part of many activities so I want to store each activity they do in the field activity. Can somebody please explain to me what I need to be learning to do this. I only know how to store one entry in a field at the moment not lots of separate ones. Not only that but I would not know how to call just one entry from this field.
  19. thank you but now the error has moved down a few lines; PHP Parse error: syntax error, unexpected T_ELSE in /home/sites/yourarena.co.uk/public_html/members/index.php on line 82, referer: // Query for finding out if the signed in user is part of any clubs and then display them here. $qMyClub = "SELECT clubID, name FROM clubs WHERE memberID = ".$User['memberID'].""; $rMyClub = mysql_query($qMyClub); $NumClubs = mysql_num_rows($rMyClub); if ($NumClubs>=1) { while($Clubs = mysql_fetch_assoc($rMyClub)){ echo"<li>My Clubs <ul> <li><a href=\"members/myclub.php?club='{$Club['clubID']}'\">{$Club['name']}</a></li> </ul> </li>"; } else ($NumClubs=0) { echo" <li>My Clubs <ul> <li>None</li> </ul> </li>"; } } it means this line else ($NumClubs==0) { I tried changing it to just one = but nothing
  20. Hi im trying to echo out some html within php based on an if statement. Basically if you the is part of a club within a list item list the clubs, if they are not echo none within the list. Here is the code and below will be the error from the server. <?php // Query for finding out if the signed in user is part of any clubs and then display them here. $qMyClub = "SELECT clubID, name FROM clubs WHERE memberID = ".$User['memberID'].""; $rMyClub = mysql_query($qMyClub); $NumClubs = mysql_num_rows($rMyClub); if ($NumClubs>=1) { while($Clubs = mysql_fetch_assoc($rMyClub)){ echo"<li>My Clubs <ul> <li><a href=\"members/myclub.php?club='$Club['clubID']'\">$Club['name']</a></li> </ul> </li>"; } else ($NumClubs==0) { echo" <li>My Clubs <ul> <li>None</li> </ul> </li>"; } } ?> and the error; [error] [client ] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sites/index.php on line 78, referer: its referencing to the following line; <li><a href=\"members/myclub.php?club='$Club['clubID']'\">$Club['name']</a></li> I dont understand php enough to fix this can anyone help?
  21. Ok ill post the whole pages as is so far to show you what Ive got. That last piece of code doesn't do it either. <?php include('../Connections/connect.php'); include('../functions.php'); session_start(); //calls to functions $User = GetUser($_SESSION['Username']); $Clubs = GetClub($User['memberID']); $tmp = GetClub($myID); if (!$tmp[0]) { echo '<pre>' . print_r($tmp,true) . '</pre>'; } else { $Clubs = $tmp['results']; } //if (!$Clubs[0]) { // echo '<pre>' . print_r($Clubs,true) . '</pre>'; //} else { // echo '<pre>' . print_r($Clubs['results'],true) . '</pre>'; //} $randomKey = getUniqueCode2(25); $newCatKey = getUniqueCode2(20); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Create a new club account here on</title> <link href="/members/logged.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> <div id="head"> <div align="left"><a href="index.php"><img src="../images/logo.png" width="410" height="125" border="0" /></a></div> </div> <div id="horiz_navigation"></div> <div id="vert_navigation"> </div> <div id="content"> <form action="" method="post" name="insert_club" id="insert_club"> <table width="400" id="insert_club_tbl" > <tr valign="baseline"> <td width="176" valign="top" nowrap="nowrap">Club Name:</td> <td width="752" valign="top"><div align="left"> <input type="text" name="name" value="<?php echo $Clubs['clubID'] ;?>" size="32" /> </div></td> </tr> <tr valign="baseline"> <td valign="top" nowrap="nowrap"> </td> <td valign="top"><div align="left"> <input type="submit" id="insert_club" name="insert_club" value="Insert record" /> </div></td> </tr> </table> </form> </div> <?php include('../footer.php'); ?> </div> </body> </html> I have checked and the $User['memberID']; does hold the actual ID.
  22. Array ( [0] => 9 [clubID] => 9 [1] => 15 [memberID] => 15 an so on to the end of the table. ) What im looking for is from the being able to echo say the clubID by typing echo $Clubs['clubID'];
  23. Ok that seems to work in someway. I prints a list of the selected club
  24. Ken that code echos this on the server [Tue Feb 15 16:11:21 2011] [error] [client 90.198.47.133] PHP Parse error: syntax error, unexpected T_RETURN in /home/sites/site/functions.php on line 30, referer: http:/site.php?new_club=6620d5b156ae8c2ddf298249e The line it says is wrong is $rFindClub = mysql_query($qFindClub) or return(array(false,'query'=>$query,'error'=>mysql_error());
  25. hello. On my function page I have this function. function GetClub($clubs) { $qFindClub = "SELECT * FROM clubs WHERE memberID = '$clubs'"; $rFindClub = mysql_query($qFindClub); $Club = mysql_fetch_array($rFindClub); return $Club; } now when I feed it the variable $myID. If I try to echo say the club name $Clubs = GetClub($myID); echo $Clubs['name']; Nothing happens as its not working properly. Can anybody see what I have done wrong?
×
×
  • 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.