Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql update problem

Status
Not open for further replies.

jartse

Programmer
Apr 10, 2002
15
FI
why this not update my database i have another page where form and it send all data to this

<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<title></title>
</head>
<body>

<?php

$hostname = &quot;localhost&quot;;
$username = &quot;&quot;;
$password = &quot;&quot;;
$usertable = &quot;users&quot;;
$dbName = &quot;myusers&quot;;


MYSQL_CONNECT($hostname, $username, $password) OR DIE(&quot;Unable to connect to database&quot;);
mysql_select_db($dbName) or die( &quot;Unable to select database&quot;);

$result = mysql_query(&quot;
UPDATE $usertable
SET
user_fname = '$user_fname',
user_lname = '$user_lname',
user_pass = '$user_pass',
user_mail = '$user_mail',
hollow_point = '$hollow_point',
hollow_cash = '$hollow_cash',
referrer_id = '$referrer_id',
referrer_cash = $referrer_cash',
WHERE user_id = '$user_id'&quot;);

if ($result) :
print &quot;Osasto $user_id päivitetty: &quot;;
print &quot;$user_fname, $user_lname, $user_pass, $user_mail, $hollow_point, $hollow_cash, $referrer_id, $referrer_cash&quot;;
else :
print &quot;Päivitys epäonnistui!&quot;;
endif;
?>

</body>
</html>
 
referrer_cash = $referrer_cash',
WHERE user_id = '$user_id'&quot;);

perhaps get rid of the , on the last field. it is not right to have a , on the last field
so

referrer_cash = $referrer_cash'
WHERE user_id = '$user_id'&quot;);

I can't judge the rest of the script
 
i have change litle but not work yet

<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<title></title>
</head>
<body>

<?php

$hostname = &quot;localhost&quot;;
$username = &quot;&quot;;
$password = &quot;&quot;;
$usertable = &quot;users&quot;;
$dbName = &quot;hollowcash&quot;;


MYSQL_CONNECT($hostname, $username, $password) OR DIE(&quot;Unable to connect to database&quot;);
mysql_select_db($dbName) or die( &quot;Unable to select database&quot;);

$query = &quot;UPDATE $usertable
SET
user_fname = $user_fname,
user_lname = $user_lname,
user_pass = $user_pass,
user_mail = $user_mail,
hollow_point = $hollow_point,
hollow_cash = $hollow_cash,
referrer_id = $referrer_id,
referrer_cash = $referrer_cash
WHERE user_id = $user_id&quot;;

$results = mysql_query($query) or die(&quot;Query failed&quot;);



?>

</body>
</html>
 
Highlighted a couple of changes, this worked ok for me.

if ($result) {
print &quot;Osasto $user_id päivitetty: &quot;;
print &quot;$user_fname, $user_lname, $user_pass, $user_mail, $hollow_point, $hollow_cash, $referrer_id, $referrer_cash&quot;;
}else{
print &quot;Päivitys epäonnistui!&quot;;
} ***************************************
Party on, dudes!
[cannon]
 
why did you get rid of the single quotes ???
and perhaps try to update only one field.

$result = mysql_query(&quot;
UPDATE myusers
SET user_fname = '$user_fname'
WHERE user_id = '$user_id'&quot;);

and are you sure the connection works ??
 
Thank you KarveR and Hos2
code work now when i try it but database not change
 
stick in a echo mysql_error() after the SQL statement --BB
 
Also when you are doing the query if the field is a integer for example user_id = '$user_id' you don't need the single quotes.

user_id = $user_id


Good Luck,

[ponytails2]
MAO
 
yes he may need.

if user_id is varchar or any field non-numeric he NEEDS the quotes. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
thank you everyone this is final code and it's works like i want to


<html>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<title></title>
</head>
<body bgcolor=&quot;F5F5F5&quot;>

<?php

$hostname = &quot;localhost&quot;;
$username = &quot;&quot;;
$password = &quot;&quot;;
$usertable = &quot;users&quot;;
$dbName = &quot;mydatabase&quot;;


MYSQL_CONNECT($hostname, $username, $password) OR DIE(&quot;Unable to connect to database&quot;);
mysql_select_db($dbName) or die( &quot;Unable to select database&quot;);


$results = mysql_query(&quot;UPDATE $usertable
SET
Firstname = '$Firstname',
Lastname = '$Lastname',
pass = '$pass',
email = '$email',
hollowpoint = '$hollowpoint',
hollowcash = '$hollowcash',
refid = '$refid',
refcash = '$refcash'
WHERE id = '$ID'&quot;);

if ($results){
print &quot;Osasto $ID päivitetty: &quot;;
print &quot;$Firstname, $Lastname, $pass, $email, $hollowpoint, $hollowcash, $refid, $refcash&quot;;
}
else{
print &quot;Päivitys epäonnistui!&quot;;
}

?>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top