Jump to content

little help


KYKK

Recommended Posts

my file manager using cpanel you use that? i going to read through that manuel any question i will ask you :) do you have MSN i want to get help from you as quickly as possible so i don;t need to wait for reply...but if you want like people to see my questions here in forums then....or i can tell you i have a new question and come look at it :) anyway thank for helping

Link to comment
Share on other sites

i think i forgot something so, is this how to read data from database ? you saypost, get, cookies, and sessions are 4 different things, and none of them have anything to do with a database.i went to w3 tutorial and go to MySQL Select, and it SELECT column_name FROM table_name, how i select user that login with the session so i look at your login codes

 $result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'");

I went to my index and add

  db_query("SELECT id, name, title FROM users WHERE name='{$_SESSION['user_name']}'"); 

but how do i make the title of pages to have the title i put in database? do i like make title a session and i put down $_SESSION['title'] = $row['title']; and in header i put <title><?php echo $_SESSION['user_name']; ?></title>any better way i now need to select the row and make it session and read session , any other way without going through session?

Link to comment
Share on other sites

It sounds to me like you're doing it right (except the indexes you use aren't the same - "title" and "user_name")... But I don't understand this:

i now need to select the row and make it session and read session

Can you rephrase the last part (after "row")?

Link to comment
Share on other sites

so a row in database is a list of stuff about 1 user and include name email password title and i find this db_query("SELECT id, name, title FROM users WHERE name='{$_SESSION['user_name']}'"); so i know how to select name FROM that session user_name which is the one who login so i select that and only that user info... but i don't know how to put it so it show on the website, so question is What do i do after select data ? and on make it session and read sessionthat i look back at the login.php code and it Post session of user_name and in index.php it read that session because that go from page to page so now it same page so do i still need to do session?

Link to comment
Share on other sites

so a row in database is a list of stuff about 1 user and include name email password title and i find this db_query("SELECT id, name, title FROM users WHERE name='{$_SESSION['user_name']}'"); so i know how to select name FROM that session user_name which is the one who login so i select that and only that user info... but i don't know how to put it so it show on the website, so question is What do i do after select data ?
See the second example code at The PHP Manual: mysql_query. Use a result function and handle your data however you need to.
and on make it session and read sessionthat i look back at the login.php code and it Post session of user_name and in index.php it read that session because that go from page to page so now it same page so do i still need to do session?
Do you need the session data when the user requests a new page? For example, do you need to customize the title of any pages other than the welcome page?
Link to comment
Share on other sites

I read the link you send me and i don't really understand what result really is... the link say // This shows the actual query sent to MySQL, and the error. Useful for debugging. //but do I need that? and i look at $query = sprintf("SELECT id, name, email, title FROM users WHERE name='$_SESSION['user_name']'";what is sprintf ?

Link to comment
Share on other sites

