Jump to content

2-d

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

About 2-d

  • Birthday 03/03/1987

Profile Information

  • Gender
    Male
  • Location
    New Jersey

2-d's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. You could always do a check to see if the file exists already and then increment it like so: <?php $i = 1; $filename = ("C:\\temp\\output".$i.".txt"); if(file_exists($filename)){ do{ $i++; $filename = ("C:\\temp\\output".$i.".txt"); } while(!file_exists($filename)); }
  2. <?php while($key > 0 && $key < 2){ //do stuff } The key youre missing is that && is how you do and in conditonals. You should read up some on while loops here: http://php.net/manual/en/control-structures.while.php
  3. Hello, I've seen this error before when invalid utf-8 characters were being encoded. So most likely whatever your function is returning has an invalid utf8 character in it. I resolved the issue by doing somthing like this to clean out the invalid characters: <?php $newstring = iconv('UTF-8', 'ISO-8859-1//IGNORE', $string); Where the $string variable is the utf-8 string with the invalid character. I'm not too sure if this is a valid solution to you, but it may be something to look into.
  4. What changes are you making to the database to cause this? That question mark symbol usually means you are tyring to display a character that is not valid in the character set you are using. What character set are you using? Generally, its a good idea to stick to utf-8
  5. Hello, Are you sure your query is returning anything? If it isn't you are not going to fall into that while loop you have. Also, it could be possible that column name "DateCreated" is incorrect. Looking at your dateDiff function, if your second date ($d2) does not exist, then it will return the amount of days since the beginning of unix time. For example, say $d1 is today and $d2 does not exist you will end up with 15000+ days. <?php $d1 = date("Y-m-d"); echo round(abs(strtotime($d1)-strtotime($d2))/86400); In that case, you will always fall into the first part of your if statement which does not echo anything out. You need to be careful with that because you may delete rows you do not intend to. You may want to add some more checking to your function to make sure those two variable exist. To check some stuff out, you should modify you while loop to see whats being returned. Try changing that while loop temporarily to be this: <?php echo "Rows being returned: " . mysql_num_rows($result); while($row = mysql_fetch_array($result)){ echo "<pre>"; print_r($row); echo "Date Difference: " . dateDiff(date("Y-m-d"),$row['DateCreated']); echo "</pre>"; } If this doesn't give you any insight into what may be causing the issue, then I would need to see what your database table structure is. Let me know. 2-d
  6. Oops, thats a typo on my part, the request variable should be using [] to index the array, not (): if ($_REQUEST['error'] == 1){ echo "Sorry that user name already exist!"; }
  7. the Header call would need to replace the echo of the error, you cannot change the headers once something is written to the screen. As for where to put the echo error, you will need to put that in the HTML, wherever you want to display it. It would be something completely separate from the error check.
  8. You can redirect them back to the form with an extra variable, lets say error: Header("Location: <url of form>?error=1"); Then on the HTML side of things, you can put a php snippet in that looks for that error: if ($_REQUEST('error') == 1){ echo "Lets display an error"; } Cheers
  9. Yeah, that make sense. What you can do in that scenario, is foreach loop through every element that is in the row and then display it accordingly. I will entail just the same amount of if statements run, but you will only have 1 if statement coded. It will just loop through it accordingly. So you can do something like this: while ($row = mysql_fetch_array($qry, MYSQL_BOTH)) { foreach($row as $key => $val){ if(!empty($val)){ $checked = "checked"; } else{ $checked = ""; } // This will make the key into a nice name to display in the echo // ucfirst makes the first letter captial, and str_replace swaps our the _ with spaces $nice_name = ucfirst(str_replace("_", " ", $key)); echo $nice_name . "<input style='font-size:10px;' name='$key' type='checkbox' $checked>"; } } I added in the $nice_name part as well to make a nice name out of the Key so you can display it in the echo. Let me know if this helps or if you need any explaining. Cheers
  10. Ah alright, I see your issue now. You are doing the insert without doing any checking on it. So if the username exists, you get the error of trying to insert a duplicate key. In your code you have this: $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } This piece of code is going to need to be inside of the check you mentioned in the fist post. Like this: $sql="select * from Profile where username = '$UserName'"; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(!mysql_num_rows($result)){ $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } } else{ echo "That username already exist!"; } This way, the insert will not even be run if the username is found in the database. And it will return the echoed error that you want. Hope this helps. Cheers
  11. Do you mean you want to have multiple comparisons in one if statement? You can use || (or) to check if any of the rows are empty like this: if (!empty($row['acid_wash']) || !empty($row['neutralise']) || !empty['clean']) || !empty(['grind'])) an or will check all of the variables, and if any one of them returns true, you will fall into that case.
  12. Hey, I believe the word 'checked' being in the HTML <input> line is all you need to have the checkbox selected. So since you always have 'checked=' it will always be checked. Try changing that line to: <td>High Pressure Clean <input style='font-size:10px;' name='clean[]' type='checkbox' $checked></td> Hope this helps. Cheers.
  13. Hello, What appears to the be the issue here is the way you are doing the comparison in the if statement: if(mysql_num_rows($result)!=0) Since you are doing a 'not equal', it will only fall into this case if a row was returned from the mysql statement above, meaning the username was already taken. So if a username does not exist, this comparison will fail and you will fall into the else case which throws the error. For example, if the mysql statement does NOT find a username, mysql_num_rows($result) will return 0. The if case willl then be "if(0 != 0)" which will return false and send you to the else. That is why you were receiving the error message each time. You will want to change the if statement to equals to: if(mysql_num_rows($result) == 0) Let me know if there are any other errors you need help with, I didn't go through all of the code, that was just the first thing I saw.
×
×
  • 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.