• 0

php / mysql and form


Question

Hi, I have a form in php for entering a username with alot of other field. When I submit, a jscript verify everything to see if its correct. Now, what I would like to do is to verify if the username already exist. Now, I founded a way to do this, but then, the page refresh and every field lost there value so the user must re-enter everything. I want to know how can I do this so he doesn't need to re-enter everything.

Here is the jscript that verify everything:

<script>
	function checkDataRegisterAddJob()
	{
 ?var correct = true
 ?if (document.registerAddJob.username.value == "") {correct = false; alert("Veuillez entrer un nom d'utilisateur")}
 ?else if (document.registerAddJob.password.value == "") {correct = false; alert("Veuillez entrer un password!")}
 ?else if (document.registerAddJob.password_confirm.value == "") {correct = false; alert("Vous devez confirmer votre password!")}
 ?else if (document.registerAddJob.password_confirm.value != document.registerAddJob.password.value) {correct = false; alert("Vos password ne concorde pas!")}
 ?else if (document.registerAddJob.Nom_Compagnie.value == "") {correct = false; alert("Veuillez entrer le nom de votre compagnie!")}
 ?else if (document.registerAddJob.adresse.value == "") {correct = false; alert("Veuillez entrer l'adresse de votre compagnie!")}
 ?else if (document.registerAddJob.email.value == "") {correct = false; alert("Veuillez entrer votre e-mail!")}
 ?else if (document.registerAddJob.tel.value == "") {correct = false; alert("Veuillez entrer votre # de t?l?phone!")} ? ? ? ?
 ?else if (document.registerAddJob.titre.value == "") {correct = false; alert("Veuillez entrer le titre de l'emploi!")}
 ?else if (document.registerAddJob.description.value == "") {correct = false; alert("Veuillez entrer la fonction de l'emploi!")}
 ?else if (document.registerAddJob.contact.value == "") {correct = false; alert("Vous devez sp?cifier le nom du contact!")}

 ?return correct
	}
</script>

now, the php to verify the username is :

?<?php 
 ?	$username=addslashes($username);
 ?	$query="SELECT User FROM Employeurs where user='$username'";
 ?	$result=mysql_query($query);
 ?	if ($ligne=mysql_fetch_array($result)){
 ? ?echo "<script>";
 ? ?echo "registerEmployeurError()";
 ? ?echo "</script>";
 ?	}
	?>

how can make that without loosing all field data?

tks

P.S. Sorry for the french error, but anyway, is doesn't matter for the need of the debugging

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

ok. There is a form that require a username and password. Once the user submit, I verify if the username is already taken in the mysql database. If it's already taken, it redisplay the same page with but all field are empty so every information need to be re-entered. Now, what I want is that the field filled with the user information that he entered.

Link to comment
Share on other sites

  • 0

Just use the <?= syntax. That is:

<input type="text" name="username" value="<?= $_POST['username'] ?>" />

Do that for each field :)

Link to comment
Share on other sites

  • 0
  • 0

First thing, the values are not encapsulated with quotes. need to add quotes, or spaces in things will mess with you.

Also, you're using register_globals, which is bad. use $_POST['username'] instead.

Beyond that, I can't really follow your code, to be honest. Needs a better design. (and needs to be in english :p ;) just kidding)

Link to comment
Share on other sites

  • 0

Ok, now, I manage to make work my check (another way out but work well). Now, what I would like to do is to make this line work. It was working when register_global was on, but now, it doesn't work. It's a mysql query.

$query="SELECT Nom FROM Cat_Salaire where ID = $_POST['Cat_Salaire_ID']";

I know that $_POST['Cat_Salaire_ID'] have a value since I did a phpinfo() right after to se all variable.

Link to comment
Share on other sites

  • 0

right before that line put something like

$cat_salaire_id = $_POST['Cat_Salaire_ID'];

and when you are doing the query simply do:

$query="SELECT Nom FROM Cat_Salaire where ID = $cat_salaire_id";

btw, if $cat_salaire_id is an integer then you dont need to put it in quotes so you can have:

$cat_salaire_id = $_POST[Cat_Salaire_ID];

Link to comment
Share on other sites

  • 0

Well, I manage to make it work, I simply forgot the right way to put variable...

"SELECT Nom FROM Cat_Salaire where ID = '" . $_POST['Cat_Salaire_ID'] . "'";

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.