phorce 131 Posting Whiz in Training Featured Poster

What I can see is that the variable "link" contains both the href and the image itself.

<?php
	ob_start();
    session_start();
    if(!isset($_SESSION['Username']))
    {
        $alt = 'Please Register';
	$link = ( '<a href="http://www.test.com/signup.php"><img src=/images/register.png" alt="' .$alt. '" /></a>' );
        echo $link;
    }else{
        $alt = 'Vote';
	$link = ( '<a href="http://www.test.com/thanks.php"><img src=/images/vote.png" alt="' .$alt. '" /></a>' );
        echo $link;
	
  }
?>

Is that what you mean?

phorce 131 Posting Whiz in Training Featured Poster

Look up 'Database Normalisation'

From what I can see, your table is not even in first normal form.. Which is why you're having this problem :)

phorce 131 Posting Whiz in Training Featured Poster

Thanks for your replies, they've been really helpful!

The module is based on this book: http://www.amazon.co.uk/Mastering-Prolog-Rob-Lucas/dp/1857284003/ref=sr_1_1?ie=UTF8&qid=1324566135&sr=8-1

So I bought it =) I've downloaded that Application but it isn't really that good :(!

phorce 131 Posting Whiz in Training Featured Poster

Hey Lee,

You're designing and structuring your database wrong, which, is why you're having this problem:

Items "qty1" and "qty2" are displayed. However since qty3 is NULL (nothing) it is not displayed. I have done this by:

qty2 SHOULD contain something.. Because let's say if I came along and ordered a book:

username='Phorce', book='PHP OOP', qty='1' -> I've ordered 1 book.. No redundant data.

Your way:

username='Phorce', book='PHP OOP', pizza='cheese' qty='1', qty='2', qty='3'

Everytime someone orders a product (whether it's a book, pizza, or even a monkey) it should have it's own row inside the table, and, therefore, can have it's own quantity..

I'm trying to put this across in a way you can understand :(!

phorce 131 Posting Whiz in Training Featured Poster

Right, what I'm guessing is your table looks like this:

order_number first_name, last_name, qty1 qty2 qty3
----------------------------------------------
1 Phorce In Time 1
2 James Henry 1
3 blah blah 2


You shouldn't really have null data in your table, it's bad practise..


order_number first_name, last_name, qty
------------------------------------
1 Phorce In Time 1
2 James Henry 1
3 blah blah 2

If that makes sense? Sorry if I'm completely missing the point here? ...

Each item ordered has a qty..

phorce 131 Posting Whiz in Training Featured Poster

Why do you have a table in your database with:

'qty1, qty2, qty3, qty4' etc? Just have 1 called 'qty' :S This way you wouldn't have to mess around with any of this!

phorce 131 Posting Whiz in Training Featured Poster

Can I just ask, do you want to display 20 records from the table? And each of these records have a field called 'qty' or something?

Also, I don't understand what you're doing with the last part.. Are you inserting something?

phorce 131 Posting Whiz in Training Featured Poster

Below the reply box there should be a message that says: 'Mark this thread as solved'

To give reputation: By someones username that you found their post to be helpful/interesting click on the up arrow and enter your message

:)!

phorce 131 Posting Whiz in Training Featured Poster

Also, it's not really ideal to use shorthand php tags..

<?

?>

Use:

<?php

?>

Just minor :)

phorce 131 Posting Whiz in Training Featured Poster

No worries :) Could have been solved quicker my dear!

If your problem has been solved, please mark this thread as solved! And, give reputation if you think someone helped you!

Good luck :) !

phorce 131 Posting Whiz in Training Featured Poster
<?php
include 'connection.php'
?>

<!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>Index</title>
</head>

<body>
<b>Update for:</b> <br  />
<?
$getdb = mysql_query("SELECT * FROM person WHERE firstName='$_POST[updateN]'");

while($getdata = mysql_fetch_array($getdb))
{
	echo "ID no. " . $getdata['personID'];
	echo "<br />";
	echo "Name: " . $getdata['firstName']	. " " . $getdata['lastName'];
	echo "<br />";
	echo "Age: " . $getdata['Age'];
}


mysql_close($connection);
?>

