Jump to content

Minimeallolla

Members
  • Posts

    197
  • Joined

  • Last visited

    Never

Posts posted by Minimeallolla

  1. They are called when the form is submitted

     

    <div id="regform"><form name="input" action="Registration.php" method="get">
        Username: <input type="text" name="Username" value="Username" onFocus="this.value=''"/><br />
        Password: <input type="password" name="Password"/><br />
        Email: <input type="text" name="Email" value="Enter Email"  onFocus="this.value=''"/><br /> 
        <input type="submit" name="Submit" value="Register" /><br />
    </div></form>
    

     

    you mean put:

    <?php
    if ($login_success == true) { print "$login_msg"; }
    ?>
    

    in the html form if i want to display a message for a few seconds before they get redirected?

  2. All criticism/suggestions/improvements appreciated :P

     

    Registration.php

    <?php
    $con = mysql_connect("localhost","","") or die(mysql_error());
    mysql_select_db('Users');
    
    if(isset($_COOKIE['ID_my_site'])) {
    $cookie_username = mysql_real_escape_string(filter_input(INPUT_COOKIE, 'ID_', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
    $cookie_password = sha1($_COOKIE['Key_']);
    $cookie_check = mysql_query("SELECT * FROM Users WHERE username = '$cookie_username'") or die(mysql_error());
    $cookie_results = mysql_fetch_array($cookie_check);
    
    	if ($cookie_password == $cookie_results['Password']) {
    		echo "<div id=\"login_msg\">You are already logged on. Redirecting...</div><br />" && header("location:/index.php");
    	}
    }
    
    if(isset($_POST['submit']))	{
    $Username = mysql_real_escape_string(filter_input(INPUT_POST, 'Username', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
    $Email = mysql_real_escape_string(filter_input(INPUT_POST, 'Email', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
    $Password = sha1($_POST['Password']);
    $Password2 = sha1($_POST['Password2']);
    
    if (!$Username | !$Email | !$Password | !$Passord2) {
    echo "<div id=\"error_msg\">You did not complete all of the required fields, please try again.</div><br />";
    }
    
    if ($Password != $Password2) {
    echo "<div id=\"error_msg\">Your passwords do not match, please try again.</div><br />";
    }
    
    $check_username = mysql_query("SELECT * FROM Users WHERE (Username = $Username)");
    $result_username = mysql_fetch_row($check_username);
    $check_email = mysql_query("SELECT * FROM Users WHERE (Email = $Email)");
    $result_email = mysql_fetch_row($check_email);
    
    if ($result_username == true) {
    echo "<div id=\"error_msg\">The Username: '$Username', already exists. Please enter another username.</div><br />";
    }
    
    if ($result_email == true) {
    echo "<div id=\"error_msg\">The Email Adress: '$Email', is already in our Database.</div><br />";
    }
    
    $sql = "INSERT INTO Users (Id, Username, Email, Password) VALUES ('', '$Username','$Email','$Password')";
    $add_member = mysql_query($sql) or die(mysql_error());
    
    if (mysql_query($add_member)) {
    	$week = time() + 604800; 
    	setcookie(ID_, $_POST['Username'], $week); 
    	setcookie(Key_, $_POST['Password'], $week);
    	echo "<div id=\"login_msg\">Successfully added to our Database.</div><br />"  &&  header ("location:/Login.php"); 
    }
    
    else {
    	echo "<div id=\"error_msg\">Invalid input.</div><br />"; 
    }
    }
    ?>
    

     

    Login.php

    <?php
    include("db.php");
    
    if(isset($_COOKIE['ID_my_site'])) {
    $cookie_username = mysql_real_escape_string(filter_input(INPUT_COOKIE, 'ID_', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
    $cookie_password = sha1($_COOKIE['Key_']);
    $cookie_check = mysql_query("SELECT * FROM Users WHERE username = '$cookie_username'") or die(mysql_error());
    $cookie_results = mysql_fetch_array($cookie_check);
    
    	if ($cookie_password == $cookie_results['Password']) {
    		echo "<div id=\"login_msg\">You are already logged on. Redirecting...</div><br />" && header("location:/index.php");
    	}
    }
    
    if(isset($_POST['submit']))	{ 
    $Username = mysql_real_escape_string(filter_input(INPUT_POST, 'Username', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
    $Password = sha1($_POST['Password']);
    
    if (!$Username | !$Password) {
    echo "<div id=\"error_msg\">You did not complete all of the required fields, please try again.</div><br />";
    }
    
    $sql = "SELECT * FROM Users WHERE (Username, Password) = ('$Username', '$Password')";
    $db_check = mysql_num_rows($sql) or die(mysql_error());
    
    if (mysql_query($db_check))	{
    	$week = time() + 604800; 
    	setcookie(ID_, $cookie_username, $week); 
    	setcookie(Key_, $cookie_password, $week);
    	echo "<div id=\"login_msg\">Successfully Logged In.</div><br />"  &&  header ("location:/index.php");
    }
    
    elseif (($Username | $Password) != $db_check) {
    	echo "<div id=\"error_msg\">Invalid username or password, please try again.</div><br />";
    }
    }
    ?>
    

     

    Logout.php

    <?php
    include("db.php");
    
    if(isset($_COOKIE['ID_my_site'])) {
    $cookie_username = mysql_real_escape_string(filter_input(INPUT_COOKIE, 'ID_', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
    $cookie_password = sha1($_COOKIE['Key_']);
    $cookie_check = mysql_query("SELECT * FROM Users WHERE username = '$cookie_username'") or die(mysql_error());
    $cookie_results = mysql_fetch_array($cookie_check);
    
    	if ($cookie_password != $cookie_results['Password']) {
    		header("location:/login.php");
    	}
    		else {
    			$past = time() - 604800; 
    			setcookie(ID_, gone, $past); 
    			setcookie(Key_, gone, $past); 
    			echo "<div id=\"error_msg\">Sucessfully logged out. Good Bye!</div><br />" && header ("location:/login.php");
    		}
    } 
    
    ?>
    

  3. You really should test more thoroughly. These code pasted directly into a .php file shows the following errors:

     

    Notice: Undefined index: item in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 36
    
    Notice: Undefined index: credit_input in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 39
    
    Notice: Undefined index: submit in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 42
    You do not have sufficient funds to purchase a .
    Notice: Undefined index: submit in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 46
    You do not have sufficient funds to purchase a .
    Notice: Undefined index: submit in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 50
    You do not have sufficient funds to purchase a .
    Notice: Undefined index: submit in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 55
    Coke resources depleted.
    Notice: Undefined index: submit in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 61
    Sprite resources depleted.
    Notice: Undefined index: submit in /var/www/private_html/projects.smsmarketeers.com/html/scripts/vending_machine.php on line 67
    Fanta resources depleted.Your current funds accumlate to 
    

     

    The problem is that "submit" is not defined because "submit" is the submit button which is not defined until the form is submitted. I suggested checking to see if the form was submitted a different way, perhaps using $_SERVER variables. For example:

     

    <html>
    <head>
    <title>Vending Machine</title>
    <style type="text/css">
    	*		{ font-size:12px; font-family:Arial; margin:0px; outline:0px; padding:0px; }
    	body	{ background:#ffffff; color:#000000; margin:10px 0px 0px 0px; }
    	img		{ border:0px; }
    	p		{ margin:5px 0px 10px 0px; }
    	form	{ border:none; margin:0px; padding:0px; }
    
    	a				{ cursor:pointer; }
    	a:link			{ color:#9AB324; text-decoration:none; }
    	a:visited		{ color:#9AB324; text-decoration:none; }
    	a:hover 		{ color:#9AB324; text-decoration:underline; }
    	a:active 		{ color:#9AB324; text-decoration:none; }
    
    	.container		{ margin:0px auto; width:400px; }
    	.success		{ background:#EEF5CD; border:1px dashed #9AB324; color:#608339; margin-bottom:5px; padding:5px; text-align:left; }
    	.warning		{ background:#eed4d2; border:1px dashed #a94637; color:#ac241a; margin-bottom:5px; padding:5px; text-align:left; }
    	.attention		{ background:#fefbcc; border:1px dashed #e6db55; color:#ada019; margin-bottom:5px; padding:5px; text-align:left; }
    
    	h1	{ color:#9AB324; font-size:16px; }
    
    	form, fieldset			{ border:none; margin:0px; padding:0px; }
    	input, textarea, select { font:100% arial, sans-serif; vertical-align:middle; }
    	input[type='text']		{ background:#ffffff; border:1px solid #c3c3c3; border-left-color:#7c7c7c; border-top-color:#7c7c7c; padding:2px; }
    	input[type='password']	{ background:#ffffff; border:1px solid #c3c3c3; border-left-color:#7c7c7c; border-top-color:#7c7c7c; padding:2px; }
    	input[type='radio']		{ margin:0px 5px 0px 5px; }
    	input[type='hidden']	{ display:none !important; }
    	select					{ border:1px solid #c3c3c3; border-left-color:#7c7c7c; border-top-color:#7c7c7c; min-width:100px; padding:1px; }
    	select option			{ padding:0px 5px 0px 5px; }
    	textarea				{ background:#ffffff; border:1px solid #c3c3c3; border-left-color:#7c7c7c; border-top-color:#7c7c7c; padding:2px; }
    
    	table.data th				{ background:#9AB324; border-bottom:1px solid #596E0E; color:#ffffff; font-weight:bold; padding:5px; text-align:center; }
    	table.data td				{ padding:5px; }
    	table.data td.rowOne		{ background:#f0f0f0; border-bottom:1px solid #dddddd; }
    	table.data td.rowTwo		{ background:#f5f5f5; border-bottom:1px solid #dddddd; }
    	table.data td.button		{ background:#ffffff; border:none; text-align:right; }
    </style>
    </head>
    <body>
    
    <div class="container">
    <?php
    
    	// Check if form was submitted
    	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    		// Cost of items
    		$price = array('coke' => '1.25', 'diet' => '1.50', 'sprite' => '1.75');
    
    		// Quantity Available
    		$quantity = array('coke' => '5', 'diet' => '7', 'sprite' => '2');
    
    		// Selected Item Information
    		$quantAvail = $quantity[strtolower($_POST['item'])];
    		$itemPrice = $price[strtolower($_POST['item'])];
    
    		// First check Quantity
    		if ($quantAvail < $_POST['quantity']) {
    			echo '<div class="warning">Insufficient quantity available.</div>';
    		} elseif ($quantAvail >= $_POST['quantity']) {
    			echo '<div class="success">Sufficient quantity available. Checking funds...</div>';
    		}
    
    		// If we passed quantity, check funds
    		if (($_POST['quantity'] * $itemPrice) > $_POST['funds']) {
    			echo '<div class="warning">Insufficient funds available.</div>';
    		} elseif (($_POST['quantity'] * $itemPrice) <= $_POST['funds']) {
    			echo '<div class="success">Sufficient funds available.</div>';
    		}
    
    		// Remaining Funds
    		$remainingFunds = $_POST['funds'] - ($_POST['quantity'] * $itemPrice);
    
    		echo '<div class="attention">You have <strong>$' . $remainingFunds . '</strong> funds remaining</div>';
    	}
    
    ?>
    
    <h1>Vending Machine</h1>
    <p>What would you like to purchase?</p>
    
    <form action="" method="post" name="vend">
    	<table align="center" border="0px" cellpadding="0px" cellspacing="1px" class="data" width="400px">
    		<tr>
    			<th width="30px"> </th>
    			<th style="text-align:left;">Item</th>
    			<th width="70px">Price</th>
    		</tr>
    		<tr>
    			<td align="center" class="rowOne"><input name="item" type="radio" value="Coke" /></td>
    			<td class="rowOne">Coke</td>
    			<td align="center" class="rowOne">$1.25</td>
    		</tr>
    		<tr>
    			<td align="center" class="rowTwo"><input name="item" type="radio" value="Diet" /></td>
    			<td class="rowTwo">Diet Coke</td>
    			<td align="center" class="rowTwo">$1.50</td>
    		</tr>
    		<tr>
    			<td align="center" class="rowTwo"><input name="item" type="radio" value="Sprite" /></td>
    			<td class="rowTwo">Sprite</td>
    			<td align="center" class="rowTwo">$1.75</td>
    		</tr>
    		<tr>
    			<td align="center" class="rowOne" colspan="3">
    				Qty: <input type="text" size="2" name="quantity" value="1" />    Available Funds: $<input type="text" value="5.00" name="funds" size="5" />
    			</td>
    		</tr>
    		<tr><td class="button" colspan="3"><input name="submit" type="submit" value="Vend" /></td></tr>
    	</table>
    </form>
    </div>
    
    </body>
    </html>
    

     

    Wow that is pretty amazing code right there compared to mine. I'm obviously starting out but oneday I want to code as well as you can.

     

    A few of those errors were merely stupid mistakes. I'm using a school laptop that can't run php or test it, so I practically use notepad without testing.

     

     

  4. This is just my software assignment. We have to create a functioning vending machine. How does it look so far?

     

     

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Vending Machine Assignment</title>
    <link href="vending.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    
    <div id="vending_machine_base">
    <img src="vending_machine_base.gif" alt="Vending Machine Base" title="Vending Machine Base" />
    </div>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    
    <p>Coke<input type="radio" name="item" value="Coke" /></p>
    <p>Sprite<input type="radio" name="item" value="Sprite" /></p>
    <p>Fanta<input type="radio" name="item" value="Fanta" /></p>
    <input type="text" size="15" name="quantity" value="Enter quantity here" />
    $<input type="text" value="Enter your financial balance." name="credit_input" size="23" />
    <input type="submit" value="Submit" />
    
    </form>
    
    <?php	
    error_reporting(E_ALL);
    
    // Cost of items
    $coke_price = "1.25";
    $sprite_price = "1.50";
    $fanta_price = "1.75";
    
    // Quantity of items
    $coke_quantity = "7";
    $sprite_quantity = "5";
    $fanta_quantity = "3";
    
    // Selected radio button into variable
    $selected_item = $_POST['item'];
    
    // Credit into variable
    $credit = $_POST['credit_input'];
    
    // If funds are less than price, dispay error message
    if (($_POST['submit']) && ($selected_radio = 'coke') && ($credit >= $coke_price))
    { echo "You have purchased a $selected_item!"; } else { echo "You do not have sufficient funds to purchase a $selected_item."; }
    
    if (($_POST['submit']) && ($selected_radio = 'sprite') && ($credit >= $sprite_price))
    { echo "You have purchased a $selected_item!"; } else { echo "You do not have sufficient funds to purchase a $selected_item."; }
    
    if (($_POST['submit']) && ($selected_radio = 'fanta') && ($credit >= $fanta_price))
    { echo "You have purchased a $selected_item!"; } else { echo "You do not have sufficient funds to purchase a $selected_item."; }
    
    // Item quantity
    if (($_POST['submit']) && ($coke_quantity = 0))
    { echo ""; } else { echo "Coke resources depleted."; }
    
    if (($_POST['submit']) && ($sprite_quantity = 0))
    { echo ""; } else { echo "Sprite resources depleted."; }
    
    if (($_POST['submit']) && ($fanta_quantity = 0))
    { echo ""; } else { echo "Fanta resources depleted."; }
    
    // Item cost subtracted from credit
    if (($coke_quantity >= 1) && ($credit >= $coke_price))
    { $coke_price - $credit; } 
    
    if (($sprite_quantity >= 1) && ($credit >= $sprite_price))
    { $sprite_price - $credit; } 
    
    if (($fanta_quantity >= 1) && ($credit >= $fanta_price))
    { $fanta_price - $credit; } 
    
    // Funds available
    echo "Your current funds accumlate to $credit ";
    
    ?>
    
    </body>
    </html>
    

  5. DreamWeaver starts some fonts in the font-family with capitals eg (font-family: "Times New Roman", Times, serif;) I was told to never use uppercase in Css because "A" and "a" are not the same.

     

    Just wondering if this is an error within Dreamweaver or if i was mislead. (I've noticed W3schools starts them with capitals aswell)

     

    Also, "Times New Roman" is in double quotes because of the spaces, right?

  6. Here is the working script if anybody ever wants it.  (all codes shown are vital for a working code)

     

    
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    
    <a class="image-expand" style="cursor: pointer" onclick="toggleSize(this)">
    	<img src="Pics/roflcopter.gif" />
    

    $(document).ready(function(){
    	// default width and height to 75px
    	$("a.image-expand img").css({'height':'75px', 'width':'75px'});
    });
    
    function toggleSize(_var_)
    {
    	image = $(_var_).children("img");
    
    	if(($(image).css("height") == "75px") && ($(image).css("height") == "75px"))
    	{
    		$(image).css({'height':'auto', 'width':'auto'});
    	}
    	else
    	{
    		$(image).css({'height':'75px', 'width':'75px'});
    	}
    }
    
    

  7. I have come across a script that sets all images by default to 75x75pixels and clicking toggles between original size and back to 75x75px only problem is each image is in the "a.image-expand img" class. therefor when one image is expanded they all expand.. -.- any way to only expand selected image?

     

    $(document).ready(function(){
    	// default width and height to 75px
    	$("a.image-expand img").css({'height':'75px', 'width':'75px'});
    
    	// Click function (toggle)
    	$("a.image-expand").click(function(){
    		if(($("a.image-expand img").css("height") == "75px") && ($("a.image-expand img").css("height") == "75px"))
    		{
    			$("a.image-expand img").css({'height':'auto', 'width':'auto'});
    		}
    		else
    		{
    			$("a.image-expand img").css({'height':'75px', 'width':'75px'});
    		}
    	});
    });
    

  8. @haku, That is not what I want to achieve.  That is all the code you need to see what I'm trying to do.

     

    Onclick it will expand the image from the default set 75x75pixels to auto (100%)

     

    What I'm trying to do is revert back to its default size onclick.

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Funny Pictures</title>
    <script type="text/javascript" src="Interactive.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    
    <body>
    
    <a class="image" onClick="this.className = 'new_class'; return false;"><img src="Pics/batman.png" alt="I'm Teh Batman!" /></a>
    
    </body>
    </html>
    
    

     

    Javascript

    onClick="this.className = 'image-expand'";
    
    

     

    Css.

     

    a.image img
    {
    width:75x;
    height:75px;
    }
    
    a.image-expand
    {
    border:0;
    position:center;
    width:auto;
    height:auto;
    z-index:10000;  
    }
    
    

  9. Is it possible to make it so if you click on a <a href> the information such as the name or link changes the <title> of the page and replaces existing opened <div>s with information from the link or such.

    eg

     

    If i had a list of swf files that were attatched to links how could I display each swf file onclick without redirecting whilst changing the title and content?

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