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!
if($submit == "true"){
$price = $_POST['price'];
$location = $_POST['location'];
foreach($_POST['checkbox'] as $value) {
$longstring .= $value."' or userID ='"."\r\n";
}
$str = "Select * from boxers where userID = '".$longstring;
$str = substr($str, 0, -14); // takes away the last or userID =
echo $str; // which outputs Select * from boxers where userID = 'haf1' or userID = 'haf2'
// Which it exactly what I want - but when adding to the database
$result=MYSQL_QUERY( "update table SET string='$str' ");
it results in Select * from boxers wh being added ?? not the whole string
Any ideas ??
basically what I'm doing is having a list of checkboxes which when submitted it creates a string in the database to pull a result in another page.
Select * from boxers where userID = 'haf1' or userID = 'haf2'
haf1 and haf2 being 2 of the checkboxes
Cheers
Last edited by leewad on Tue May 11, 2004 8:55 am, edited 2 times in total.
foreach($_POSTї'checkbox'] as $value) {
$longstringї] = "userID='".$value."'";
}
$str = 'Select * from boxers where '.join(' OR ', $longstring);
produces the following error:
Invalid query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'haf2''' at line 1
Hmm..yeah, UPDATE and SELECT are 2 different things. I'm not sure what you're trying to do, SELECT or UPDATE?
UPDATE syntax should be UPDATE boxers SET string='whatever' WHERE something='blah' ... i'm not sure where your select comes into it. Maybe you want to "UPDATE boxers SET string='whatever' WHERE $longstring"; ? and not even bother with a select *shrug*
$result=MYSQL_QUERY( "update table SET string='$str' where 1 ");
should both work - i have other fields updating along side this which is not menioned - but this string is the only problem I have in getting it updated in the database - I can create the string but there is something about it with is stopping it updating maybe its the ' ' in the string ?