Jump to content

how can I change the table name so I only need one post file?


oraya

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.