I have a code that i get the $_POST's result and then insert them in tables
of Mysql
it can run without error but it'll insert in the table twice and i don't
know why.
when I click the submit then with array_key_exists I go to if statement and
insert it.
i'll show the code if someone have time
Negin Nickparsa wrote:
I have a code that i get the $_POST's result and then insert them in tables
of Mysql
it can run without error but it'll insert in the table twice and i don't
know why.
when I click the submit then with array_key_exists I go to if statement and
insert it.
i'll show the code
Consistently
here is the code:
?php
session_start();
$connection=Mysql_connect('localhost','admin','123');
Mysql_select_db('db',$connection);
if(array_key_exists('sub',$_POST)$_POST['sub']=='Register')
{
$str=$_POST['uname'];
$str2=$_POST['pass1'];
$str3=$_POST['pname'];
$str4=$_POST['lname'];
I click the submit button just one time! not twice
but when i go to MySql and select * from it
it shows me happening two times
hi negin,
do you get duplicate inserts into both tables? if yes, try an
'exit();' right after the success message;
echo you have been registered successfully!;
exit();
this will stop the script after the message, and you wont see the form
either. at this point check the tables for duplicate
Hi viraj
intresting!
i changed the code to this:
$kind=$_SESSION['s3'];
$query1=insert into
user(kind,user,pass,name)values('$kind','$str','$str2','$str3');
$result1=mysql_query($query1);
i set the session in my another page
and now it works properly:D
LOL!!
Yes viraj it was in both tables
i used your exit too,yes it's better to hide the form after registration:)
Negin Nickparsa wrote:
I click the submit button just one time! not twice
but when i go to MySql and select * from it
it shows me happening two times
The code looks OK, so something is hitting it twice. I normally have a unique
index on anything that I do not want duplicates in - which would
i'm wondering that what was the problem!
why with just a session it now works propely!!!
how!
But why do you double-post your question?
http://news.php.net/php.general/313198
?
On Sat, May 28, 2011 at 11:21, Negin Nickparsa nickpa...@gmail.com wrote:
i'm wondering that what was the problem!
why with just a session it now works propely!!!
how!
cause it's in another topic!!! and another problem!
this problem was solved
i had another problem
what do you mean!?
in this topic problem WAS this one:
insert to a table twice(that was solved)
and on that post problem is this one:
working with echo html then insert to a table (problem in $_POST)
I thought it is very different am i wrong?
hi nigen,
the intention of that 'exit' was to stop the script temporarily to
avoid any second time inserts. i think you better figure-out what
caused your script to insert same data twice in a single form post.
to hide the form, 'exit' is not the best option. there are several
different ways, one
Thanks Viraj,I'll read it.
15 matches
Mail list logo