Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update where

Author  Topic 

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 15:51:55
table pads with first field pname... val $name
I get a server error in this php. The error is in the update line & I have changed syntax and tried everything i know. What is wrong with this? I want to update the parameters for whatever row contains the $name..
<?php
$name = $_POST["pad"];
$gx = $_POST["xr"];
$gy = $_POST["yr"];
$gz = $_POST["zr"];
$mx = $_POST["xg"];
$mz = $_POST["yg"];


echo "xx$name";


$link = mysql_connect('localhost', 'whitebu4_admins', '****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db('whitebu4_regions', $link);
if (!$db_selected) {
die ('no db ' . mysql_error());
}
else {
UPDATE pads SET global_x ='$gx' WHERE pname = '$name';// , global_y='$gy' , Global_z='$gz' , google_x ='$mx' , google_y ='$mz' WHERE pname = '$name';
}

msqli_close($dbc);
?>

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-16 : 16:00:09
doesnt seem like t-sql. are you using sql server?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-08-16 : 16:08:25
you have to use mysql_query(), you cant write the update statement direct in your php code...

http://php.net/manual/de/function.mysql-query.php


Too old to Rock'n'Roll too young to die.
Go to Top of Page

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 16:13:17
I have this now with no errors but it doesnt update...

$sql = "UPDATE pads SET global_x ='$gx' WHERE pname = '$name'";
Go to Top of Page

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 16:16:05
Withthis I get server error msql_query(UPDATE pads SET global_x ='$gx' WHERE pname = '$name');
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-08-16 : 17:15:11
quote:
Originally posted by dustty

Withthis I get server error msql_query("UPDATE pads SET global_x ='".$gx."' WHERE pname = '".$name."'");


maybe this?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 17:31:57
I have fought this for 4 or 5 days, read 40 dozen wikis and watched 40 dozen tuts. Tried inserts and about every php example given and now this update.

This code gives no errors but like all the rest nothing is changed in the data base. I have used mysql in the past What the hell have they done with the damn updates and versions?
<?php
$name = $_POST["pad"];
$gx = $_POST["xr"];
$gy = $_POST["yr"];
$gz = $_POST["zr"];
$mx = $_POST["xg"];
$mz = $_POST["yg"];


echo "xx$name";


$link = mysql_connect('localhost', 'whitebu4_admins', 'admins123');
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db('whitebu4_regions', $link);
if (!$db_selected) {
die ('no db ' . mysql_error());
}
else {

$result = msql_query("UPDATE pads SET global_x ='$gx' WHERE pname = '$name'");
if (!$result) {
die('Invalid query: ' . mysql_error());}
}

echo "updated";


msqli_close($dbc);
?>

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-08-16 : 17:52:15
In my last answer there was an approach to concatenate the variables - did you try my solution?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 19:02:23
I just see my copied quote And maybe this? I dont see your approach.. Could you repost..
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-08-16 : 19:14:12
msql_query("UPDATE pads SET global_x ='".$gx."' WHERE pname = '".$name."'");



Too old to Rock'n'Roll too young to die.
Go to Top of Page

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 19:37:27
Ok tried it I had an insert statement that worked...using those values.. I replaced it with your update statement. ,, It does not change the database. Can you tell why by comparing?

mysql_query("INSERT INTO pads (pname,global_x,global_y,global_z,google_x,google_y) VALUES('$name' , '$gx' , '$gy' ,'$gz', '$mx', '$mz')") or die(mysql_error());
Go to Top of Page

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 20:00:27
db [url] http://s1141.photobucket.com/albums/n594/karyoker/?action=view¤t=db2.png[/url]
Go to Top of Page

dustty
Starting Member

8 Posts

Posted - 2012-08-16 : 20:01:11
db
Go to Top of Page
   

- Advertisement -