<hr  />

<p>
<form action="updateprocess.php" method="post">
	Please Enter your ID number stated above: <input type="text" name="pID"  /> <br  /><br  />
    
    
 	First Name: <input type="text" name="updateFN"  /> <br />
    
    Last Name:  <input type="text" name="updateLN"  /><br />
    
    Age: <input type="text" name="updateA"  /> <br /><br />
    
    <input type="submit" value="Update" />
</form>
</p>

</body>
</html>

The index of "pID" cannot be identified because it isn't be posted, because of this line:

Please Enter your ID number stated above: <input type="text" name"pID"  /> <br  /><br  />

You need to have an = between name="pId" I am pretty sure I resolved this in my last post?

It works fine on my server once the pID is being processed =)

PrettyBird commented: Very thorough and helpful +1
phorce 131 Posting Whiz in Training Featured Poster

Open up your database, in phpmyadmin or something and check to see if the value for 'password' in the table is like:

d713e38281718ed2d493fdcfa44dac7e

or if it's like:

sfsf

=)

phorce 131 Posting Whiz in Training Featured Poster

change again to this:

if(mysql_affected_rows() == 1)
{
   while($row = mysql_fetch_array($result))
   {
	$expire = time()+60*60*24*30;
	setcookie("uid", $row['uid'], $expire);
	echo "Logged in. as <b>".$row['username']."</b>";
   }
}

Also, can you please make sure that the 'password' value is MD5 (i.e. NOT plain text) I don't see why there is a problem :(

phorce 131 Posting Whiz in Training Featured Poster

Please, everytime you post code.. Can you put them in tags please? It just makes it easier to read things (and hopefully, sort your problem out in less time)

<form action="updatinginfo.php" method="post">
Please Enter your ID number stated above: <input type="text" name="pID" />


First Name: <input type="text" name="updateFN" />

Last Name: <input type="text" name="updateLN" />

Age: <input type="text" name="updateA" />


<input type="submit" value="Update" />
</form>

Hope this helps you :)

phorce 131 Posting Whiz in Training Featured Poster

Okay.. As Catherine says would print out the title, however, to address your other question about displaying the books on a separate page:

1. Make sure your table consist a primary key (book_id)
2. Query the Book title, as well as the book_id
3. Create a new script (page) that selects all the information about this book, from the ID e.g.:
www.bookstore.com/books.php?id=1

<?php
   $id = $_GET['id'];
   // SELECT * FROM books WHERE book_id='$id';
?>

Pretty much done :)

phorce 131 Posting Whiz in Training Featured Poster

Please try this then:

<?php
if(isset($_POST['user']))
{
$user = $_POST['user'];
$pass= md5($_POST['pass']);

$con = mysql_connect("localhost", "root", "");
if(!$con){die('could not connect: '.mysql_ereor());}

mysql_select_db("test", $con);

$query = "SELECT * FROM users where username='$user' AND password='$pass'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 1)
{
   while($row = mysql_fetch_array($result))
   {
	$expire = time()+60*60*24*30;
	setcookie("uid", $row['uid'], $expire);
	echo "Logged in. as <b>".$row['username']."</b>";
   }
}else{
		echo"<b>Username or password</b><br><br>";
}
mysql_close($con);
}
echo "<form method='post'>
Username:<input type='text' name='user'><br>
Password:<input type='password' name='pass'><br>
<input type='submit' value='LOG IN'>
</form>";
?>

Also, please make sure that the value of 'password' in your database is in MD5 otherwise, it won't work :)

phorce 131 Posting Whiz in Training Featured Poster

You can't do it, you have 3 queries in 1 query?

$firstName = $_POST['updateFN'];
$lastName = $_POST['updateLN'];
$age = $_POST['updateA'];
$personID = $_POST['pID']; //line 7


$update= "UPDATE person SET firstName='$firstName', lastName='$lastName', Age='$age' WHERE personID='$personID'";
$result = mysql_query($update) or trigger_error('Cannot update user');

Try that :)

phorce 131 Posting Whiz in Training Featured Poster

Change this part:

