Page 1 of 1
whats wrong with this????????
Posted: Fri Jul 30, 2004 9:13 pm
by hward
what am i missing here?
Code: Select all
<?php
$sql = "
UPDATE $table_name
SET print = 'no'
WHERE id = 'id_1'
";
?>
Posted: Fri Jul 30, 2004 9:28 pm
by d3ad1ysp0rk
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);
?>
Posted: Fri Jul 30, 2004 9:35 pm
by John Cartwright
what am i missing here?
you tell us..
Posted: Fri Jul 30, 2004 9:39 pm
by tim
with a query like that, better off to throw in a:
or die(mysql_error());
in there =]
Posted: Fri Aug 27, 2004 3:29 am
by Lord Sauron
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'";
Posted: Fri Aug 27, 2004 4:37 pm
by d3ad1ysp0rk
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.
Posted: Fri Aug 27, 2004 5:22 pm
by Vash the Stampede
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.
Posted: Fri Aug 27, 2004 8:18 pm
by d3ad1ysp0rk
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.