0

hi all,
I am new to php and have started some coding.I want to insert values in one table1 and update values of table2.
It worked for me last day..but today it doesnt work.I have hardly changed any code.i guess except fr deleting some comments in code..u plz tell me if this thing works.

//line1
$sql="UPDATE table1 SET col2=$p WHERE col1=$p AND col2 IS NULL";
//line2
$sql="INSERT INTO user(u_id,u_uname, u_fname, u_lname) VALUES ($q,'$username','$fname','$lname')"

i tried to see which statement works in sequence..i found that the line 2 statement works in any case even if u swap the statements..means line 1 statement will work if u swap it with line 2.It worked fine last day.insertion and updates were performed easily..plz help..y this happens? is it bcoz of same variable $sql used to catch return values?

Edited by diafol: Use code tags

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by gacoekchip.pokher
0

thanks for your reply..i tried your suggestion.

$result_1=mysql_query($sql);

$result_2=mysql_query($sql);

also i have this block of code..
echo " after pin sql";


if (!mysql_query($result_1,$con))
  {
  if(mysql_errno()==1062)
        echo "Sorry! The username has been taken already. Please try another username.";
  else
        die('Error: ' . mysql_error());
  }

//////////////////////////

it gave me this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

1

How about this:

$sql="UPDATE table1 SET col2=$p WHERE col1=$p AND col2 IS NULL";
$result =mysql_query($sql);
echo (mysql_affected_rows()) ? "update OK" : "problem with update: $sql";

$sql="INSERT INTO user(u_id,u_uname, u_fname, u_lname) VALUES ($q,'$username','$fname','$lname')"
$result=mysql_query($sql);
echo (mysql_affected_rows()) ? "insert OK" : "problem with insert: $sql";
0

i tried your first answer..it worked..!! thanks for ur reply..ur name will be in my project references list.. ;) thanks..u took my project one step ahead..Thanks a lot!!

0
//line1
$sql="UPDATE table1 SET col2='$p' WHERE col1='$p' AND col2 IS NULL";
//line2
$sql="INSERT INTO user(u_id,u_uname, u_fname, u_lname) VALUES ('$q','$username','$fname','$lname')"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.