I read the link you send me and i don't really understand what result really is...
$result is a variable of the "resource" type because that's what mysql_query returns. Resources are different from the other types because 1) you can't directly tell what's in them, and 2) you can't initialize them. PHP initializes and manipulates them "under the hood" via functions like mysql_query and mysql_fetch_assoc.
the link say // This shows the actual query sent to MySQL, and the error. Useful for debugging. //but do I need that?
I suppose this depends on whether you want your users to see the error message (so they could more precisely report the bug to you). Depending on your user base, they might be scared away by an error message, or they might not bother to report the bug anyway.
and i look at $query = sprintf("SELECT id, name, email, title FROM users WHERE name='$_SESSION['user_name']'";what is sprintf ?
$query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",	mysql_real_escape_string($firstname),	mysql_real_escape_string($lastname));

That code is equivalent to this:

$query = "SELECT firstname, lastname, address, age FROM friends WHERE firstname='" . mysql_real_escape_string($firstname) . "' AND lastname='" . mysql_real_escape_string($lastname) . "'";

Look the function up in the manual for more detailed info.But neither of these was what I wanted to show you...

// Use result// Attempting to print $result won't allow access to information in the resource// One of the mysql result functions must be used// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.while ($row = mysql_fetch_assoc($result)) {	echo $row['firstname'];	echo $row['lastname'];	echo $row['address'];	echo $row['age'];}

That's one way to get the data out of the resource, one row at a time; other similar methods are listed in the last comment.

Link to comment
Share on other sites

um.. ok so i put $query = ("SELECT id, name, email, title FROM users WHERE name=$_SESSION['user_name']";what wrong it sayT_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on that line..i check if i miss any ' ' "" but i don't think so

<?phpsession_start();require_once 'db.php';  $title = $_POST['title'];mysql_query("UPDATE users SET title='{$title}'WHERE name={$_SESSION['user_name']}");$query = ("SELECT id, name, email, title FROM users 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>               </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>

Link to comment
Share on other sites

great it work !!! but it won't read data still <?php echo $row['title']; ?>i already select and echo row what i need to put else?

<?phpsession_start();require_once 'db.php';  $title = $_POST['title'];mysql_query("UPDATE users SET title='{$title}'WHERE name={$_SESSION['user_name']}");$query = ("SELECT id, name, email, title FROM users 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></title>  </head>  <body>    <?php    if (isset($_SESSION['user_id']))    {    ?>        Hello, <?php echo $_SESSION['user_name']; ?>,                     <?php echo $row['title']; ?>                 <form action="index.php" method="post">    <input type="hidden" name="page_mode" value="">    <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>

i put select, and <?php echo $row['title']; ?> and why it don't work

Link to comment
Share on other sites

ok so here my codes

<?phpsession_start();require_once 'db.php';  $title = $_POST['title'];mysql_query("UPDATE users SET title='{$title}'WHERE name={$_SESSION['user_name']}");$query = ("SELECT id, name, email, title FROM users 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></title>  </head>  <body>    <?php    if (isset($_SESSION['user_id']))    {    ?>        Hello, <?php echo $_SESSION['user_name']; ?>,     <?php echo $row['name']; ?> <?php echo $row['title']; ?>         <form action="index.php" method="post">    <input type="hidden" name="page_mode" value="">    <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>

my database field is name, title, email, id, password and i put echo row title and name but it don't show why? I selected and Echo row

Link to comment
Share on other sites

i put echo row title and name but it don't show why?
Because there's no data in the database. If there was data in the database then it would show, right? You still have a problem with missing quotes though. String values need to be quoted. If you don't quote something it thinks that it's a name for something else, not a value. If you want to search for a specific value you need to quote it. The value you're looking up for the name field needs quotes around it.
Link to comment
Share on other sites

to make things clear let do thiswhat this call '' what this call ""what this call { } what this call [ ] what this call ( ) that call quotes, in my kind of english..and for SELECT is it a value $query = ("SELECT id, name, email, title FROM users WHERE name={$_SESSION['user_name']}");and i think <?php echo $row['title']; ?> is fine right? $title = $_POST['title']; ?i am sry if this annoying but i want to know what quotes you talking about and i am SURE that there is data in database thank you a lot

Link to comment
Share on other sites

what this call '' single quoteswhat this call ""double quoteswhat this call { } curly bracketswhat this call [ ] square bracketswhat this call ( )parenthesesIn general you need quotes, either single or double. In a SQL statement, it's single quotes specifically.$query = ("SELECT id, name, email, title FROM users WHERE name='{$_SESSION['user_name']}'");

and i think <?php echo $row['title']; ?> is fine right? $title = $_POST['title']; ?
that's right
Link to comment
Share on other sites

What is the problem i still can't see it i add quotes are there a machine that check errors....so this what i havinghttp://clanwebsite.co.cc/admin/index.php

<?phpsession_start();require_once 'db.php';  $title = $_POST['title'];mysql_query("UPDATE users SET title='{$title}'WHERE name={$_SESSION['user_name']}");$query = ("SELECT id, name, email, title FROM users 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></title>  </head>  <body>    <?php    if (isset($_SESSION['user_id']))    {    ?>        Hello, <?php echo $_SESSION['user_name']; ?>,        <p>start row</p><?php echo $row['name']; ?> <?php echo $row['users_title']; ?><?php echo $row['title']; ?><p>end row</p>              <form action="index.php" method="post">    <input type="hidden" name="page_mode" value="">    <div class="left_box">title FOR FORM</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>

I don't see there any problem with my codes...

Link to comment
Share on other sites

How do you know your database has data? Do you have a database administration application like phpMyAdmin, cPanel, etc.? If not, how have you ever managed to see the data?

Link to comment
Share on other sites

This line needs quotes also:mysql_query("UPDATE users SET title='{$title}'WHERE name='{$_SESSION['user_name']}'");You can also check if a query fails and show an error if it does (the error doesn't get shown automatically).mysql_query("UPDATE users SET title='{$title}'WHERE name='{$_SESSION['user_name']}'") or exit(mysql_error());

Link to comment
Share on other sites

o my god....i did something and now I can't update my data! are there a exsample of CMS that i can look at like register-login the one justsomeguy didEDITOK great it work but it still don't show or read data from database and i can update to change at anytime $query = ("SELECT id, name, email, title FROM users WHERE name='{$_SESSION['user_name']}'");I don't see any problem with what i learned.. and what i think is the select do have some problem because if it the title problem then <?php echo $row['name']; ?> should so name but it don't.. .do you mind if i start a new thead

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...