oraya Posted June 13, 2012 Share Posted June 13, 2012 Is there a way I can carry over the table name into my post file so that I only need one file for all the different forms? I was wondering if I could put the variable in the post address as I have done below in the form? But after that I can't think how to put it in the update statement. I'm new to php, so be gentle lol.. But with that said I would be so grateful of any help given. My form: <fieldset> <legend class="formtitle"><?php echo $rows ['title'];?></legend> <form action="incl/submit.php?varname=<?php echo $table ?>" method="post"> <input type="hidden" name="id" value="<?php echo $rows['id'];?>" /> <p class="form"><label class="formlabel">Page Title</label> <input type="text" name="title" value="<?php echo $rows['title'];?>" size="30" class="updatesubtitle" /></p> <p class="form"><label class="formlabel">Sub title</label> <input type="text" name="sub_title" value="<?php echo $rows['sub_title'];?>" size="30" class="updatesubtitle" /> * Sub Menu used for brake down of content items.</p> <p class="form"><label class="formlabel">Content</label> <textarea cols="70" rows="20" wrap="virtual" class="updatecontent" name="content"><?php echo $rows['content'];?></textarea></p> <p class="buttons"><input type="submit" value=" Update Content " /> <input type="submit" value=" Cancel " /></p> </form> </fieldset> ------------------- My datapost file: <?php $host = "localhost"; $user = "me"; $pass = "password"; $database = "penfal"; $conn = mysql_connect($host, $user, $pass) or die( mysql_error() ); mysql_select_db($database) or die( mysql_error() ); $id = mysql_real_escape_string( $_POST["id"] ); $title = mysql_real_escape_string( $_POST["title"] ); $sub_title = mysql_real_escape_string( $_POST["sub_title"] ); $content = mysql_real_escape_string( $_POST["content"] ); $sql="UPDATE sometable SET title='$title', sub_title='$sub_title', content='$content' WHERE id='$id'"; $result = mysql_query( $sql ) or die( mysql_error() ); if($result) { header('Location: ../successful.php'); }else{ header('Location: ../problem.php'); } ?> Many many thank yous in advance, Oraya Quote Link to comment https://forums.phpfreaks.com/topic/264139-how-can-i-change-the-table-name-so-i-only-need-one-post-file/ Share on other sites More sharing options...
AMcHarg Posted June 13, 2012 Share Posted June 13, 2012 Please put code into code brackets - it makes it easier to read! You can use a hidden field in your html form. Call it something like "tabletoupdate". You then pull the variable from this as you would any other post variable and add it to your sql. Quote Link to comment https://forums.phpfreaks.com/topic/264139-how-can-i-change-the-table-name-so-i-only-need-one-post-file/#findComment-1353626 Share on other sites More sharing options...
oraya Posted June 13, 2012 Author Share Posted June 13, 2012 Please put code into code brackets - it makes it easier to read! You can use a hidden field in your html form. Call it something like "tabletoupdate". You then pull the variable from this as you would any other post variable and add it to your sql. My apologies! I thought about that, but the bit that's throwing me is how I put it into the update statement? $sql="UPDATE changethetablename SET title='$title', sub_title='$sub_title', content='$content' WHERE id='$id'"; Would you be so kind as to explain how I would put that into the update statement? Many thanks for your help Oraya Quote Link to comment https://forums.phpfreaks.com/topic/264139-how-can-i-change-the-table-name-so-i-only-need-one-post-file/#findComment-1353628 Share on other sites More sharing options...
oraya Posted June 14, 2012 Author Share Posted June 14, 2012 Ok i can see now why I was getting the error in the update statement, sigh... been working on this all evening i had misspelt the variable grrr... thank you again for you help! Quote Link to comment https://forums.phpfreaks.com/topic/264139-how-can-i-change-the-table-name-so-i-only-need-one-post-file/#findComment-1353630 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.