...

View Full Version : insert query help



it_seeker
09-13-2011, 06:06 AM
plz tell me whats wrong with this.....plz reply soon


<?php
$a = $_POST['T1'];
$b = $_POST['T2'];
$c = $_POST['T3'];
$d = $_POST['T4'];
$e = $_POST['T5'];
$f = $_POST['T6'];

$con = mysql_connect("localhost", "root", "");
if(!$con)
{
echo "error in connection".mysql_error();
}
mysql_select_db("uc", $con);
$q = mysql_query("insert into members values('$a',$b','$c','$d','$e','$f'",$con);
if(!$q)
{
echo "error in query".mysql_error();
}
if($r = mysql_fetch_array($q))
{
session_start();

$_SESSION['sname'] = $a;
header("location:confrmreg.php");
}
else
{
echo "invalid id or password try again";
}
?>

abduraooft
09-13-2011, 09:21 AM
plz tell me whats wrong with this.....plz reply soon
You forgot to tell us the issue that you are facing!

myfayt
09-13-2011, 12:14 PM
You were missing a comma, here you go try this.


<?php
$a = $_POST['T1'];
$b = $_POST['T2'];
$c = $_POST['T3'];
$d = $_POST['T4'];
$e = $_POST['T5'];
$f = $_POST['T6'];

$con = mysql_connect("localhost", "root", "");
if(!$con)
{
echo "error in connection".mysql_error();
}
mysql_select_db("uc", $con);
$q = mysql_query("insert into members values('$a','$b','$c','$d','$e','$f'",$con);
if(!$q)
{
echo "error in query".mysql_error();
}
if($r = mysql_fetch_array($q))
{
session_start();

$_SESSION['sname'] = $a;
header("location:confrmreg.php");
}
else
{
echo "invalid id or password try again";
}
?>

it_seeker
09-14-2011, 03:49 PM
its is query error i made changes in query later on it execute successfully but now again its giving error "duplicate key 0 to key 1 "i dont know what is this


You forgot to tell us the issue that you are facing!

abduraooft
09-15-2011, 01:15 PM
You might have a unique/primary key set on a filed and the script may be trying to insert an already used value to the same column. Have you forgot to set an auto_increment on that column?

ekgrad
09-15-2011, 01:42 PM
If you want to test again, just truncate the table and start afresh.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum