KYKK Posted August 26, 2008 Share Posted August 26, 2008 so i want to like update user info, and i create <?php session_start() $con = mysql_connect("localhost","ksclans_ksclans","pass");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("carn", $con);mysql_query("INSERT INTO carn (title) VALUES ('title')"); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Index</title> </head> <body> <?php if (isset($_SESSION['user_id'])) { ?> Hello, <?php echo $_SESSION['user_name']; ?> <form action="index.php" method="post"> <input type="hidden" name="page_mode" value="save"> <h5>title</h5> <input type="text" name="title" size="30" maxlength="255" value="<?php if (isset($title)) echo $title; ?>"></div> <div class="left_box"> </div> <div class="right_box"><input type="submit" value="save" size="30"></div> </form> <br><br> <a href="logout.php">Log out</a> <?php } else { ?> Click <a href="register.php">here</a> to register or click <a href="login.php">here</a> to log in. <?php } ?> </body></html> and it say Parse error: syntax error, unexpected T_VARIABLE in /home/ksclans/public_html/carn/admin/index.php on line 4this line 4$con = mysql_connect("localhost","ksclans_ksclans","pass");what wrong with that? and anything wrong with mysql_query("INSERT INTO carn (title) VALUES ('title')"); ?> Link to comment Share on other sites More sharing options...
Jesdisciple Posted August 26, 2008 Share Posted August 26, 2008 You need to terminate your previous statement with a semicolon: <?php session_start(); I don't see anything wrong with your query. Link to comment Share on other sites More sharing options...
jeffman Posted August 26, 2008 Share Posted August 26, 2008 Missing punctuation almost always gets reported as an error farther down the page. FWIW Link to comment Share on other sites More sharing options...
KYKK Posted August 26, 2008 Author Share Posted August 26, 2008 I using the http://w3schools.invisionzone.com/index.php?showtopic=12509 register-login that codes so i need <?php session_start(); to login and then what is semicolon? ,,, Deirdre'sDad what Missing punctuation do you mean like "" '' this kind of forget to close that Missing punctuation >? and i don't see any in my codes.. Link to comment Share on other sites More sharing options...
jeffman Posted August 26, 2008 Share Posted August 26, 2008 Punctuation: " ' , ; : ) ( } {, and so on. This is a semicolon (, the item you were missing at first. Error reporting doen't always give you the correct line of code when punctuation is missing. It usually figures it out several or even many lines later on.I was really just commenting, not adding advice to your particular question. Link to comment Share on other sites More sharing options...
Jesdisciple Posted August 26, 2008 Share Posted August 26, 2008 Eh, because Dad forgot to disable smilies, his semicolon didn't show... Here it is, 2 lines down:; Link to comment Share on other sites More sharing options...
KYKK Posted August 26, 2008 Author Share Posted August 26, 2008 because of that little ; make me stop working for a day !........... thank guys any question i post later Link to comment Share on other sites More sharing options...
KYKK Posted August 27, 2008 Author Share Posted August 27, 2008 ok so i have register-login and there some empty column, should i use insert or update to get info to the database? <?php session_start() ;$con = mysql_connect("localhost","ksclans_ksclans","apassword");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("carn", $con); $title = $_POST['title'];mysql_query("INSERT INTO carn ('title') VALUES ('title')"); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Index</title> </head> <body> <?php if (isset($_SESSION['user_id'])) { ?> Hello, <?php echo $_SESSION['user_name']; ?> <form action="index.php" method="post"> <input type="hidden" name="page_mode" value="update"> <h5>title</h5> <input type="text" name="title" size="30" maxlength="255" value="<?php if (isset($title)) echo $title; ?>"></div> <div class="left_box"> </div> <div class="right_box"><input type="submit" value="update" size="30"></div> </form> <a href="logout.php">Log out</a> <?php } else { ?> Click <a href="register.php">here</a> to register or click <a href="login.php">here</a> to log in. <?php } ?> </body></html> what wrong i put something and press the button the something stay there so <input type="text" name="title" size="30" maxlength="255" value="<?php if (isset($title)) echo $title; ?>"></div> is right but nothing show in phpadmin why what wrong? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 27, 2008 Share Posted August 27, 2008 ok so i have register-login and there some empty column, should i use insert or update to get info to the database?An insert query adds a new record to the database, an update query will update an existing record. Link to comment Share on other sites More sharing options...
KYKK Posted August 27, 2008 Author Share Posted August 27, 2008 so anything wrong with my code because i can't see anything in my database Link to comment Share on other sites More sharing options...
justsomeguy Posted August 27, 2008 Share Posted August 27, 2008 With this statement:mysql_query("INSERT INTO carn ('title') VALUES ('title')");The field names do not go in quotes. Quotes mean a string, and you're trying to refer to a field, so remove the quotes around the field name. After you do that, executing that query will insert the string "title" into the title field in the carn table as a new record.You can also use mysql_error to look for errors, it would have told you about that error. Link to comment Share on other sites More sharing options...
KYKK Posted August 27, 2008 Author Share Posted August 27, 2008 ok so I start over so first step i made db.php which connect to database, and my database is ksclans_website and table is users (new table not carn anymore..) and have field name title want to add data to it and so <?phprequire_once 'db.php'; db_query("INSERT INTO users (title) VALUES ('title')"); exit();?> ok so field don't have "" or '' and values have it copy from mysql insert tutorial from w3school right?so i add the formthere is a question inside the code there.... <form action="index.php" method="post"> <input type="hidden" name="page_mode" value="title"> <div class="left_box">title</div> <div class="right_box"><input type="text" name="title" size="30" maxlength="255" value=" IS IT OK TO PUT NOTHING HERE ????? "></div> <div class="left_box"> </div> <div class="right_box"><input type="submit" value="update" size="30"></div> and anything wrong? because i don't see the form why? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 27, 2008 Share Posted August 27, 2008 Well, I see an exit statement in the PHP code, is the form on the same page? The value attribute for an input is optional. Link to comment Share on other sites More sharing options...
KYKK Posted August 28, 2008 Author Share Posted August 28, 2008 omg lol yes i keep testing and there all those row with just title title tiele... i need to put input instead of VALUES ('title')") so i go look at your script and why ('{$email}')"); not just ($email) and so i do require_once 'db.php'; $title = $_POST['title']; db_query("INSERT INTO users (title) VALUES ('{$title}')");is it right? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2008 Share Posted August 28, 2008 It's just "more correct" to use curly brackets when you have a variable in a string. It's good practice, and for some situations it's necessary. Link to comment Share on other sites More sharing options...
KYKK Posted August 28, 2008 Author Share Posted August 28, 2008 ook i need to login to save the data to the user row right? so how do i do that i mean like INSERT INTO table_name (column1, column2,...)VALUES (value1, value2,....)there no insert into user name so how to do that?or i use like your session thingy ? like session start ?...so i use <?phpsession_start();require_once 'db.php'; $title = $_POST['title']; db_query("INSERT INTO users (title) VALUES ('{$title}')");?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Index</title> </head> <body> <?php if (isset($_SESSION['user_id'])) { ?> Hello, <?php echo $_SESSION['user_name']; ?>, <form action="index.php" method="post"> <input type="hidden" name="page_mode" value="title"> <div class="left_box">title</div> <div class="right_box"><input type="text" name="title" size="30" maxlength="255" value="title"></div> <div class="left_box"> </div> <div class="right_box"><input type="submit" value="update" size="30"></div> <br><br> <a href="logout.php">Log out</a> <?php } else { ?> Click <a href="register.php">here</a> to register or click <a href="login.php">here</a> to log in. <?php } ?> </body></html> but I can see that hello user that one but it still don't save data to that user row Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2008 Share Posted August 28, 2008 One of us is confused, if someone is logging in then you shouldn't be using an insert statement. They should already be in the database. If a user is making a new account then you would insert, but if they are logging in then you use select to find them in the database and check their password. Once they are logged in, if you want to change the information in the database then you use update. What are you trying to insert? What data are you trying to save to the user record? Link to comment Share on other sites More sharing options...
KYKK Posted August 28, 2008 Author Share Posted August 28, 2008 ok so I am making a website that let users to create a simple "website" or like a profile about themselves, and clans i am in to make a 'website' to show others what their clan look like so i making a website that help people to put words on webpages...so i have the register-login thingy you have in php tips... so I want to login and a box to type words and other page to see those words, it can't be cookie right? like vistor come they don't have cookie then they don't see it ...so i need to use database, and the title to put in the title of clan or their name, so i made title on same table as the users so my database-table isdatabase: ksclans_website table is users and table have field : id name password email ( from your tips section and i add ) titledid it do it right? and so it empty because i didn't put title in register page so insert or update? or should i do like put title or something field title in the database at register page then when the user login he can use update, and if not insert first and 2nd time he use it need update so anyway to change insert to update after something is there ? get what i mean.... Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2008 Share Posted August 28, 2008 When someone registers for a new account, you do your insert statement there to add their information. If you want to have the title on that form as well then you can add that to the insert statement (don't insert *only* the title, add it with the rest of the user's information). Once they log in they should have a way to update their information, and you use the update statement there if they want to change something.note: statistcally, there's a 67% chance of your next post starting with "ok" or "so", and a 33% chance of it starting with "ok so". Link to comment Share on other sites More sharing options...
KYKK Posted August 28, 2008 Author Share Posted August 28, 2008 without saying ok, i should say I get what you mean? i understand now?... and try not to say so think about before i type...so you mean put in something when they register like db_query("INSERT INTO users (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");and add db_query("INSERT INTO users (email, name, password, title) VALUES ('{$email}', '{$name}', '{$password}', "title")");like that? and after register and they login then use update likemysql_query("UPDATE users SET title = '{$title}' WHERE username= ' HOW TO PUT SESSION USER NAME ?? ' ");i don't know how to put session username at the username field..is that what you mean??_______________________________________________if so....do that mean i can't add new fields? for example my clans use the website i made to make webpages, and i add some new stuff like forums...and how i make codes for them to update or insert? because i can't ask so much people to re-register to put something there first and login to UPDATE data....i talk good now? not very good with english Link to comment Share on other sites More sharing options...
KYKK Posted August 28, 2008 Author Share Posted August 28, 2008 ( INTERNET problem and i reload the page and it send the reply again sry for double post)without saying ok, i should say I get what you mean? i understand now?... and try not to say so think about before i type...so you mean put in something when they register like db_query("INSERT INTO users (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");and add db_query("INSERT INTO users (email, name, password, title) VALUES ('{$email}', '{$name}', '{$password}', "title")");like that? and after register and they login then use update likemysql_query("UPDATE users SET title = '{$title}' WHERE username= ' HOW TO PUT SESSION USER NAME ?? ' ");i don't know how to put session username at the username field..is that what you mean??_______________________________________________if so....do that mean i can't add new fields? for example my clans use the website i made to make webpages, and i add some new stuff like forums...and how i make codes for them to update or insert? because i can't ask so much people to re-register to put something there first and login to UPDATE data....i talk good now? not very good with english Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2008 Share Posted August 28, 2008 You can add anything you want to the database, that's up to you. What I mean about updating is like you see with any site that has user accounts. On this forum if you sign in you can click on the My Controls link to look at your account information and make changes. That's what I'm talking about, when someone logs in you will want to set up a page where they can go to change their information. I'm not suggesting that immediately when someone logs in you run an update statement, just give them a link to a page that has their account information on it where they can change anything. You can add whatever database fields you want and give them a place to change that information on their update page. The session variables work like $_POST or $_GET, you just use $_SESSION instead. If you save their username in $_SESSION['username'] on the login page, then on the update page you get the username from $_SESSION['username']. Link to comment Share on other sites More sharing options...
KYKK Posted August 28, 2008 Author Share Posted August 28, 2008 oook what different between $_POST ? in w3school tutorial PHP $_GET PHP $_POST is under php and insert and update is under mysql, and i think like post and get is cookie or session stuff without go through database right? and visitors can't see them because they don't have session and cookie right? and insert and update is to get data to database and to get it need $_SESSION['user_email'] = $row['email']; but i still can't insert stuff to my database! ... and update is like remove the old data and add the new one right? OR meaning that add stuff to a row? <?phpsession_start();require_once 'db.php'; $title = $_POST['title'];mysql_query("UPDATE users SET title='{$title}'WHERE name='$_SESSION['user_name']");?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Index</title> </head> <body> <?php if (isset($_SESSION['user_id'])) { ?> Hello, <?php echo $_SESSION['user_name']; ?>, <form action="index.php" method="post"> <input type="hidden" name="page_mode" value="title"> <div class="left_box">title</div> <div class="right_box"><input type="text" name="title" size="30" maxlength="255" value="title"></div> <div class="left_box"> </div> <div class="right_box"><input type="submit" value="update" size="30"></div> <br><br> <a href="logout.php">Log out</a> <?php } else { ?> Click <a href="register.php">here</a> to register or click <a href="login.php">here</a> to log in. <?php } ?> </body></html> what i missing?_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRINGso much error.. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 29, 2008 Share Posted August 29, 2008 and i think like post and get is cookie or session stuff without go through database rightNo; post, get, cookies, and sessions are 4 different things, and none of them have anything to do with a database. They are different ways of passing information between pages. If you have a URL like this:page.php?var=testThen the value "test" will be in $_GET['var']. That's what $_GET is used for. If you have a form like this:<form action="page.php" method="post"><input type="text" name="var" value="test">Then the value "test" will be in $_POST['var']. That's what $_POST is used for. If your browser sends the server a cookie called "var" with the value "test", then $_COOKIES['var'] will be "test". The $_SESSION collection only holds information that you add to it, information doesn't get automatically put there by anything else. When you save a variable to $_SESSION, you can access the value on other pages. Using the session is similar to using cookies, but a session will only last as long as the user has their browser open.and update is like remove the old data and add the new one rightUpdate doesn't add or remove, it only changes. If your database has this record in it:id name age-----------------------10 Joe 30 and you execute this query:UPDATE table SET age=31 WHERE id=10Then it updates that record in the database to change the age to 31. It doesn't delete anything, and it doesn't add anything. It updates the existing record and that's all.Your update query is missing a quote. mysql_query("UPDATE users SET title='{$title}'WHERE name='{$_SESSION['user_name']}'"); Link to comment Share on other sites More sharing options...
KYKK Posted August 29, 2008 Author Share Posted August 29, 2008 great thx it worked, and is it possible using codes to make a button to "add a new page" to my file manager? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.