Jump to content

Ell20

Members
  • Posts

    337
  • Joined

  • Last visited

    Never

Everything posted by Ell20

  1. Hey, Im trying to create a drop down box which at the end has a Other option. If Other is selected I want the variable which is set from the drop down box to be set to whatever is typed in, in the input box below by the user e.g: <select name="team_name"><option value='' selected disabled>Select Team Name</option> <option value="1st XI">1st XI</option> <option value="2nd XI">2nd XI</option> <option value="3rd XI">3rd XI</option> <option value="Other>Other</option> </select> I dont really want to use Java or AJAX, is there anyway in which this can still be done? Cheers
  2. Hey, Im currently trying to produce some code which displays the 3 latest news items followed by a link to Read More = Working fine. However I also wanted to display a message saying if there are no news messages then echo "No news yet". Here is my code: <?php $query = "SELECT * FROM news WHERE club_id = '$club_id' ORDER BY 'news_id' DESC LIMIT 3"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<b>Title: </b>" ; echo $row['title']; ?> <hr> <?php } ?> <a href='news.php'>Read More</a> <br> <?php if ($row == 0) { echo "No news yet"; } ?> When I use this code the message "No news yet" is always there whether there is news or not. Appreciate any help Cheers
  3. Thanks MadTechie, your code produced a mysport.event table does not exist! It was a typo and should have read .......FROM events WHERE....... Thanks for the help
  4. Hey, Im using part of some code I created on a previous page to help me with a new page im creating. I have changed around the variables so they respond to the correct page however I am getting an error which I dont understand: An error occured in script c:\program files\easyphp1-8\www\html\events.php on line 43: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource The code works on the previous page but dosent work on this one, when all I changed is the variables!! $query = ("SELECT * FROM event WHERE club_id = '$club_id' ORDER BY 'date' DESC") OR DIE(mysql_error()); $result = mysql_query($query); //Line 43 while ($row = mysql_fetch_assoc($result)) { $eventid = $row['event_id']; Cheers for any help Elliot
  5. Hey, ive been working on this code for a while now. Im sure I had it working earlier to prefection but now its not working as its should but I cant work out what I have changed to stop it working. The idea of the code is that when the edit button is pressed the message from which the edit button was pressed appears in the textarea, then once the Edit News button is pressed the changes are saved. There is also a delete button which can be used to delete a news message from the page. At the moment when I pressed the Edit button its putting the news into the textarea but at the same time it runs the Delete code and deletes the news with the message "News Message Deleted". Appreciate any help on working out where I am going wrong. Cheers <?php require_once ('includes/errors.inc'); $page_title = 'News'; include_once ('includes/header.html'); require_once ('../mysql_connect.php'); include_once ('includes/functions.php'); $id = $_SESSION['club_id']; $clubinfo=getClubInfo($id, '*'); ?> <br /> <br /> <html> <body> <table width="60%" align="center" border="0" cellpadding="0" cellspacing="0" class="game"> <tr> <th><?=$clubinfo['clubn']?> News</th> </tr> <tr> <td> <?php $club_id = mysql_query("SELECT club_id FROM users WHERE user_id = '{$_SESSION['user_id']}'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($club_id); $club_id = $row['club_id']; $clubname = mysql_query("SELECT clubn FROM club WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($clubname); $clubname = $row['clubn']; $message = mysql_query("SELECT * FROM news WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($message); $news = $row['news']; $query = "SELECT * FROM news WHERE club_id = '$club_id' ORDER BY 'news_id' DESC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $newsid = $row['news_id']; echo "<b>Title: </b>" ; echo $row['title']; echo "<br>"; echo $row['news']; echo "<br>"; ?> <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=edit'>Edit News</a> | <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=delete'>Delete News</a> <hr> <?php } ?> </td> </tr> </table> <?php if (isset($_SESSION['user_id'])){ $sql = "SELECT member_type FROM users WHERE user_id = '{$_SESSION['user_id']}' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); if ($row['member_type'] == "Admin") { $query = mysql_query("SELECT news FROM news WHERE club_id='$club_id'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); $message = $row['news']; ?> <br> <br> <table border="1" align="center" cellspacing="0" border="0" class="game"> <th colspan="6"> Tags: </th> <tr> <td> Bold Text: <b>Text Here</b> </td> <td> Italic Text: <i>Text Here</i> </td> <td> Center Text: <center>Text Here</center> </td> </tr> <tr> <td> New Paragraph: <p> </td> <td> Insert Image: <img src="Link"/> </td> <td> Text Colour: <font color=colour>Text Here</font> </td> </tr> </table> <br> <?php if (isset($_POST['submit2'])) { require_once ('../mysql_connect.php'); $title = escape_data($_POST['title']); $news = escape_data($_POST['news']); $query = "INSERT INTO news (club_id, news, title) VALUES ('$id', '$news', '$title')"; $result = @mysql_query ($query); if ($result) { echo '<h3>New News Message Created!</h3>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table width="36%" border="0" align="center" cellspacing="0" border="0" class="game"> <tr> <th> Create New News: </th> </tr> <tr> <td> Title: <input type="text" name="title" size="60" maxlength="80" value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" /> </td> </tr> <tr> <td>News: <input type="text" name="news" size="60" maxlength="1000" value="<?php if (isset($_POST['news'])) echo $_POST['news']; ?>" /> </td> </tr> <tr> <td align="center"> <?php echo "<input name=\"submit2\" value=\"Create News\" type=\"submit\" />"; ?> </td> </tr> </table> <?php echo "</form>"; ?> <br> <?php if(isset($_GET['news_id'])){ $query = "SELECT * FROM news WHERE news_id = '{$_GET['news_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $newsid = $row['news_id']; $message = $row['news']; $title = $row['title']; if ($_GET['news_id']){ mysql_query("DELETE FROM news WHERE news_id='$newsid'") or die(mysql_error()); echo '<center><h3>Message Deleted!</h3></center>'; } ?> <table width="36%" border="0" align="center" cellspacing="0" border="0" class="game"> <tr> <th> Editing Post: <?=$title?> </th> </tr> <tr> <td> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="91" rows="10"><?=$message?></textarea> <input name="m_id" type="hidden" value="<?=$newsid?>"> </td> </tr> <tr> <td align="center"> <input name="submit3" value="Edit News" type="submit" /> </td> </tr> </form> </table> <?php } if (isset($_POST['submit3'])) { $message = $_POST['news']; $update = "UPDATE news SET news='{$_POST['my_messages']}' where news_id='{$_POST['m_id']}'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo '<center><h3>Message Updated!</h3></center>'; }}}}} ?> </body> </html> <?php include_once ('includes/footer.html'); ?>
  6. There isnt one, the code works, just the message was being displayed in an unexpected place so I didnt see it!
  7. Hey, I am attempting to create a link which when clicked deletes that particular news item. if ($_GET['news_id']){ mysql_query("DELETE FROM news WHERE news_id='$newsid'") or die(mysql_error()); echo '<center><h3>Message Deleted!</h3></center>'; } It is successfully deleting the record from the display and the database but the message is not being printed on the screen? Cheers
  8. WOW! Excellent, its working Can you just explain why you added the hidden part and what it does? Cheers
  9. Appreciate any help looking for the error in this code - when I edit a news item and press submit, no matter which news item I edit it saves the changes to the bottom news item <?php $club_id = mysql_query("SELECT club_id FROM users WHERE user_id = '{$_SESSION['user_id']}'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($club_id); $club_id = $row['club_id']; $clubname = mysql_query("SELECT clubn FROM club WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($clubname); $clubname = $row['clubn']; $message = mysql_query("SELECT * FROM news WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($message); $news = $row['news']; $query = "SELECT * FROM news WHERE club_id = '$club_id'"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $newsid = $row['news_id']; echo "<b>Title: </b>" ; echo $row['title']; echo "<br>"; echo $row['news']; echo "<br>"; ?> <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=edit'>Edit News</a> <hr> <?php } ?> </td> </tr> </table> <?php if(isset($_GET['news_id'])){ $query = "SELECT * FROM news WHERE news_id = '{$_GET['news_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $newsid = $row['news_id']; $message = $row['news'];//added by teng ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="100" rows="10"><?=$message?></textarea> <input name="submit3" type="submit" /> <?php } if (isset($_POST['submit3'])) { $message = $_POST['news']; $update = "UPDATE news SET news='{$_POST['my_messages']}' WHERE news_id='$newsid'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo '<center><h3>Message Updated!</h3></center>'; } ?> Cheers
  10. Unfortunately it dosent work. When you click submit it dosent even say the changes this time! Grr!!
  11. I was just looking at that, i changed it to: WHERE news_id='$newsid' and now when I do the update it updates the bottom update only even if i edit the top one!
  12. Ok I have it working to a certain level however when I submit query it is updating all the news items with the same text I just typed in: <?php $club_id = mysql_query("SELECT club_id FROM users WHERE user_id = '{$_SESSION['user_id']}'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($club_id); $club_id = $row['club_id']; $clubname = mysql_query("SELECT clubn FROM club WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($clubname); $clubname = $row['clubn']; $message = mysql_query("SELECT * FROM news WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($message); $news = $row['news']; $query = "SELECT * FROM news WHERE club_id = '$club_id'"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $newsid = $row['news_id']; echo "<b>Title: </b>" ; echo $row['title']; echo "<br>"; echo $row['news']; echo "<br>"; ?> <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=edit'>Edit News</a> <hr> <?php } ?> </td> </tr> </table> <?php if(isset($_GET['news_id'])){ $query = "SELECT * FROM news WHERE news_id = '{$_GET['news_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $newsid = $row['news_id']; $message = $row['news'];//added by teng ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="100" rows="10"><?=$message?></textarea> <input name="submit3" type="submit" /> <?php } if (isset($_POST['submit3'])) { $message = $_POST['news']; $update = "UPDATE news SET news='{$_POST['my_messages']}' WHERE club_id='$club_id'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo '<center><h3>Message Updated!</h3></center>'; } ?>
  13. Thanks, I think were getting somewhere, when I click edit now it brings up the textarea but it is currently empty? Cheers
  14. Im confused, here is my code, not sure which variables are right anymore, but I no 'id' isnt right: <?php $club_id = mysql_query("SELECT club_id FROM users WHERE user_id = '{$_SESSION['user_id']}'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($club_id); $club_id = $row['club_id']; $clubname = mysql_query("SELECT clubn FROM club WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($clubname); $clubname = $row['clubn']; $message = mysql_query("SELECT * FROM news WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($message); $news = $row['news']; $query = "SELECT * FROM news WHERE club_id = '$club_id'"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $newsid = $row['news_id']; echo "<b>Title: </b>" ; echo $row['title']; echo "<br>"; echo $row['news']; echo "<br>"; ?> <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=edit'>Edit News</a> <hr> <?php } ?> </td> </tr> </table> <?php if(isset($_GET['id'])){ $query = "SELECT * FROM news WHERE club_id = '{$_GET['id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $newsid = $row['news_id']; $message = $row['message'];//added by teng ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="100" rows="10"><?=$message?></textarea> <input name="submit" type="submit" /> <?php } if (isset($_POST['submit'])) { $message = $_POST['message']; $update = "UPDATE news SET news='{$_POST['my_messages']}' WHERE club_id='$club_id'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo '<center><h3>Message Updated!</h3></center>'; } ?> Appreciate any help
  15. Thanks for the code, no errors but the code dosent appear to do anything?!?!
  16. This is my layout, once the Edit News button is clicked id like the message to appear in a textarea then you can submit any changes. See code for Edit News button on previous page.
  17. Im not sure were thinking along the same lines? I already have a form where I can create new news items by typing in the title and news. However I want the admin to be able to edit each of the news items so that they can be changed once posted. I have already done something like this for a welcome message but as it was only the 1 message it was easy however my news page can have hundreds of news items. When the user presses the edit button I would like the message which is currently stored to be printed in the text area, the user can then edit the news and press submit, which updates the news item?
  18. I understand how to update the database but I am having trouble getting the value into the textarea in the first place? $query = "SELECT * FROM news WHERE club_id = '$club_id'"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $newsid = $row['news_id']; echo "<b>Title: </b>" ; echo $row['title']; echo "<br>"; echo $row['news']; echo "<br>"; ?> <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=edit'>Edit News</a> <hr> <?php } ?> </td> </tr> </table> Cheers
  19. Bump Can anyone help finish this off? I need to get the news into a textarea which I can then use sql to UPDATE the database once the news item has been edited? Cheers
  20. Thank you, working now. However im still learning php so I dont understand how to get the message into the textarea Cheers
  21. <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=edit'>Edit Message</a> Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\easyphp1-8\www\html\news.php on line 49 Cheers
  22. Thanks, ive got the Edit Message link in place now and its correctly using the new_id value. The way you have written the next bit, requires me to created a new page: editmessage.php, is there anyway in which I can direct the message into a textarea on the same page rather than on a different page? Cheers
  23. Ok thanks, How would I go about adding a "Edit News" link to the bottom of each news item so that the news item is put into the textarea rather than just the first news item? Cheers
×
×
  • 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.