Jump to content

garry

Members
  • Posts

    217
  • Joined

  • Last visited

    Never

Everything posted by garry

  1. Thanks for your reply I wanted to know how how exactly to make it so that when the page is submitted, the information is added and confirmed but the form is not displayed again. I'm pretty sure you can do this with a hidden field in the form which sets a variable but I'm not exactly sure how you do it so I thought I'd ask here! Thanks again
  2. So i'm trying to make a form that will add an artist to the database for my music review website. I'm doing this with a form and want to do the actions on the same page. I'm sorta confused about how I can do this :/ I don't want to parse the information through the URL because description will often be very big. Can someone also please help me with how I should filter the information that is added, I've heard about html_strip_chars and html_entities but i'm not sure exactly what they do and what should be used. Here's what I've got so far for the page: <h3> Add Artist </h3> <?php ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <table width="615" border="0"> <tr> <td width="144" height="32"><div align="right">Artist Name:</div></td> <td width="461"><input type="text" name="artist" value="" /></td> </tr> <tr> <td height='32'><div align="right">Artist Description: </div></td> <td><input type="text" name="description" value=""> </td> </tr> <tr> <td> </td> <td><input name="submit" type="submit" value="Submit" /></td> </tr> </table> </form> Any help would be greatly appreciated
  3. It definitely does exist. Okay, i changed some stuff and it seems to be working now. index.php: <?php $title = "Home"; require ("includes/includes.php"); require ("config.php"); ?> includes/includes.php: <?php include ("functions.php"); ?>
  4. Using the code you gave me I get another error Warning: require(../config.php) [function.require]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/dev/includes/includes.php on line 5 Fatal error: require() [function.require]: Failed opening required '../config.php' (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/dev/includes/includes.php on line 5
  5. Okay so I'm trying to do what you suggested but am having trouble with the relative paths.. it just doesn't seem to be working. Here's my folder structure index.php config.php includes/includes.php includes/functions.php I'm using this code in "includes.php" <?php require("config.php"); include ('functions.php'); ?> And this code in index.php <?php $title = "Home"; require_once('config.php'); require_once('includes/includes.php'); ?> But I keep getting this error: Warning: require(../config.php) [function.require]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/dev/includes/includes.php on line 4 Fatal error: require() [function.require]: Failed opening required '../config.php' (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/dev/includes/includes.php on line 4
  6. The only reason I wanted to do absolute was including files with paths in them. For example, if I had a file "includes/includes.php" that contained a link to "../file.php" and then I wanted to include that in the index.php AND the "style/style.php" file. Wouldn't it not work because the link would only be relative to one of the files? (Sorry if i'm explaining this bad).
  7. Thanks for your help! I tried getcwd() function works well and it all works great when I define the DOC_ROOT in the document i'm working on but whenever I try to use it in a different document I get an undefined error. Do you know how I can fix this? I considered relative paths but I thought that they could get complicated down the track as more and more files are added so it would be easier to simply use the absolute paths.
  8. So I'm sort of planning for the future here... At the moment, I'm creating a website and its address is http://localhost/dev When I use includes for the config and function files, i'm currently using this include_once ($_SERVER['DOCUMENT_ROOT'] . "/dev/includes/whatever.php"); I know that once I move the site to a different server, everything will not display because I've added /dev/ to the paths. Can anyone suggest a way to fix this? I've tried making a variable in the config.php but it means I have to set the variable at the top of each page for it to include the config file. Can anyone please help?
  9. Ah that worked, thank you. I only started learning PHP a week ago and am still trying to understand how it all works. Thanks for your help Yeah, I know. It was just that I was thinking that the row variable was only being set by that line and that deleting it would produce an error. Thanks for showing me.
  10. Yes but i'm not sure how to remove one of them and retain the row variable. I'm very new to php and still learning - please remember that we all aren't gurus
  11. So what do I need to do in order to fix this? Thank you
  12. Okay so I posted a question on here before and it was answered (thank you very much!) and now I have another problem. For some reason, when i'm trying to display data from the database, the first row (where artist_id is 1) will not show but all others (2,3,4,5..) do show. Can anyone explain why it is not returning the 1st row? Here's the code I'm using: echo "Welcome to the artists page! <br /><br />"; $query =" SELECT * FROM artists "; $result = mysql_query($query); $row = mysql_fetch_array($result); while ($row = mysql_fetch_assoc($result)) { echo "<a href=\"artists.php?id=" . $row['artist_id'] . "\">" . $row['artist'] . "</a><br />"; }
  13. Ah thank you very much for your help! I am very new to PHP and still trying to learn the basics Thanks again!
  14. Thankyou for your replys everyone. Darkwater, I'm only new at php which is why I tried to use a switch to do what I wanted as I wasn't sure exactly how. I tried your code and the default page now works but when i go to .php?id=1 i get the following error: Fatal error: Call to undefined function mysql_num_row() in /htdocs/dev/artists.php on line 22 Not sure why this is happening? Note - I also removed one of your '}'s from just before the else statement as I was getting a syntax error.
  15. Thanks for your reply! Unfortunately that wouldn't work as it wouldn't be able to provide the .php?id=x ability. After playing around a bit, I've got it all working except one bit. <?php add_header(); db_connect(); $id = $_GET['id']; $query =" SELECT artist_id, artist, description FROM artists WHERE artist_id = '$id' "; $result = mysql_query($query); $row = mysql_fetch_array($result); switch ($id) { case ($id): echo "<b>Artist:</b> " . $row['artist'] . "<br /><br /><b>Description:</b> <br />" . $row['description']; break; default: echo "Welcome to the artists page!"; break; } ?> Now this code works fine when you navigate to a .php?id= page and will show the relevant information for the artist. However if you just go to the artists.php page (the default case) I get the following page: Notice: Undefined index: id in /Applications/MAMP/htdocs/dev/artists.php on line 12 Artist: Description: For some reason, it is still using the data from the $id case and not using the default case that I put. Can anybody suggest a solution that will let me keep the .php?id= function and also execute different code when the user simply vists artists.php. Thank you!
  16. Okay, so I'm trying to write a music review website using php. I want to set it up so that it goes www.mysite.com/artists.php?id=1 for example, and then it would check the id against the database and get the row for the artist id that is 1. I'm trying to do this using a switch and keep getting errors with variables not being defined and such and don't know how to do it. Can someone please have a look at my code and help? <?php add_header(); db_connect(); $query =" SELECT artist_id, artist, description FROM artists WHERE artist_id = '$artistid' "; $result = mysql_query($query); $row = mysql_fetch_array($result); $artistid = ???? switch ($id) { case ($artistid): echo 'artist info'; break; default: echo "Welcome to the artists page!"; break; } ?> I am only very new to php and still learning. Thankyou for 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.