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?

Recommended Answers

All 5 Replies

Member Avatar for diafol

If you run the SQL with mysql_query in between the lines, it should be OK?

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

Member Avatar for diafol

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";

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!!

//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')"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.