Lee Posted April 7, 2010 Share Posted April 7, 2010 Hi, I am trying to use 1 form to update a page title and a page content. They are both in different tables in the db. I tried the code below, but it won't work. Is there some way I can do it in the same function? function EditHomepage($param) { $connect = db_connect(); if(isset($param['submit'])){ $errors = array(); if(strlen($param['editbody']) < 1) { $errors[] = 'Homepage body must be at least 2 characters.'; } if(strlen($param['edit_title']) == 0) { $errors[] = 'You must enter a page title.'; } if($errors) { return $errors; } else { $homepageBody = mysql_real_escape_string($param['editbody']); $homepageTitle = mysql_real_escape_string($param['edit_title']); $query = sprintf ("UPDATE content, title SET homepage = '$homepageBody', tile,homepage = '$homepageTitle' "); $result = mysql_query($query); if (!$result) { return false; } else { return true; } } } } Quote Link to comment Share on other sites More sharing options...
tomtimms Posted April 7, 2010 Share Posted April 7, 2010 I recommend a WHERE clause in your update query. Otherwise what record is it updating? Quote Link to comment Share on other sites More sharing options...
Lee Posted April 7, 2010 Author Share Posted April 7, 2010 There is and will only ever be only one record in each. Quote Link to comment Share on other sites More sharing options...
tomtimms Posted April 7, 2010 Share Posted April 7, 2010 Gotcha, are you able to have this work? If not what is your database structure like? Quote Link to comment Share on other sites More sharing options...
Lee Posted April 7, 2010 Author Share Posted April 7, 2010 Ok, I'm quite a noob to SQL (the reason for this practice) so I'll explain my db as in caveman terms. Tables in bold, columns in brackets. So far, it doesn't work. DB structure content ( homepage, about_page, contact_page ) title ( homepage, about_page, contact_page ) I guess I could just re-structure the db like this: homepage ( title, content ) about_page ( title, content ) contact_page ( title, content ) But then if I want to add pages, I will need to keep adding more tables. I don't suppose that is so bad.. Thanks for the reply Quote Link to comment Share on other sites More sharing options...
tomtimms Posted April 7, 2010 Share Posted April 7, 2010 I recommend this. content (id,homepage, about_page, contact_page ) title (id,homepage, about_page, contact_page ) set id to 1 then make your query this. $query = sprintf("UPDATE content,title SET homepage = '".$homepageBody."' , title,homepage = '".$homepageTitle."' WHERE id = '1'"); again not tested. Quote Link to comment Share on other sites More sharing options...
Lee Posted April 7, 2010 Author Share Posted April 7, 2010 Thanks, I'll give that a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.