Jump to content

Aftek

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Aftek's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hehe well sorry for confusing.. 1) - when you use session_start(), php sends the session id to the viewing browser/user     - with this id , every different user will have his own set       of session variable as in $_SESSION['name of the var']       for example, user A with his unique session id gets $_SESSION['username'] = "john";       while user B with another unique session id gets $_SESSION['username'] = "smith"; 2) when u use session_start() it ONLY assign the id...     to check if it exist first, you should have if (isset ($_SESSION['username'])) before.     and you can retrieve it with: $username = $_SESSION['username'];     if you make sure to unset/destroy session variables when user log off...     and dont set your session variable until the user has provided info to log in...     the if it is not set... the user is simply guest... otherwise.. you can retrieve any session variables you might need. 3) if you follow all steps in [url=http://www.adcommcepts.com/wamp-install.pdf]http://www.adcommcepts.com/wamp-install.pdf[/url]     (found on from apache lounge) you should then have a workin     apache 2.2.2 php 5.1.4 and mysql 5.0.22 installation.     i recommend installing mysql administrator and query browser which you can get from     mysql.com finally, if you are starting, let me recommend once more using mysqli extension instead of mysql... mysqli being mysql improved extension if not in you php.ini simply copy paste the mysql extension line, uncomment and add a 'i' to make mysqli alright... cya next break if i have time :) lol sorry again for confusing... i hope the guide [url=http://www.adcommcepts.com/wamp-install.pdf]http://www.adcommcepts.com/wamp-install.pdf[/url]  is clearer than me :) and it will get you the latest released version working... and be sure to check www.apache-lounge.com dedicated to apache under windows, but many information, they too provide the php 5.1.4 apache2.2.2 connector. (for you server to understand the last version of php code)... read the guide, and tell me    
  2. it strange how you wrote this.. im not an expert.. but maybe what i know is enough to help you there. [quote] [code] <?php     if($word_ok!==false) ?> [/code] [/quote] first of all !== is unknown to me... ( sorry i checked and it is available as a PHP operator... so !== isnt wrong) it is either != for 'is different from' or == for 'is equal to' Now if you use booleans, you dont even need to use them.. you can simply use [code] <?php $isValid; //then use a function to validate your $word_ok // a function that returns false in case of errors, true ( or anything else) if no error encountered. $isValid = validate_my_string ($word_ok); //now if $isValid == false if (!$isValid) {     echo "$word_ok is invalid"; } // else means $isValid is anything else but false.. // so if needed you function can return something else than true ( like an array, an object, a value or a variable) else {     echo "$Thanks you, $word_ok has been validated"; } //you can also have your function to create an array and return it at the end.. //during the validation if necessary add entries to it, i usually name $errors and use $errors ['where is happens'] = "err_msg"; function validate () {     //first create an empty array     $errors = array();   // do your validation and if there is an error add it to $errors     if (empty($_POST['username']) || $_POST['username'] == "") $errors['username'] == "blank username";     if (empty($_POST['password']) || $_POST['password'] == "") $errors['password'] == "blank password";     //once it is done just return $errors array     return $errors; } //then you can have a page looking like //validate and get the array $validation = validate (); if (empty ($validation)) echo "the error array is empty... which means you pass thru my validation, congrats, lol"; //else means there has been an error somewhere else {     echo "the following errors where found<br />";     echo "<ul>";     // foreach will do this for every entries in our error array. I'm putting it in unordered list, 100%optional     foreach ($validation as $whereIsError => $error_msg)     {         echo "<li>$whereIsError - $error_msg</li>";     }     echo "</ul>"; } [/code] [quote]"INSERT INTO test Name=$_POST['Name'], Title=$_POST['Title']";[/quote] try either [code]<?php $sql = "INSERT INTO test Name='{$_POST['Name']}', Title='{$_POST['Title']}'";[/code] or [code]<?php $sql = "INSERT INTO test Name='" . $_POST['Name'] . "', Title='" . $_POST['Title'] . "'";[/code] Im am even farther to being a mysql expert, but shouldnt it be "INSERT INTO table_name ( column_name1, column_name3,..) VALUES ( '$value1', '$value3',..)" alright, im saying it again, im not an expert , far from it unfortunatly.. but in the meantime i'd love someone to correct me here if there's any mistake still hope it helps though :)
  3. [quote author=deemurphy link=topic=96917.msg388798#msg388798 date=1151496738] To asnwer your question  this is what I use: $conn = mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database",$conn)  or die(mysql_error()); This worked for me with dreamweaver MX and dreamweaver 8. I just hope someone can help me soon. Thanks Dee [/quote] if you use php5, use mysqli extension... oop available for mysqli connection, easier, and i think safer. [code] <?php $mysqli = new mysqli ($host, $username, $password, $schema); if (mysqli_connect_errno()) echo "error connection to database"; else {     //inset, update, alter, etc... which returns nothing.     $mysqli->query ($query);     if (mysqli_error ($mysqli)) echo "error updating database";     //select     $result = $mysqli->query ($query);     if (!$result) echo "error getting information from database";     elseif ($result->num_rows == 0) echo "no result";     else     {         while ($row = $result->fetch_assoc())         {             //example:             $something_id = $row['row_id'];             $something_name = $row['row_name'];         }     }     //if the result was successful ( even 0 row ) be sure to close result before user further $mysqli->query     if ($result) $result->close();     //and close the connection once your done.     $mysqli->close(); //or unset ($mysqli) ?>[/code]
  4. I'm actually trying to make a user management system too, so im not an expert.. yet ( hopefully lol ). but at least some basics, you can use session with php. when you use session_start(), php will give the viewer a random unique session id. and when your session is started you can user $_SESSION['var'] variables. (i think using $_SESSION['var'] starts one automatically.. not sure). so lets say you have $_SESSION['username']; You create a login form that will set this variable... and a logout  page that will unset it. ( since you can have many many more session variables, you should use session_destroy() so you dont have to unset one by one each variables it does it all at once ). now for your session to carry out to other page, along with its variables, you have 2 choices. within the url ( http://urDomain/?PHPSESSID=the session id ) or with a cookie. using cookie is much safer... read your php.ini at session section. you either need to session_start() on every page, or you can set session_auto_start in php.ini so every page retrieve the session variables.. ex for something you want to registered members only: [code] <?php if (!isset ($_SESSION['username'])) {     echo "Please login/register to access this"; } else {     //show the form you reserved to registered users } ?>[/code] 2 ) now for user information to be edited [code] <?php // if the user is not even logged in... if (!isset ($_SESSION['username'])) {     echo "You shouldnt even be here! Shoo";     //you can redirect to login page too } // else if the logged user has not wished to edit yet. elseif (!isset ($_POST ['edit'])) {     //you simple list the information you have in your database } // else means the logged users wishes to edit this time. else {   //now's the biggest part.... the form, the validation and entering in database   //if you unset $_POST['edit'] once the data is saved you can redirect to the same page too. } ?>[/code] for your 3) dunno if thats what you need but... if your getting started you should use mysqli right away.. ( enable the extension and get the files at mysql.com i think ) with mysqli there's an oop available and much easier/safer i think [code] <?php //you first need to know the info about your database $username = "username"; $password = "password"; $db_host  = "the address to your database server"; // ip, url, localhost... $db_schema = "the schema where you'll be able to create view alter you tables"; //then you create a mysql connection as a mysqli object $mysqli = new mysqli ($db_host, $username, $password, $db_schema); //if you have a INSERT or ALTER query then simply //you can then check for errors with mysqli_error() or mysqli_errno() $mysqli->query ($urQuery); //if you have a SELECT query then it will give you another object to handle results $result = $mysqli->query ("SELECT...FROM.."); //then you get $result->num_rows; // which is the number of rows returns by the query //each time you call this, you pass to the next row, first time getting first row. $row = $result->fetch_assoc(); // you get an array of eacg colym of you query by colum name $row['column_name1'], etc.. //so you can either do $i=0 while ($i < $result->num_rows) {     $row = $result->fetch_array(); // you get an array of each column of your query order in $row[0], $row[1] etc } //or do while ($row = $result->fect_both()) {     // do whatever you want with data accessible by $row['0'] or $row['column_name1'] etc... } alright.. its late i need sleep :) I too in fact hope to get feedback of my use of php.. so i hope it does help you, and if you need some thing clarified, seen how im tired i wont be surprised.. ?> [/code] good luck alright... if it helps... or if i can clarify some things for you, itll be my pleasure... im hoping to get comments on my comment too lol cya
×
×
  • 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.