$query = "SELECT * FROM users where username='$user' AND password='$pass' ";
$result = mysql_query($query);
if(mysql_affected_rows() == 1)
{
    while($row = mysql_fetch_array($result))
    {
        $expire = time()+60*60*24*30;
	setcookie("uid", $row['uid'], $expire);         
        header("Location: index.php");
    }
}else{
  echo"<b>Your username/password did not match those on the system!</b><br><br>";
}

Hope this helps =)

phorce 131 Posting Whiz in Training Featured Poster

It says what, when? When you use the wrong information or the right info?

phorce 131 Posting Whiz in Training Featured Poster

Just a suggestion:

Put the data you're posting into variables:

$firstName = $_POST['updateFN'];
$id = $_POST['perID'];
phorce 131 Posting Whiz in Training Featured Poster
$query = "SELECT * FROM users where username='$user' AND password='$pass' "; // This is the query
$result = mysql_query($query); // This executes the query

Is there an error?

phorce 131 Posting Whiz in Training Featured Poster
<?php
if(isset($_POST['user']))
{
$user = $_POST['user'];
$pass= md5 ($_POST['pass']);

$con = mysql_connect("localhost", "root", "");
if(!$con){die('could not connect: '.mysql_ereor());}

mysql_select_db("test", $con);

$query = "SELECT * FROM users where username='$user' AND password='$pass' ";
$result = mysql_query($query);
if(mysql_affected_rows() == 1)
{
   while($row = mysql_fetch_array($result))
   {
	$expire = time()+60*60*24*30;
	setcookie("uid", $row['uid'], $expire);
	echo "Logged in. as <b>".$row['username']."</b>";
   }
}else{
		echo"<b>Username or password</b><br><br>";
}
mysql_close($con);
}
echo "<form method='post'>
Username:<input type='text' name='user'><br>
Password:<input type='password' name='pass'><br>
<input type='submit' value='LOG IN'>
</form>";
?>

Try that =)

phorce 131 Posting Whiz in Training Featured Poster

Hey, has this been answered? I can try and give some clarification, if you like.. Let me know =)

phorce 131 Posting Whiz in Training Featured Poster

Hey =)

It's kind of right, the only problem is that the function is declared after the main and when it's read in main, it doesn't know yet that the function exists. Two solutions:

Put the function before main:

# include <iostream>
using namespace std;

void testFunction ()
{
    cout << "Hello 2!\n";
}

int main()
{
   
    cout << "Hello!\n";
    
    testFunction ();

    cout << "Your back!\n";

    char f;
    cin >> f;
    return 0;
}

Or, create a prototype of the function:

# include <iostream>
using namespace std;

void testFunction();

int main()
{
   
    cout << "Hello!\n";
    
    testFunction ();

    cout << "Your back!\n";

    char f;
    cin >> f;
    return 0;
}


void testFunction()
{
    cout << "Hello 2!\n";
}

Hope that helped :)

phorce 131 Posting Whiz in Training Featured Poster

My best solution:

- Run a query to get the data
- Then, in your preferred language, build a map depending on the data..

There are queries and libraries which can help you achieve this =)

phorce 131 Posting Whiz in Training Featured Poster

It compiles =)

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
	int i1,i2;
	i2=0;
	int t=0;
	cout << "enter the value" << endl;
	cin>>i1;
	t=1;
	sleep(2);
	if(t==0)
	{
  		cout<<i1;
	}	
	else
	{
  		cout<<i2;
	}
	return 0;
}

Dunno what the program is expected to do!

phorce 131 Posting Whiz in Training Featured Poster

Aha, thank you =) Does it have a place even in the modern day world? Like, I'm studying Computer Science and have a module on AI and our programming language is Prolog, but, personally, I would have found it so much easier to understand logic through say C++ etc.. Or am I missing the point? :P

phorce 131 Posting Whiz in Training Featured Poster

haha no problem! One last question though ;)

Any way that I can maybe somehow create a simple interpreter of prolog in C++? Or.. Is that a bit too adventurous? :P

phorce 131 Posting Whiz in Training Featured Poster

Thanks for your reply.. I downloaded and installed I then checked the user manual and then I ran the line (in terminal)


% gplc prog.pl

But just get an error:

