Jump to content

garry

Members
  • Posts

    217
  • Joined

  • Last visited

    Never

Everything posted by garry

  1. I can see what you're doing but what does adding the "selected" text do to it?
  2. Of course it can be done with mysql and PHP. I'd take a look into the Joomla CMS. Very customizable and easy for your client to add content to.
  3. Okay, here's the entire form that I'm using for the edit artist, i'm didn't post the whole file because it's very large but just ask if you need more.. <?php $query = "SELECT * FROM artists WHERE artist = '$artistname' "; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $artist = clean_output($row['artist']); $description = clean_output($row['description']); $artistid = $row['id']; $genreid = $row['genre_id']; if (mysql_num_rows($result) == 1) { ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST"> <table width="615" border="0"> <tr> <td><div align="right">Artist: </div></td> <td><input type="text" name="artist" value="<?php echo $artist; ?>"></td> <td><input type="hidden" name="artistid" value="<?php echo $artistid; ?>"></td> </tr> <tr> <td><div align="right">Description: </div></td> <td><textarea name="description" rows="20" cols="80"><?php echo $description; ?></textarea></td> </tr> <tr> <td><div align="right">Genre: </div></td> <td><select name="genre" > <? $query = "SELECT * FROM genres ORDER BY "; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<option name=\"genre\" value=\"" . $row['id'] . "\">" . $row['genre'] . "</option><br />"; } ?> </select></td> </tr> <tr> <td height="33"><input name="submitted2" type="hidden" value="1"></td> <td><input name="submit" type="submit" value="Edit" /></td> </tr> </table> </form>
  4. So I have a page where users can edit an artist. Once they select the artist, they are bought to a form with the artist name, description and genre. The genre is in a select list where the database is queried to obtain a list of all the genres, the genres are then all displayed in the list. The problem is the default genre used (the first one that is on the list that will be obtained if nothing else is selected). If the user is simply editing the description, they won't worry about the changing the genre and will just click "submit" which would change the genre from what it should be to something else. My question is, how is it that I can have the current genre for the artist (already in database) appear at the top of the select list so that the users don't accidentally change the genre to something incorrect. Here's the code i'm using: //the initial query used to get all of the artist information // (contains a row called genre_id to specify the genres current artist $query = "SELECT * FROM artists WHERE artist = '$artistname' "; // and the query to get all of the genres <select name="genre" > <? $query = "SELECT * FROM genres ORDER BY "; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<option name=\"genre\" value=\"" . $row['id'] . "\">" . $row['genre'] . "</option><br />"; } ?> </select> Thanks for the help!
  5. So I have a function to add the header to my site called add_header. This will add a file called header.php to the document I have a menu in the header and I want to use an if ($variable == 'somepage') { change the id } This would change the id of the menu so that the current page is a different color. The problem is, even if I add the $variable at the top of the page, it is not available within the function and I get an error. Is there any way to fix this? Thanks
  6. Thanks very much! That's all I need for now. I'll have a play around with this and see if I can get what I want working but I'm sure i'll run into more troubles later on the track. Thanks a bunch for your help, I really appreciate it
  7. Okay turns out it was my fault, I was using the html path for the image instead of the full server path for the php. When I use the full server path the error goes away and the area is just blank. I used var_dump on the variable and got the following array: array(7) { [0]=> int(300) [1]=> int(300) [2]=> int(2) [3]=> string(24) "width="300" height="300"" ["bits"]=> int( ["channels"]=> int(3) ["mime"]=> string(10) "image/jpeg" } Now how can I use this information to resize the image and such? Sorry for newb question!
  8. Hmm.. weird... Using this code displays the image: <img src="/dev/albumart/watershed.jpg" /> However, using your code, I get an error saying "No file"
  9. The file exists, I used an <img src> test to make sure and the image showed up. It's supposed to be /dev/ as i'm using absolute path.
  10. So I'm trying to manipulate some images for my website. I've checked and apparently the GD image library is installed. But when I use the getimagesize(); function, I get the following error: Warning: getimagesize(/dev/albumart/watershed.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/dev/test.php on line 23 Why does this happen? :/
  11. Thanks for your help but I've solved it now! Turns out the code I had was right, I was just calling my tinymce editor function twice on the page which screwed it up, all fixed now though. Thanks again!
  12. It's because you're calling the $row function twice. I assume you've already set the $row variable before that block of code? Just delete the other $row and it should work.
  13. come one.. can't anyone help? i'm sure it's only simple
  14. So this is my code, the user should submit a textarea and then I should be able to get the results on the next page. The form is to update a review. The problem is, whilst I get all the other data fine, the textarea retains the data ($body) that was initially put into it and does not update on the next page. Any idea why? <form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST"> <table width="615" border="0"> <tr> <td><div align="right">Album: </div></td> <td><input type="text" name="album" value="<?php echo $album; ?>"></td> <td><input type="hidden" name="albumid" value="<?php echo $albumid; ?>"></td> <td><input type="hidden" name="reviewid" value="<?php echo $reviewid; ?>"></td> </tr> <tr> <td><div align="right">Review: </div></td> <td><textarea name="body" rows="20" cols="80"><?php echo $body; ?></textarea></td> </tr> <tr> <td height="33"><input name="submitted2" type="hidden" value="1"></td> <td><input name="submit" type="submit" value="Edit" /></td> </tr> </table> </form> Thanks!
  15. Anyone?! I'd really appreciate some help on this!
  16. I'm still not sure how to do this? Could you explain further how to use AJAX to validate a registration field or link me to a good tutorial?
  17. Okay new problem too. For some reason, this code at the top of the page stops the message from updating dynamically (found out through trial and error): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> anyone know why?
  18. So I can change this URL to something different to the page I am on and it will be fine?
  19. How exactly do you do that? Sorry, I'm a complete newb to JS and ajax!
  20. Okay, so I'm trying to use a tutorial I found to validate my information using Ajax and javascript and the jquery library. I'm completely new to javascript and haven't a clue how any of it works (I usually only use PHP). Here is the tutorial: http://jqueryfordesigners.com/using-ajax-to-validate-forms/ Here is the code I'm using <?php $message = ''; $error = array(); // we'll fake the database check, the following names won't be available. $taken_usernames = array( 'remy', 'julie', 'andrew', 'andy', 'simon', 'chris', 'nick' ); // main submit logic if (@$_REQUEST['action'] == 'register') { $resp = check_username($_REQUEST['username']); if ($resp['ok']) { $message = 'All details fine'; } else { $message = 'There was a problem with your registration details'; $error = $resp; } } else if (@$_REQUEST['action'] == 'check_username' && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { // means it was requested via Ajax echo json_encode(check_username($_REQUEST['username'])); exit; // only print out the json version of the response } function check_username($username) { global $taken_usernames; $resp = array(); $username = trim($username); if (!$username) { $resp = array('ok' => false, 'msg' => "Please specify a username"); } else if (!preg_match('/^[a-z0-9\.\-_]+$/', $username)) { $resp = array('ok' => false, "msg" => "Your username can only contain alphanumerics and period, dash and underscore (.-_)"); } else if (in_array($username, $taken_usernames)) { $resp = array("ok" => false, "msg" => "The selected username is not available"); } else { $resp = array("ok" => true, "msg" => "This username is free"); } return $resp; } ?> <script src="<?php echo HTML_PATH; ?>public/js/jquery.js" type="text/javascript"></script> <?php if (!isset($_REQUEST['nojs'])) : ?> <script type="text/javascript"> <!-- $(document).ready(function () { var validateUsername = $('#validateUsername'); $('#username').keyup(function () { var t = this; if (this.value != this.lastValue) { if (this.timer) clearTimeout(this.timer); validateUsername.removeClass('error').html('<img src="<?php echo HTML_PATH; ?>images/ajax/ajax-loader.gif" height="16" width="16" /> checking availability...'); this.timer = setTimeout(function () { $.ajax({ url: 'Iindex.php?action=register', data: '&action=check_username&username=' + t.value, dataType: 'json', type: 'post', success: function (j) { validateUsername.html(j.msg); } }); }, 200); this.lastValue = this.value; } }); }); //--> </script> <?php endif ?> <?php if (isset($_POST['submitted'])) { // Database stuff goes here } else { ?> <div class="register"> <?php if ($message) : ?> <p id="message"><?=$message?></p> <?php endif ?> <fieldset title="Register"> <legend><heading>Register<heading></legend> <form action="<?php $_SERVER['PHP_SELF']; ?>?action=register" method="POST"> <table width="300" height="200"> <tr> <td><div align="right">First Name:</div></td> <td><input name="firstname" type="text" size="20" maxlength="30"></td> </tr> <tr> <td><div align="right">Last Name:</div></td> <td><input name="lastname" type="text" size="20" maxlength="30"></td> </tr> <tr> <td width="120"><div align="right">Username:</div></td> <td width="180"><input type="text" name="username" value="<?=@$_REQUEST['username']?>" id="username" /></td> <td><span id="validateUsername"><?php if ($error) { echo $error['msg']; } ?></span></td> </tr> <tr> <td><div align="right">Password:</div></td> <td><input name="password" type="password" size="20" maxlength="30"></td> </tr> <tr> <td><div align="right">Confirm Password:</div></td> <td><input name="confirmpassword" type="password" size="20" maxlength="30"></td> </tr> <tr> <td><div align="right">Email:</div></td> <td><input name="email" type="text" size="20" maxlength="30"></td> </tr> <tr> <td><input name="submitted" type="hidden" value="1"></td> <td><input name="submit" type="submit" value="Register"></td> </tr> </table> </form> </fieldset> </div> <?php ; } ?> This is already inside the index.php page (index.php?action=register). I haven't a clue why it isn't working. I've only put the extra stuff on the username at the moment and it comes up with "checking availability" when you click it and never changes. Sorry if I haven't explained this well. Can anyone help me fix this or point me to another tutorial/way of doing this that is easier? Thanks!
  21. But that will set the artistid as the users id, this isn't what I want as I will have multiple users adding multiple reviews. I simply need a way to get the id that has just been set by the database through the auto-increment
  22. There is no easier way of getting the id that the first row in the first query is assigned? I thought there might be a way with PHP..?
  23. Hi, I needed some help with a query I was making. I am trying to use user supplied data to insert into two separate tables in one database but the second table that is inserted into needs to get information from the first table that was inserted from (the new id created) Here's an example of the code: $album = clean_full($_POST['album']); $artistid = $_POST['artist']; $year = (int)($_POST['year']); $review = clean_body($_POST['review']); $user_id = $_SESSION['user_id']; $query = "INSERT INTO albums SET id = '', // This id will auto-increment in the database but I need to get the number it is assigned artist_id = '$artistid', title = '$album', year = '$year', user_id = '$user_id', created_at = NOW() "; $query1 = "INSERT INTO reviews SET id = '', artist_id = '$artistid', album_id = '?WHERE DO I GET THIS?', // I need to get the id from the previous insert and place it here body = '$review', user_id = '$user_id', created_at = NOW() "; $result = mysql_query($query); I would really appreciate any help
×
×
  • 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.