Jump to content

Updating SQL through Text Field


oliverj777

Recommended Posts

Hello,

 

I'm trying to update some data from a text field into an SQL table that already exists. Here is my code:

 

<?php
include("include/session.php");

$subwebsite_name = $_POST;
?>
<form name="form" method="post" action="">
  <input name="subwebsite_name" type="text" value="<?=$subwebsite_name;?>">
  <input type="submit" name="button" id="button" value="Submit">
</form>
<?
$database->updateUserField($session->username,"website_name",$subwebsite_name);
?>

 

Please help, I'm sure its an easy fix :)

Link to comment
Share on other sites

It would probably be easier if you'd say what kind of problem you're having, what errors are being produced, etc., but if it's what I suspect it is, get rid of the lazy quick echo syntax <?=$subwebsite_name;?> and use the proper tags [tt]<?php echo $subwebsite_name; ?>

Link to comment
Share on other sites

Basically, here what I want to happen.

 

User inputs data into text field (ed, the word "Hello")

Click submit,

 

The data is then submitted to SQL, but I already have a table in SQL, and all i want to be done is to update a column of data, so it would now say 'Hello' within the website_name column of my SQL.

 

Thats it ... Thanks

Link to comment
Share on other sites

Humm,

 

Maybe I've written the code completely wrong.

 

All I want to do is save the input data of a text field into my SQL table, which is located by this code:

 

$database->updateUserField($session->username,"website_name",$subwebsite_name);

 

(website_name is the name of the field in my table)

(subwebsite_name is the new data being placed into my table)

 

Can you pleaseeee help me. To me it sounds like such a simple thing to do, but I've been fighting over it for about 5 hours now ... It's ridiculous.

 

Thanks ...

Link to comment
Share on other sites

Okay,

 

Here is the form, where the user input data into the text field:

 

<form method="post">

  <input name="website_form" type="text">

  <input type="submit" name="button" id="button" value="submit">

</form>

 

Then here is the PHP which is suppose to save the data into my SQL table:

 

<?
if(isset($_POST['submit'])){
$_POST = $website_form;
$_website_form = $website_name;
$database->updateUserField($session->username,"website_name",$website_name);
}
?>

 

But the PHP code is completely wrong, I don't know how to tell PHP to save that data from the text field into:

$database->updateUserField($session->username (this is where the data in my SQL table needs to be saved - the location)

 

Thanks

Link to comment
Share on other sites

you have it completely wrong is why...

 

<form name="website_form" method="post">

<input name="website_name" type="text">

<input type="submit" name="button" id="button" value="submit">

</form>

 

<?php

if(isset($_POST['website_name'])) {

$database->updateUserField($session->username, "website_name", $_POST['website_name']);

}

?>

 

Link to comment
Share on other sites

Bearing in mind,

 

When I do this:

 

$website_name = 'hello';
$database->updateUserField($session->username,"website_name",$website_name);

 

It works, it places 'hello' into my SQL table. But I want to replace 'hello' with an input field so a user can input anything they want into the table ...

Link to comment
Share on other sites

Not tested, but try this.

 

<?php
include("include/session.php");
if( $_POST['submitted'] == 'true' ) {
$subwebsite_name = mysql_real_escape_string(trim($_POST['subwebsite_name']));
if( !empty($subwebsite_name) ) {
	if( $database->updateUserField($session->username,"website_name",$subwebsite_name) ) {
		echo 'Query succeeded.';
	} else {
		echo 'Query failed.';
	}
}
}
?>
<form name="form" method="post" action="">
  <input name="subwebsite_name" type="text" value="<?php echo $subwebsite_name; ?>">
  <input type="hidden" name="submitted" value="true" />
  <input type="submit" name="button" id="button" value="Submit">
</form>

Link to comment
Share on other sites

Both work, so I'll use either.

 

$database->updateUserField($session->username,

 

Is what i'm using to access my session. Because the table in the SQL is different depending on who is logged into the website, and the code determines the location of the columns in the table according to the user.

Link to comment
Share on other sites

something like this would work..

 

@ beginning of file  prior to form

 

$data = mysql_result(mysql_query("SELECT 'table_name' FROM table"), 0);

 

then in the form value = "<?php echo $data; ?>"

 

that would work.

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.