oliverj777 Posted July 27, 2010 Share Posted July 27, 2010 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 27, 2010 Share Posted July 27, 2010 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; ?> Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 27, 2010 Share Posted July 27, 2010 And what part isn't working? What are the error messages you're getting? Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 I'm not getting any errors, its just not placing the data into my SQL column ... When I hit submit, the page simply appears to refreshe Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 27, 2010 Share Posted July 27, 2010 This assigns the entire $_POST array to $subwebsite_name, which I'm sure is not what you want to do. $subwebsite_name = $_POST; Should be $subwebsite_name = $_POST['subwebsite_name']; Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 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 ... Quote Link to comment Share on other sites More sharing options...
radar Posted July 27, 2010 Share Posted July 27, 2010 except that website_name isnt listed in your field, as the name is also subwebsite_name Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 27, 2010 Share Posted July 27, 2010 Post all of the relevant code, and let's see what we can do here . . . Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 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 Quote Link to comment Share on other sites More sharing options...
radar Posted July 27, 2010 Share Posted July 27, 2010 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']); } ?> Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 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 ... Quote Link to comment Share on other sites More sharing options...
radar Posted July 27, 2010 Share Posted July 27, 2010 read my post just above you here, and you'll have your solution fixed. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 27, 2010 Share Posted July 27, 2010 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> Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 Still not doing it, When I hit submit, it looks like its just refreshing again ... Could it be a problem in my SQL? I have the website_name in my SQL as a 'text' type, is that important? Thanks Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 I just don't understand what is going wrong here .... Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 WORKS!! AWESOMEE!! I my session logged me out so the user-> didn't work ... all works now!! Thanks guys! Quote Link to comment Share on other sites More sharing options...
radar Posted July 27, 2010 Share Posted July 27, 2010 which code are you using now? and what is the code for updateUserField Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted July 27, 2010 Author Share Posted July 27, 2010 So now that I am able to update my SQL table through a text field - how would I be able to echo what is in that table? (My SQL knowledge sucks) Thanks Quote Link to comment Share on other sites More sharing options...
radar Posted July 27, 2010 Share Posted July 27, 2010 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. 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.