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
https://forums.phpfreaks.com/topic/209038-updating-sql-through-text-field/
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; ?>

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

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 ...

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

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']);

}

?>

 

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 ...

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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.