Jump to content

jscix

Members
  • Posts

    197
  • Joined

  • Last visited

    Never

Posts posted by jscix

  1. Hrmm, I could.. I really want to make this script sulf-suffiecent though.

    It isn't terribly important, as im just making this as a "learn by doing" kinda thing.

     

    Thanks for the imput though, I think I just need to mess with it a bit more.

     

    **bashes head on keyboard**

     

  2. Ok, what I want to know is, what is the best way to display a php generated image?

     

    I have a script that generates the image but I need to display it on a page, so if I use a header command it will just redirect to the image without the page, correct?

     

    So I made it generate a .JPG file, then print the HTML to display it, which works well EXCEPT, I want the script to delete the generated .jpg file after having either a successful form submission or a unsucessful form submission(And Generate a new one if form submission failed) which I got it to do..., BUT

     

    the problem now is that if the user completly just LEAVES the page, without submitting at all.. the generated image stays in the directory.. which isn't a good thing.. How can I fix this? Any ideas?

  3. How could I make this function return a true or false value depending on if the supplied string passes the checks??

     

    <?php
    
    Function ValidateString($txtcheck)
    {  //start function
    
    if ($txtcheck == (null))
    {
    // didn't pass because string is null
    }
    
    elseif (strlen($txtcheck) < 3)
    {
    // didn't pass because string is too short
    
    }
    
    elseif (ctype_alnum(!$txtcheck))
    {
    // didnt pass because string contains alphanumeric chars
    }
    else
    {
    // return true
    }
    
    } // end function
    

     

    sorry for the easy question, still getting the hang of this stuff. :o anyone?

  4. Ok, my question is:

    How do I stop the content of a script from loading and instead; redirect to another page based on criteria performed in a seperate script, that is php included from within the original script?

     

    The problem is, the included script which supplies the criteria for whether or not the content should load, must be included after some session, and error handeling code.. which prevents me from redirecting,

    and as far as I am aware, prevents the code ABOVE the INCLUDE, from being able to read any variables that are set within the included file, since they have no value until the included script sets them.

     

    Is there any way around this, or am I going to have to redesign the way the script works??

     

    Here is the login script - Which at the bottom includes display.php

    <?php
    
    session_start();
    $xxxy = (isset($_SESSION['userrname']));
    
    if ($xxxy == "1")
    {
    
        include ('db_connect.php');
        $connection1 = mysql_connect($db_host, $db_username, $db_password);
        if (!$connection1)
        {
            die ("Could not connect to the database: <br />" . mysql_error());
        }
        $db_select = mysql_select_db($db_database);
        if (!$db_select)
        {
            die ("Could not select the database: <br />" . mysql_error());
        }
        $uhusr = ($_SESSION['userrname']);
    
        $sql2 = "SELECT * FROM `" . $uhusr . "` LIMIT 0, 30 ";
        $duh2 = mysql_query($sql2);
    
        $res2 = mysql_fetch_row(($duh2));
        $latl = ($_SESSION['passwordd']);
    
        if ($res2[0] == $latl)
        {
    
            print "<center />You are already logged in <a href=index.php />click here</a 
    
    /><br />";
    
            die ();
        }
    
        if (!duh2)
        {
            die ("Username does not exist.");
        }
    
    }
    else
    {
    }
    ?>
    
    <html>
    <center>
    <img src="/PHP/Test/login.jpg"><br>
    
    <?php
    include "forms.php";
    $ohno2 = include ("parse.php");
    
    $dbusr1 = ($_POST["usrfeild"]);
    $dbpw1 = ($_POST["pwfeild"]);
    // Validatestr is called from within parse.php
    $usrf1 = Validatestr($dbusr1);
    $pwf1 = Validatestr($dbpw1);
    
    if ($dbusr1 == (null))
    {
        print "Please enter a username and password to continue.";
        die ();
    }
    elseif ($dbpw1 == (null))
    {
        print "Please enter a username and password to continue.";
        die ();
    
    }
    elseif ($usrf1 == "")
    {
        print $usrf1 . "<br />";
        print "Usernames must start with a letter!";
        die ();
    
    }
    elseif ($pwf1 == "")
    {
        print $pwf1 . "<br />";
        print "Passwords must start with a letter!";
        die ();
    
    }
    elseif ((strlen($dbusr1) < 3))
    {
        print "Usernames must be at least 3 characters.";
        die ();
    
    }
    elseif ((strlen($dbpw1) < 3))
    {
        print "Passwords must be at least 3 characters.";
        die ();
    }
    else
    {
        include "display.php";
    }
    
    ?>
    
    </center>
    </html>
    

     

     

     

    Here is the display.php script --  At the bottom is a print "thanks for logging in click here" message, Instead of this I would like to either redirect or set a variable that can be read from the loginscript and redirect from there...

    <?php
    
    include ('db_connect.php');
    
    $connection = mysql_connect($db_host, $db_username, $db_password);
    
    if (!$connection)
    {
        die ("Could not connect to the database: <br />" . mysql_error());
    }
    
    $db_select = mysql_select_db($db_database);
    if (!$db_select)
    {
        die ("Could not select the database: <br />" . mysql_error());
    }
    
    $sql = "SELECT * FROM `" . $dbusr1 . "` LIMIT 0, 30 ";
    
    $duh = mysql_query($sql);
    
    if (!$duh)
    {
        die ("Username does not exist.");
    }
    
    $result = mysql_fetch_row(($duh));
    
    $retpass = $result[0];
    
    $pwmd5 = (md5($dbpw1));
    
    $name1 = $pwmd5;
    $name2 = $retpass;
    
    $result = strcasecmp($name1, $name2);
    
    if (!$result)
    {
    
        $_SESSION['userrname'] = $dbusr1;
        $_SESSION['passwordd'] = $pwmd5;
    
        print "<center />Thanks for logging in $sbusr1 <a href=index.php />click here</a />";
        mysql_close();
        die ();
    }
    else
    {
        echo "You have entered an incorrect password.";
        mysql_close();
        die ();
    }
    
    mysql_close();
    
    ?>
    

  5. I'm not sure what's wrong here, i've tried multiple ways to destroy the current session, none of them have worked.

     

    This is the code im currently using:

    <?
    session_start();
         session_destroy();
         session_unset();
       } 
      ?>
    

     

    As far as I can tell from what I have read this should delete the session, it isn't thought.. I've done a fair bit of reading on sessions, and im stumped...

     

    Questions:

    -Should that code end the current session?

    -If so, are there any specific things which would prevent that code from ending the session?

     

    Any help is much appreciated..

  6. I started learning PHP/SQL three days ago. The last two days i've spent all my waking hours creating a user registration, login script that uses SQL. and thanks to many of you it all works now!!

     

    I should of started programming alot earlier, it's so much fun. ;o

    This is probably the wrong forum but im exciting and lots of ppl here helped so, ty!

     

    On to harder stuff!!

     

    :) :)

  7. Okay, there is no problems in the code, it all works, however.. I know there has to be a better way.

     

    What I want to know is:

    --How could I check the values of two text feilds, and basically print an error message if they dont meet a certain criteria.

    --IF they do meet the criteria, then perform the next step in the code.

     

    You can see how I did this below, but I want to refine it to check for a bit more than just a (NULL) Value.

    The way it is now, is sloppy/ineffeciant.. anyone have some pointers?

    <?php
    require "forms.php";
    
    $usrfeild = $_GET["usrfeild"];
    $pwfeild = $_GET["pwfeild"];
    
    
    
    if ($usrfeild == (NULL)) {
    $a = "0";
    print "Please enter a username!";
    die();
    }
    else {
    $a = "1";
    
    }
    
    
    if ($pwfeild == (NULL)) {
    $b = "0";
    print "Please enter a password!";
    die();
    }
    else {
    $b = "1";
    
    }
    
    $bothh = ($a + $b);
    
    if ($bothh="2"){
    require "list.php";
    }
    else
    {
    print "Enter User/PW";
    }
    
    

  8. I'm not very good with scripting yet. I'm still learning but maybe use a Switch statement instead of If?

     

    switch ($res) {

        case "1":

    // do something

            break;

        case "2":

      // do something else     

            break;

     

    }

     

    I think that's right. just tryin' to help. :)

     

  9. I actually tried a few things... which did not work...

     

    $query = 'CREATE TABLE ` .$dbusr. ` (

      `. $dbpw. ` varchar(26) NOT NULL,

      PRIMARY KEY  (` .$dbusr. `)

    )';

     

    and..

     

    $query = 'CREATE TABLE ` . ($dbusr) . ` (

      ` . ($dbpw) . ` varchar(26) NOT NULL,

      PRIMARY KEY  (` . ($dbusr) . `)

    )';

     

    what am I doing wrong now? .. ;o

  10. Ok, If I should not be using this forum for easy questions like these, please just tell me. I'm only a couple days into learning so i'm doing alot of thing's wrong here.

     

    Ok, how could I re-write this, so that PHP Inserts the value of the variables instead of the actual text $dbusr and $dbpw. Again I'm sorry for asking something, that's probably extreamly easy..

     

     

    $query = 'CREATE TABLE `$dbusr` (

      `$dbusr` varchar(26) NOT NULL,

      PRIMARY KEY  (`$dbusr`)

    )';

  11. Ok, I'm extreamly new to php/sql.. what i'm trying to do is create a table in mysql using a php script...

    I'm not sure what i'm doing wrong here.. but I am getting the error

     

    Fatal error: Call to a member function mysql_query() on a non-object in C:\wamp\www\PHP\Test\createtable.php on line 23

     

    which is: $xx=$connection->mysql_query($query);

     

    What am I doing wrong? Anyone? :/

     

    <?php
    
    include('db_connect.php');
    
    $connection = mysql_connect($db_host, $db_username, $db_password);
    
    
    if (!$connection){
    die ("Could not connect to the database: <br />". mysql_error());
    }
    
    $query = '
    CREATE TABLE `info` (
      `username` varchar(26) NOT NULL,
      `password` varchar(26) NOT NULL,
      PRIMARY KEY  (`username`)
    )';
    
    $xx=$connection->mysql_query($query);
    
    
    // print ("$xx". mysql_error());
    
    $connection->disconnect();
    
    
    ?>
    
    

     

     

  12. Okay, first off i'm a noob, (Also I hope this is the right forum for this.) I just started learning php 18 hours ago..  so yeah, laugh it up if nessecary,  but someone point me in the right direction please. :)

     

     

    I am reading:

     

    Learning PHP and MySQL

    By Michele Davis, Jon Phillips

     

    I Just got to the SQL Databases chapter.

    The problem is... I am using a remote web server to practice PHP.

    I did not install SQL/PHP on my machine, and I would rather not.

     

    Ok, Here is what I am trying to do. --->

     

    Chapter Reference:

    ----------------------------------------------------

    7.2.1. Creating Tables

    Use the create table command to specify the structure of new database tables. When you create a database table, each column has a few options, in addition to the column names and data types. Values that must be supplied when adding data to a table use the NOT NULL keyword. The PRIMARY KEY keyword tells MySQL which column to use as a key field. Then, you have MySQL automatically assign key values by using the AUTO_INCREMENT keyword.

     

    To create these tables, paste the code into the MySQL command-line client.

     

    Example 7-1 creates the books table using the data types from Table 7-8.

     

    Example 7-1.

    CREATE TABLE books (

    title_id INT NOT NULL AUTO_INCREMENT,

    title VARCHAR (150),

    pages INT,

    PRIMARY KEY (title_id));

    CREATE TABLE authors (

    author_id INT NOT NULL AUTO_INCREMENT,

    title_id INT NOT NULL,

    author VARCHAR (125),

    PRIMARY KEY (author_id));

    ----------------------------------------------------

     

    Now since I am using a remote web server to practice, how would I go about creating a table in SQL?

    My web server has PHP/SQL, so.. I would assume there is a "MySQL command-line client" of some kind that I can use?

     

    If so:

    How do I access/use it?

     

     

    Sorry if im asking the wrong questions/whatever. someone help me out? :o

     

    ty.

     

     

×
×
  • 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.