I am working on a website using a MySQL database, certain pages contain tables from the database. Also there is an admin where someone can edit (replace) values in the table. Everything is working, but I have one problem. A row in the table is named 'Best Moment' which contains a space, and there for the code below crashes. So I was wondering if there is anyway to bypass this problem, without having to remove the space (since the table will be build on the website and thus requires the space)

if($momentnew) {
  $sql = "UPDATE Lieneke SET Best moment = REPLACE(Best moment,'$moment','$momentnew')";
  $query = mysql_query($sql) or die(mysql_error()); }

Thanks in advance!

I cant say that I've ever worked with a space in a column name... but I would assume you could use the little tick marks around the name of the field.

$sql = "UPDATE Lieneke SET `Best moment` = REPLACE(`Best moment`,'$moment','$momentnew')";

If your using a tool like phpMyAdmin, you could do the update by simply editing the row and seeing how it formats the update statement.

Thanks for your reply!

Myphpadmin gives the following code, which works :) just adding the the little tick marks didn't do it, but the code below dit!

UPDATE `$tablename`.`Lieneke` SET `Mooiste moment carriere` = '$newinput' WHERE `Lieneke`.`ID` =1 LIMIT 1 ;

thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.