Jump to content

magicmoose

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Everything posted by magicmoose

  1. Hi, I'm having some problems with some code I've just tried to upload. At the beginning of the code, I include a bunch of classes, each of which start with declerations, eg public $something private $something protected $something etc Everything works fine on my local machine, but when I upload it, I get errors like: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /usr/local/psa/home/vhosts/mysite.com/httpdocs/test/classes/page.php on line 4 If I change the public/protected/private etc to var, the errors stop, but surely this isn't good practice. Can anyone tell me what's going on? Thanks.
  2. Hi, I'm using PHP to upload an unset number of images in a form. I'm trying to use javascript to add more form elements in order to allow the correct number of images to be uploaded. <script language="javascript" type="text/javascript"> function addContent(divName) { content = '<label for=\"file1\">File to upload:</label><input id=\"file1\" type=\"file\" name=\"userfile[]\" /><br />'; document.getElementById(divName).innerHTML += content; } </script> <li onclick="addContent('additemform');">More</li> The problem is, I need to replace the numbers (eg file1), with the number of times the function has been run, otherwise each file will have the same id. Is there a simple way to do this? Thanks.
  3. Hi, I'm trying to filter all input on my site but I'm having some trouble with the syntax. I tried to use this.. foreach($_POST as $key => $val) { $_POST[$key] = htmlentities($_POST[$key]); } foreach($_GET as $key => $val) { $_GET[$key] = htmlentities($_GET[$key]); } But get the error Warning: htmlentities() expects parameter 1 to be string, array given Can anyone give me any advice on how to do this? Thanks
  4. Oops, sorry for typo. Your code gives me the following: Array ( [0] => uploads/ [1] => uploads/ )
  5. Hi, I'm trying to display an unset number of images on a page, using an array to hold things like the directory and filenames etc. However, instead of echoing the values of each image, the single letter in the $key position is being echoed. For example "uploads" 2 gives the letter L. I've had this working on a separate page, but the code looks exactly the same. Can anyone point me in the right direction? Thanks. $directories = array(); $filenames = array(); $locations = array(); if($imageConn->num_rows()>0){ while($imageConn->moveNext()) { $directories[] = $imageConn->getField("directory"); $filenames[] = $imageConn->getField("filename"); $locations[] = $imageConn->getField("location"); } } foreach ($directories as $key => $directory) { echo $directory[$key]."<br />; echo $filename[$key]."<br />; echo $location[$key]."<br />; }
  6. It's returning 1 every time now ???
  7. Hi, I'm using LIMIT in my SQL query to create a paging effect for a gallery. I need to count the total number of rows in the table, but I'm having a problem. Instead of giving the number of rows, it simply returns the word "Array". Any nudges in the right direction would be appreciated. Here's the relevant part of the code, thanks. $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM $gallery ORDER BY id ASC LIMIT $offset, $rowsperpage"; $count = mysql_query("SELECT FOUND_ROWS()"); $rows = mysql_fetch_row($count); echo $rows;
  8. Didn't know that, thanks. I forgot to mention, after the form is submitted, the stylesheet DOES change, but only for one page. It goes back to the default value afterwards, whether I load up a different page, or the same one again. I am having a similar problem with sessions, it just seems that nothing will pass from one page to another. I have tried just putting a random value in both a cookie and session variable and echoing it on another page, but nothing is displayed.
  9. Hi, I have a piece of code which I want to use to allow the user to select a stylesheet. I had it working fine on another site, but I have just added the same code to a new site I am making and it's not working. At the top of my page I have: <? if (isset($_COOKIE["selectedStyle"])) // has the cookie already been set { $style=$_COOKIE["selectedStyle"]; }else{ $style = 0; } if (isset($_POST["changeStyle"])) // changing the style { $style=$_POST["changeStyle"]; } setcookie("selectedStyle",$style); // update or create the cookie ?> In the head tags I have this: <LINK REL="stylesheet" HREF="stylesheet<?= $style; ?>.css"> And in the body of the page I have the following form: <form method="post" action="<?= $_SERVER["PHP_SELF"];?>"> <P class="general">Normal<input type="radio" name="changeStyle" value="0" checked><BR></P> <P class="general">Text Only (No Flash Content)<input type="radio" name="changeStyle" value="1"><BR></P> <INPUT type="submit" name="submitstyle" value="Change"><BR> </form> Can anyone see any problems with it? If not, what settings do I need to get changed? I can post the settings from the php.php files if needed. Thanks.
  10. Sorry I have not replied sooner, I lost my internet connection for a day:( Thanks for your help, this is almost working now, except that for some reason it only ever displays the last item added. I think rather than adding a new item to the array, it is just replacing the old one each time a new item is added. Any idea why? Thanks again!
  11. OK, thanks. That seems to have helped, however it now displays... Array ( [0] => V for Vendetta ) 1 I just want the "V for Vendetta" part. Any idea where the other stuff is coming from?
  12. OK, I have added some more, but I am still having trouble. I now have the following... <? $add = $_POST['add']; //variable say if a value was sent $selected=$_SESSION['selectedcomic']; //the item selected if (!isset($SESSION['basket'])) //if array dosent exist, create it { $_SESSION['basket'] = array(); array_push($_SESSION['basket'],$selected); //add chosen item to array } if (isset ($add)) { //if item was added, display contents of array echo (array_values($_SESSION['basket'])); } else { echo "Your request could not be carried out"; } ?> But all that gets displayed is the word "Array" Can anyone see where I'm going wrong? Thanks.
  13. Sorry, should have mentioned that. I have that at the top of the file, this is just a small section from it.
  14. Hi, I'm trying to make a simple shopping basket script, but am a little unsure of the best way to do it. I want an array where items can be added/removed with a simple form and displayed as a list, but I'm a little unsure how to go about doing it. Here's what I have so far... On the page before this is a simple 'add to basket' form, which executes this. <? $add = $_POST['add']; if (isset ($add)) { echo $_SESSION['selectedcomic']; } else { echo "Your request could not be carried out"; } ?> The echo statement is just for me to check that the form was working. I need a SESSION array to hold each product that gets added. I thought you could have an empty array by just using [] and then adding to it later, but I haven't been able to get that to work yet. Any nudges in the right direction would be appreciated. Thanks.
  15. Sorry, I have closed the tags, I just cut and pasted 1 line less than I should
  16. I think I have the right idea with this code, I am just unsure of the correct syntax to use. The following is meant to simply arrange the results of a query in a table. However, I would like the first field of each row to echo as a unique hyperlink (based on $dbRecord["title"]) which can then be passed on to another page with GET. while ($dbRecord=mysql_fetch_array($queryResult)) { echo "<TR><TD><A href=\"comic.php?title=$dbRecord["title"]\">".$dbRecord["title"]."</A></TD>"."<TD>".$dbRecord["author"]."</TD>"."<TD>".$dbRecord["artist"]."</TD>"."<TD>".$dbRecord["publisher"]."</TD></TR>"; I know I have made a syntax error as I cannot get this to work yet, but are there any other problems with this? Any help would be greatly appreciated, thanks!
  17. It works for two fields, but I'm not sure how to extend this to sort by other fields. I think I may have misunderstood the way drop down menus work with php. Is it based simply on this line "<select name="Comics">" rather than the values of that are selected? EDIT: Ignore the above, it does work perfectly, just took me way longer than it should have to see what was happening Thanks!
  18. I am not yet good enough to always work things out the easiest way possible
  19. Hi, I am just getting into php and am struggling to get it to do anything useful. I have a drop down box on one page, with 4 possible options: title, author, artist and publisher. When the user clicks submit, the following script is run. I just want it to sort the results based on the field the user selects from the drop down box, but at the moment it sorts by title no matter what they choose. Can anyone help me work out where I'm going wrong? Thanks in advance. Here's the code. <? $dbServer=mysql_connect("localhost","",""); if (!$dbServer) {echo "Failed to connect to MySQL"; exit; } mysql_select_db("database",$dbServer); if ($_POST['Comics']= "Title"){ $sql ="SELECT * FROM comics ORDER BY title"; } elseif ($_POST['Comics']= "Author") { $sql ="SELECT * FROM comics ORDER BY author"; } elseif ($_POST['Comics']= "Artist") { $sql ="SELECT * FROM comics ORDER BY artist"; } elseif ($_POST['Comics']= "Publisher") { $sql ="SELECT * FROM comics ORDER BY publisher"; } $queryResult=mysql_query($sql); if (mysql_error()) { echo "Problem with Query<BR>"; echo "The following error message was returned from MySQL:<BR>"; echo mysql_error(); exit; } if (mysql_num_rows($queryResult)==0) { echo "No results that match your enquiry"; } else { while ($dbRecord=mysql_fetch_array($queryResult)) { echo "found: ".$dbRecord["title"].", ".$dbRecord["author"].", ".$dbRecord["artist"].", ".$dbRecord["publisher"]."<BR>"; } } ?> EDIT: Here's the HTML <form action="includes/dispbytitle.php" method="POST"> <select name="Comics"> <option value="Title">Title</option> <option value="Author">Author</option> <option value="Publisher">Publisher</option> <option value="Artist">Artist</option> </select> <INPUT type="submit" value="Search"> </form>
×
×
  • 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.