Jump to content

paulonline2501

Members
  • Posts

    70
  • Joined

  • Last visited

Posts posted by paulonline2501

  1. Hi,

     

    this is not my code but its giving me trouble on a site.

    the code works in IE. but in Crome

     

    there is a radio button that is defaulted to not show some text.

    when the user switches to the other radio button (three are just two) the text is supposed to display.

    it works in IE but not Crome.

     

    is the text below enough or do you want to see the code for the whole page?

    <script type="text/javascript">$(document).ready(function() { $("input:radio[alt-id='test-hide']").change(function() {      if(this.checked && this.value == "Y") {$("div#other-questions").show();}if(this.checked && this.value == "N") {$("div#other-questions").hide();}});$("input:radio[alt-id='test-hide']").change();});
  2. elseif(htmlentities($db_oregion)==htmlentities("North & Islands")){echo("North, Highlands & Islands");}
    switch ($db_oregion) {				case "Central":					echo "Central Scotland";					break;				case "East":					echo "East Anglia";					break;				case "Mid":					echo "Mid & West Wales";					break;				case "North":					echo "North Wales";					break;				case "North & Islands":					echo "North, Highlands & Islands";					break;				default:					echo "$db_oregion";}				

    thanks for all the replies.

     

    I tried using htmlentities [see above], and switch [see above] but neither worked. I wasn't sure how to do a switch with htmlentities.

     

     

     

    however, its still not working.

     

    as I said: the conversion should change entries coming back from the DB from "North & Islands" to "North, Highlands & Islands".

    this is the only conversion that is not working.

    the other conversions are all working.

    the values are correct in the DB.

    "North & Islands" is displaying incorrectly so I know the values in the DB are what i'm expecting, there just not converting.

     

     

     

     

     

     

     

    asd

  3. hi everyone,

     

    I'm having trouble with a PHP if statement.

    I'm getting a value back from a database.

    the values stored in the DB aren't exactly what I want to display so im going to do a inline conversion on them.

    I want to say for example: if the region = 'central' then display 'central Scotland'.

     

    ive added my conversion but the value that is stored in the DB is showing rather than the converted value.

     

    can anyone spot what is wrong?

     

    UPDATE: OK, so it works for all of these apart from the "North & Islands" one. all othere convert, but this one doesn't. it doesn't change to "North, Highlands & Islands" it just stays as "North & Islands". the others change.

     

    the code is below:

    <h3><strong>Region:</strong>				<?php 								if($db_oregion=="Central"){echo("Central Scotland");}				elseif($db_oregion=="East"){echo("East Anglia");}				elseif($db_oregion=="Mid"){echo("Mid & West Wales");}				elseif($db_oregion=="North"){echo("North Wales");}				elseif($db_oregion=="North & Islands"){echo("North, Highlands & Islands");}				elseif($db_oregion=="South"){echo("South Wales");}				else{echo($db_oregion);}								?>			</h3>
  4. ....actually, I think ive got it working but i'm sure there is a way to write it in a more elegant way.here's what I wrote:

    <?php	$myString = trim($myString, ",");	$myArray = explode(",", $myString);	echo("<p>Exploded string in array:</p><ul>");	foreach($myArray as $thisValue)	{		$i=0;		$thisPartsValueID="";		$thisPartsValueQuantity="";		$myArrayParts = explode("-", $thisValue);		foreach($myArrayParts as $thisPartsValue)		{			if($i==0){echo("<li>id=".$thisPartsValue."</li>");$thisPartsValueID=$thisPartsValue;$i++;}			else{echo("<li>quantity=".$thisPartsValue."</li>");$thisPartsValueQuantity=$thisPartsValue;}		}		echo("insert into tableName (quantity) values (currentQuantity - $thisPartsValueQuantity) where id = $thisPartsValueID");	}	echo("</ul>");?>
  5. <p><?php$myString = "45-2,34-2,35-1,";echo($myString);?></p><?php$myString = trim($myString, ",");$myArray = explode(",", $myString);echo("<p>Exploded string in array:</p><ul>");foreach($myArray as $thisValue){   echo("<li>".$thisValue."</li>");}echo("</ul>");?>

    I got the first explode working but struggling with the 2nd explode.

  6. ...thanks justsomeguy. yeah, I found something on exploding and am trying it now. I've got the first explode working, and even managed to trim the trailing comma to stop it from being put in the array.

  7. hi, I've got a variable being passed to me from a third party website. in the following format "45-1," where 45 would be the item id and 1 would be the quantity. the variable could hold a few key pairs. eg: "45-1,46-3,5-3,"the first number is always the item id and the 2nd number is always the quantity. each pair separated by a comma. there is always a trailing comma. I need to deconstruct these pairs and deduct the quantity from the correct item in the products table in my database. My question is, what is the best way to deconstruct these pairs?im guessing I should put these in to an array.not totally sure how to do this. any help or ideas would be great. the variable is initially set like this:

    $custom = $_POST['custom'];
  8. I got it working with the following code but if you have any improvements let me know.

     

    This code will always display the folder as empty. Opps....

    foreach (glob('../../_documents/*.*',GLOB_NOCHECK) as $file){	$fileName = basename($file);	if ($fileName = '*.*'){echo("<li>There are currently no files in this folder.</li>");break;}	if ($fileName != 'index.php') 	{?>		<li><?php echo"$fileName"?></li>		<?php 	}//end if}//end foreach
  9. Hi,

     

    Does any one know how to display a message instead of the warning error when there are no files in the folder you are doing a directory list of?

     

    I have the following code, which produces a list of files in the folder.

    The only problem is when the folder is empty.

    I get a foreach error only when there are no files in the folder.

    I can forsee that sometimes the folders will be empty so will want to show my own error instead of this server warning.

     

    I think the "GLOB_NOCHECK" function may help but this may actually only work with folders rather than files.

     

     

    The code that works when there are files in the folder but gives a PHP warning when there are no files in the folder:

    foreach (glob('../../_documents/*.*') as $file){   $fileName = basename($file);   if ($fileName != 'index.php')      {?>	<li><?php echo"$fileName"?></li>      <?php       }	//end if}//end foreach

    The warning error i get if there are no files in the folder:

    • Warning: Invalid argument supplied for foreach() in.....

     

    I would like to put the following if there is nothing in the folder:

    <li>There are currently no files in this folder.</li>
  10. I'm trying to set the quantity of an item in an HTML Paypal button.

    I'm creating the buttons dynamically using a HTML template and values from my products table in my database [php/mysql].

    I know you can set the quantity of an an item in the paypal buttons you can make on the the paypal website, but I want to make the buttons dynamically and avoid this step.

    I have generated the rest of the button without problem - they currently have name, price, postage etc.

    The one thing I can't do is set the quantity of the item.

    So the problem at the moment is, I have a lot of one off items. I want to be able to set the quantity to 1. this way I can control whats being sold. once the item is sold I will use the Paypal IPN to update my databases stock level.

    At the moment the user can add more than one of the item in the paypal basket. This is a problem where there is only one item. If any one knows ho w to set the quantity of an item in an dynamically made HTML Paypal buy now button please let me know.

  11. hi everyone,

     

     

    i've got a script that works on one website, that lists files in a directory.

     

    ive moved the script to another website but now the script isnt working.

     

    the script:

    <ul><?php	foreach (glob('../../_docs/*.*') as $file){		  $file = basename($file);	  if ($file != 'index.php') 	  {?>		<li><?php echo"$file"?> <a href="../../_docs/<?php echo"$file"?>" target="_blank">[View]</a> 									<a href="../products/delete/?id=<?php echo"$file"?>">[Delete]</a></br>									URL: http://xxxxxxxx.com/CYC/_docs/<?php echo"$file"?>									</li>	  <?php 	  }	  		} ?></ul>

    the error:

     

    • Warning: Invalid argument supplied for foreach() in/xxxxxxx/documents/index.php on line 188 [this refers to the line with the foreach glob in it]

  12. hi ,

     

    I think ive got a syntax error or something.

    my query is running from a php page and for some reason the insert doesn't work when I add the last_updated column.

    I want it to record the date and time but its just giving this error:

     

    error:

    Error in query!You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'last_updated = NOW() WHERE id='57'' at line 11

     

     

    the code:

    // open connection	$UpdateConnection = mysql_connect($all_host, $all_user, $all_pass) or die ("Unable to connect!");	// select database	mysql_select_db($all_db) or die ("Unable to select database!");	// create query	$UpdateQuery = "UPDATE xxx.products 					SET					name='$totally_clean_name', 					description='$totally_clean_description', 					price='$totally_clean_price',					post_uk='$totally_clean_post_uk',					post_eu='$totally_clean_post_eu',					post_world='$totally_clean_post_world', 					status='$totally_clean_status', 					quantity='$totally_clean_quantity'					last_updated = NOW() 					WHERE id='$currentItemID';";						// execute query	mysql_query($UpdateQuery) or die ("Error in query!".mysql_error());//.mysql_error()	// close connection	mysql_close($UpdateConnection);

    ive also tried,instead of NOW(): sysdate(), current_time, now, current_date()

     

    thanks for reading

  13. hi everyone,

     

     

    im having a problem spotting whats wrong with this code.

    what im doing is checking some input from a user of type 'folder'.

    if its got slashes on the front i remove.

    if its got slashes on the end i remove. and add one slash.

     

    it works up to here.

     

    then i check to see if the actually input a value for folder. they dont have to. in this case the value will just be '/'. as i added the slash eailier.

     

    if i leave folder blank this works too.

     

    if i input something i get a fail. i dont beleive the pregmatch is failing as i've used the same pregmatch on other types of variables.

     

    ......im stomped???????

     

    code below:

    case "folder":$clean_folder_step01 = htmlentities($thisValue, ENT_QUOTES); $clean_folder_step02 = ltrim($clean_folder_step01, "/");$clean_folder_step03 = rtrim($clean_folder_step02, "/")."/";if($clean_folder_step03=='/'){$GLOBALS['totally_clean_folder'] = '';}elseif(preg_match("/^[a-zdws-/]{1,90}$/i",$clean_hostDir_step03))  {$GLOBALS['totally_clean_folder'] = $clean_folder_step03;}else{//otherwise add error details$GLOBALS['error']++;$GLOBALS['errmsg'] .= 'Invalid folder. ';}break;
  14. hi,

     

    i have a preg_match that checks "descriptions".

    the preg_match fails when i input an apostrophe ' in the text box.

     

    my code is as follows:

    $clean_description_step01 = htmlentities($thisValue, ENT_QUOTES);$clean_description_step02 = stripslashes($clean_description_step01); if(preg_match("/^[-',.a-z0-9dws]{1,200}$/i",$clean_description_step02)) { do something here...}

    can any one see why its not working?

  15. Yeah thanks justseguy.As you said, I already have a login. This sets SESSION variables to logged in and sets the user id - I didn't really mention it before because its so obvious to me. I think this with the SQL check that I posted previously ill be able to check as you have just suggested. I think I'll go a step further and instead of using the id ill set up a token comprising id, ftp_id and random string and use that in the 'get'. That would add a level of complexity that would mean guessing the URL would be time consuming and a SESSION hack would have to be done.

  16. The problem is that it is the id of an FTP. There are numerous users all with there own FTPs. Therefore it would be a easy for a user to change the URL to the id of an FTP that doesn't belong to them and see the details. This most be a very common issue. You have items in your database. You have a page that shows the details of this item using a parameter such as id to indicate the specific item. And the need to restrict viewing access based on the user having ownership of the item.

×
×
  • Create New...