Forum Moderators: coopster

Message Too Old, No Replies

No PHP or MySQL errors but Query does not work

cannot figure it out!

         

henry0

2:19 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I cannot find what is wrong with the following:
the first 2 lines are part of a form that passes values to the second script
however values are not passed to the DB
script is not generating errors and I connect fine
do you see a coding problem
thanks
regards
Henry

<form action ="update_camp.php" method="post">

Enter your Profile Username:<input type="text" name="user_name" value="<?php echo $user_name;?>">
<br>

<?

include "connect_db.inc";

$query = "insert into profile where user_name='$user_name' VALUES ('$awarness','$promote' ,'$foster' ,'$communication')";
$result= mysql_query ($query);
if ($user_name == ""){
echo"<b>Missing field try again</b>";
}
else
{ etc......

Nick_W

2:22 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try using the superglobals array: $_POST['username']

Nick

henry0

3:00 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks I will
I should also have defined VALUES, values are col names

henry0

3:52 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it does not work even after trying the older $http_post_vars

what really puzzles me is that I have that script working
within amother code section
altough w/out the where user_name=$username

regards
HEnry

bcc1234

4:03 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't use php or mysql but
insert into ... where ... - is not a valid sql syntax, afaik.

You can either add a row to a table with insert or update a row in a table with "update... where..."

RonPK

4:08 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A WHERE clause in an INSERT instruction seems quite useless. WHERE searches for an existing row, whereas you're trying to insert a new row.

Also, try using

mysql_query ($query) or die(mysql_error());
to show MySQL errors.

henry0

4:14 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BCC1234
I do not get it
I used the same in many scripts and never had a problem

as I mentioned my only script change with the above is that
I need to add a qualifier such as a user_name to select the row and col that needs to get data in

regards

RonPK

4:26 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Come on Henry, surely we don't have to explain the difference between INSERT and UPDATE?

henry0

4:44 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ooooooooppppppsss
my mistake
thank you

henry0

6:25 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK since I am only half way brainless/braindead :)

I made it working that way:
<<<
<?
$query = "update profile set awarness = ('$awarness') ,
promote = ('$promote'),
foster = ('$foster') ,
communication = ('$communication')
where user_name='$user_name'";
$result= mysql_query ($query);
>>>

regards