PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Fri Jul 30, 2004 9:13 pm
what am i missing here?
Code: Select all
<?php
$sql = "
UPDATE $table_name
SET print = 'no'
WHERE id = 'id_1'
";
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Fri Jul 30, 2004 9:28 pm
Aren't ID's usually numeric?
Anyways, you never execute the query.
Code: Select all
<?php
$conn = mysql_connect("user","pass","localhost");
mysql_select_db("mydatabase");
$table_name = "mytable";
$sql = "UPDATE $table_name SET print = 'no' WHERE id = 'id_1'";
mysql_query($sql);
?>
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Jul 30, 2004 9:39 pm
with a query like that, better off to throw in a:
or die(mysql_error());
in there =]
Lord Sauron
Forum Commoner
Posts: 85 Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL
Post
by Lord Sauron » Fri Aug 27, 2004 3:29 am
It isn't that hard
Just leave the $-sign out, when your using a table name. And use a $-sign when you are using a php-variable (I guess id_1 is a php variable?)
$sql = "UPDATE table_name SET print = 'no' WHERE id = '$id_1'";
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Fri Aug 27, 2004 4:37 pm
ahhh! evil post digger! *puts fingers crossed* be gone evil doer!
anywho, he may be setting the table dynamically or above the query, meaning the $ should be there.
Vash the Stampede
Forum Newbie
Posts: 7 Joined: Tue Mar 30, 2004 6:15 pm
Post
by Vash the Stampede » Fri Aug 27, 2004 5:22 pm
LiLpunkSkateR wrote: anywho, he may be setting the table dynamically or above the query, meaning the $ should be there.
If he is setting it dynamically shouldn't he do it like this (assuming he has already done the connection the the database earlier):
Code: Select all
<?php
$table_name = "mytable";
$sql = "UPDATE ". $table_name ." SET print = 'no' WHERE id = 'id_1'";
?>
I always have had problems when putting a var in with out the
". $var ." in sql statements.
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Fri Aug 27, 2004 8:18 pm
Code: Select all
$sql = "SELECT * FROM $table"; //valid
$sql = "SELECT * FROM " . $table; //better
Both work.
Code: Select all
$sql = 'SELECT * FROM $table'; //NOT valid
does not work however.