0

I am new to PHP and there is one problem which I don't understand quite well.

I have web form and text fields. When web form loads text field get data from database.

What I am trying to do is to update databse on buton click, actually on second web form load. But data in database is not changing at all.

$first_name = $_POST[textfield];

session_start();
$telegramNum = $_SESSION[telegramNum]; // This is data from first page, this code is 
                                       // on third page, data was from second page

$testDataQuery="UPDATE person_response SET first_name = ".$first_name." WHERE telegram_number= " .$telegramNum;
3
  • how are you connecting to the db? Commented Jan 27, 2011 at 14:32
  • 2
    You're going to need to put quote marks around the text in your query, otherwise MySQL will return an error. eg: first_name = '".$first_name."' WHERE Commented Jan 27, 2011 at 15:00
  • I try that too. That is ok. But I get data from first page. Maybe it is problem because textfield is name of text field for first and for second page too? And I get data from first page, not from second as I wont it. Commented Jan 27, 2011 at 15:10

4 Answers 4

1

First i would read up on some tutorial about connection to database using php. Then learn how to execute queries. Also, read up a little about using mysql_real_escape_string() for data injection.

PHP MySQL connection tutorial

$first_name = $_POST['textfield'];

session_start();
$telegramNum = $_SESSION['telegramNum'];    
$testDataQuery="UPDATE person_response SET first_name = '".$first_name."' WHERE telegram_number= '" .$telegramNum."'";

make sure you use single quote around the data injected in query and also around $_POST and $_SESSION vars

Sign up to request clarification or add additional context in comments.

Comments

0

You should connect to the database and send query. In your code you only assign mysql query to the variable.

Comments

0

You didn't understand me. I connected with database. When page 2 is loading, text fields is updated with data from database.

But when I change some of that text field and go on another page, in that moment I want to update database with this new data. Connection and everything else is ok.

4 Comments

There is no error. Database is updating, but for first_name update is empty cell.
make sure you put quote around $_POST and $_SESSION and then do an echo on $first_name see if its getting value from the post
I try echo $first_name but nothing happens. I don't understand textfield is name of text field from page2. On page3 i have: $first_name = $_POST['textfield']; echo $first_name; But nothing happens.
it would help if you post the codes from page2 and page3. are your forms posting at all?
0

Problem was in form tag. I didn't put hole part of code inside form tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.