-bash: fg: %: no such job

Any ideas? I'm really confused as to how to compile and test the file!

Thanks =)

phorce 131 Posting Whiz in Training Featured Poster

Do you have to write these out in code?

phorce 131 Posting Whiz in Training Featured Poster

I started programming when I was 17, first language was C and didn't find programming as much intersting, I was more interested in Graphic desiging so I spend most of time in learing Flash, besides that I kept learing C++. In university I actually started programming in 6th semester after a great scolding by lecturer. At that time, VS 2003 and C# 2.0 was in boom, I like thse language because of this was user interface supported. After university, I tried to start my career in graphic designing but I did it for just 10 days and moved back to Asp.Net web development and from day that to now, I am asp.net guy. I started loving it ;) because it also helps me to keep my grpahics hoppy side by side.

Quick question:

Do you believe that DEVELOPERS and DESIGNERS (Graphic) are different? In a sense that, I can develop but can't design for anything, I suck haa!

phorce 131 Posting Whiz in Training Featured Poster

Hello, I'm a mac user and starting a new module in Prolog and wondering if there are any applications that can compile and run Prolog for mac? Sounds silly, but can use terminal?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

I started messing around with CSS and HTML when I was like 14 or so.. Then I saw a website that had a user system and thought "Wow, I wanna create that" so I began learning PHP.. Did that for a few years and finally created a Forum. Went on to learn C++ and C#!

C++ and PHP became my main languages that I use on a daily basis!

I think I know quite a lot, but, then meet someone and I'm like "wow, I actually know nothing"

almostbob commented: Cool, easier to absorb more knowlege when you know somebody else may have an idea you can use +0
phorce 131 Posting Whiz in Training Featured Poster

Have you started it? Can you post the code that you're struggling with?

Sorry but you need to attempt it, that's the reason you're doing assignments, and, not to post them on forums for others to do!

=)

phorce 131 Posting Whiz in Training Featured Poster

1) You shouldn't post home-work tasks and expect people to just complete them.
2) You shouldn't have left your work until the last minute.

What is it you "can't" do? Like, you must have been taught in class how to do such things, maybe look back at the lecture notes?

How do you plan to store the tasks? Or, is it a pre-defined list of tasks? Is jQuery the only language that you can use?

=)

phorce 131 Posting Whiz in Training Featured Poster

Well, you'd need to store them in something like a Database, or a text file.. It wouldn't be practical to build a user system just using cookies/sessions.. =)

phorce 131 Posting Whiz in Training Featured Poster

I wouldn't store the users login details (specifically password) in a session OR a cookie.. Yeah, you can store the the persons username but their password is bad, especially if it's not encrypted.

=)

phorce 131 Posting Whiz in Training Featured Poster

http://www.klovera.com/php-sessions-vs-cookies/

By "server-side cookie" do you mean session? You can set/access sessions quite easily:

<?php
   $_SESSION['name'] = "phorce";
   echo "Hello {$_SESSION['name']}";
?>

Could you please tell us what data you're planning on storing, and, this may help you more. =)

phorce 131 Posting Whiz in Training Featured Poster

I kinda like Codeignitor, I like how they've structured their platform, but I think it's over hyped.

I dunno about anyone else, but I kinda like making apps from the ground upwards, or, atleast, make my own classes that I can then re-use.. I know what's going into them, and, know the error management :)

phorce 131 Posting Whiz in Training Featured Poster

Also to add (Again, I believe)

If you use session, it's exactly what it is says.. SESSION (Meaning, they expire if like they close their browser etc) Whereas cookies can be set for sometime.

E.g. If I had a login form, and, an option was to set "Remember me" I wouldn't really store it in a session, I'd store it in a cookie (client-side)

Hope this helps =)

phorce 131 Posting Whiz in Training Featured Poster

No, you need to not post your database password

phorce 131 Posting Whiz in Training Featured Poster
<?php
/*Set to error level to development modes*/
ini_set("display_errors", 1);
error_reporting(E_ALL);
if ( isset($_POST['username'])) {
$ret = add_to_database();
if (!$ret) {
print "Error: Database error";
} else {
print "Welcome   <b> $_POST[username] Check your email and download the books</b>";
	
}
} else {
write_form();
}

