Jump to content


  • Posts

  • Joined

  • Last visited


About 2-d

  • Birthday 03/03/1987

Profile Information

  • Gender
  • Location
    New Jersey

2-d's Achievements


Newbie (1/5)



  1. 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!"; }
  2. 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.
  3. 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
  4. 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
  5. 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
  6. 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.
  7. 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.
  8. 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.