//functions
function write_form() {
$self =$_SERVER['PHP_SELF'];
echo <<<EOT
<form action="$self" method="POST">
<table>


<tr>
<td>User Name:</td>
<td><input type="text" name="username" /></td><br/>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="useremail" /></td><br/>
</tr>



<tr>
<td>&nbsp</td>
<td><input type="submit" /></td>
</tr>
</table>
</form>
EOT;
}

function add_to_database() {

$username = trim($_POST['username']);
$email = trim($_POST['useremail']);

mysql_connect("xxxx","xxxxx","xxxxx") or die("Couldn't connect to server");
mysql_select_db("xxxxxx");
check_user($username);
check_email($email);

$sql = "INSERT INTO dig_users(username, useremail) VALUES ('$username', '$email')";
$result = mysql_query($sql);
if(mysql_affected_rows() == 1)
{  
    echo 'Inserted';
}else{
  echo 'Could not insert';
}
  
return true;
}

//this will check whether there is user with same user name
function check_user($usr) {

$sql = "SELECT * FROM dig_users WHERE username='$usr'";
$result = mysql_query($sql);
if(!$result){
die("Function check_user failed: ".mysql_error());
}
$rows =mysql_num_rows($result);
if ($rows>0) {
print "The user $usr already exists. Please select another username.";
exit;
}
}
//checks that email is unique
function check_email($em) {


$sql = "SELECT * FROM dig_users WHERE useremail='$em'";

$result = mysql_query($sql);
if(!$result){
die("Function check_email failed: ".mysql_error());
}
 
$rows =mysql_num_rows($result);
#
if(is_resource($result))
{
if ($rows>0)
{
print "The e-mail address $em already exists. Please type another e-mail address.";
exit;
}


}
}
?>

Try that =)

phorce 131 Posting Whiz in Training Featured Poster

hahaah.. yeah I just realised that I answered my last question in the previous post. Any security concerns about client or server side sessions?

Hey,

I BELIEVE that server side sessions are a lot more secure, rather than client side because they are on the persons machine. That's the way I view them, might be wrong :)

phorce 131 Posting Whiz in Training Featured Poster

It's kind of like the codeignitor style (http://codeigniter.com/user_guide/libraries/sessions.html)

So like:

$this->session->set_userdata('some_name', 'some_value');

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello I need some advice (I'm not expecting code - Just want to know if it's possible / references)

Basically, I want to create a class that I can check if the email has been submitted AND also, if it's formatted right (e.g. does it contain a @ but also go into a lot more depth) so it'd look a bit like:

<?php

   include ('validationClass.php');

   $validation = new Validation();

   if($validation->validate($_POST['email']))->formatted())
   {
      echo 'Yes';
   }
?>

So like:

$this->validate->formatted()

Any suggestions? =)

phorce 131 Posting Whiz in Training Featured Poster

Can you link to where you've seen this code? :S

phorce 131 Posting Whiz in Training Featured Poster

I think you mean:

<?php
   echo 'Hello, world';
?>
<?php
  $var = "foo";
  echo $var;
?>
phorce 131 Posting Whiz in Training Featured Poster

haha woo :)! You're welcome, pleasure! If you ever need anything else, feel free to ask! I hope this project goes well for you. Take care =)

phorce 131 Posting Whiz in Training Featured Poster

41 replies later and ripping my hair out ;) woo!

Let me know how you get on!

phorce 131 Posting Whiz in Training Featured Poster
<?php
session_start();

include "db_connect.php";

$username = $_POST['username'];
$pass = $_POST['pass'];

mysql_select_db($dbname, $connect);
$sql="SELECT username, password FROM alunos WHERE username='". $username. "'";

$resultado = mysql_query($sql, $connect) or die(mysql_error());

$num = mysql_fetch_assoc($resultado);

if ($username == $num['username'] AND $pass == $num['password']) {
        $_SESSION['username'] = $username;
        header("Location: test.php"); // sorry xD
        } else {
        echo "Could not log in :(";
        }
mysql_close($con);
?>

Try that now =) I think there was a problem with the previous SQL statement!