This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#51 2011-09-11 17:05:39

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Right, I'm looking through it in notepad++ which is colour coding it all for me. Watch this space:

Firstly, you have more { than } in your js show_prompt() function.

Secondly you have an if statement OUTSIDE a php tag set.

You need to echo the text "invalid username/password"

You have a </script> tag without a <script> tag

You're missing a } at the end of the page

You're trying to send text (username and password invalid message) outside of the html tags

Code:

<title>Scratch User Panel 1.0</title>
<?php
if(!isset($_POST['submit'])){ ?>
    <form action="scratch_cp.php" method="post" name="loginForm">
    Username: <input type="text" name="username" />
    Password: <input type="password" name="password" />
    <input type="submit" name = "submit" value = "Login as . $username "/>
    </form>
    <script language="javascript" type="text/javascript" src="http://plaxon.org/js_methods.js">
    
    function show_prompt(){
        var name=prompt("Please enter a username:");
        var projectid=prompt("Please enter a project ID:");
        if (projectid!=null && projectid!=""){
            window.location = "http://scratch.mit.edu/projects/" + name + "/" + projectid;
        }
    }
    </script>
    <html>
    <head>
    <?php
}
if(isset($_POST['submit'])){
    $fileContents = file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" . $_POST['username'] . "&password=" . $_POST['password'] );

    if(trim($fileContents) == "false"){
    echo "Invalid Username/Password.";
    }
    else { ?>
        <script type="text/javascript">

        </script>
        </head>
        <body>

        <input type="button" onclick="show_prompt()" value="Open a Project" />

        </body>
        </html>
        <?php
    }
}
?>

You have an empty script tag near the bottom which I've left if case you want it there. I've also tidied up your layout a bit using tab to make it easier to read and follow  smile  Something to get into the habit of is writing comments all over your code so you don't forget what bits do! Look up php/HTML/ javascript comments, they all do it differently but they're very useful!

Thansk sparks!  smile


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#52 2011-09-11 17:08:33

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

UPDATE! I missed something and reposted the code on page 2  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#53 2011-09-11 17:10:44

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

Great! It's worked! I'll give tons of credit to sparks! You can be an admin if you like?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#54 2011-09-11 17:12:02

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

By the way, it's going to be a tool for scratch...


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#55 2011-09-11 17:13:57

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

Great! I'm glad it worked! Thanks for the offer but I'm already working on five websites and a load of other projects so I don't have the time! You're learning fast though, which is great, you just need to study the syntax a bit more and make sure you don't get php in your HTML or Javascript in your php  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#56 2011-09-11 17:15:51

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Great! I'm glad it worked! Thanks for the offer but I'm already working on five websites and a load of other projects so I don't have the time! You're learning fast though, which is great, you just need to study the syntax a bit more and make sure you don't get php in your HTML or Javascript in your php  tongue

Thanks  wink  By teh way, what was the thing you changed in the code?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#57 2011-09-11 17:23:08

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

You mean when reposted it?

you wrote:

<input type="submit" name = "submit" value = "Login as $username" />

I wrote:

<input type="submit" name = "submit" value = "Login as " . <?php echo $username;?> />

Notice that as the input is outside the main php tags, I have to echo the variable $username to the html. The html simply sees the value of $username instead of the variable. However, as I wrote in the earlier post, the variable is unset at that point in the code so your button will always say "Login as".

EDIT: OH NO!

I should have wrote:

<input type="submit" name = "submit" value = "Login as <?php echo $username;?>" />

!!!

How silly of me, the string joining period is only in php so HTML doesn't know what to do with it! The variable is echoed inside the speech marks *facepalm*

However, the point still stands that $username is equal to nothing at the moment  tongue

Last edited by sparks (2011-09-11 17:26:36)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#58 2011-09-11 17:25:59

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

You mean when reposted it?

you wrote:

<input type="submit" name = "submit" value = "Login as $username" />

I wrote:

<input type="submit" name = "submit" value = "Login as " . <?php echo $username;?> />

Notice that as the input is outside the main php tags, I have to echo the variable $username to the html. The html simply sees the value of $username instead of the variable. However, as I wrote in the earlier post, the variable is unset at that point in the code so your button will always say "Login as".

EDIT: OH NO!

I should have wrote:

<input type="submit" name = "submit" value = "Login as <?php echo $username;?>" />

!!!

How to I make links in echos?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#59 2011-09-11 17:30:17

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

php echoes text to HTML. HTML then uses the text as if it had never been echoed. This means you simply echo any HTML you like! Links for example:

echo "<a href = 'link'>Link text</a>";

Notice the ; at the end of the line, very important. Also note that single speech marks are used inside the doubles as doubles inside doubles doesn't work! Always start of with doubles so that there's space for singles to be used later.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#60 2011-09-11 17:32:45

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

php echoes text to HTML. HTML then uses the text as if it had never been echoed. This means you simply echo any HTML you like! Links for example:

echo "<a href = 'link'>Link text</a>";

Notice the ; at the end of the line, very important. Also note that single speech marks are used inside the doubles as doubles inside doubles doesn't work! Always start of with doubles so that there's space for singles to be used later.

Cool! So your saying the ; at the end of a line is just like the . at the end of a line in squeak. Cool! That's the mistake I was making! I was using double quotes inside doubles! lol!


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#61 2011-09-11 17:35:36

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

One more question... How do I make an actual space between </br> tags?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#62 2011-09-11 17:36:14

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

Yeah, you can't do that  tongue  It thinks you've left the quotes and re-entered them!

;'s appear at the end of almost every line in php unless the line is part of a statement or function (such as an if statement or the closing curly bracket of a statement.) You get used to just typing them automatically. If you don't, you'll get a "php error, expecting ';' on line x" message.

And now I'm going to bed. Adieu.

Last edited by sparks (2011-09-11 17:36:52)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#63 2011-09-11 17:37:18

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

Cool!


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#64 2011-09-11 17:45:50

Nuparu11
New Scratcher
Registered: 2011-09-11
Posts: 6

Re: Web Coding Questions

WindowsExplorer, do you need help with anything else?

P.S. I'm one of the team members...

Offline

 

#65 2011-09-11 23:13:52

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Web Coding Questions

Just one tip:

When checking if a form is submitted, you don't need to put

Code:

if (isset($_POST['submit'])) {

You can instead put

Code:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

To accomplish the same thing.


Fork Clamor on GitHub!

Offline

 

#66 2011-09-12 02:51:54

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Yeah, you can't do that  tongue  It thinks you've left the quotes and re-entered them!

;'s appear at the end of almost every line in php unless the line is part of a statement or function (such as an if statement or the closing curly bracket of a statement.) You get used to just typing them automatically. If you don't, you'll get a "php error, expecting ';' on line x" message.

And now I'm going to bed. Adieu.

Just like I automatically type 4 tildes at the end of a post on the wiki.  tongue  ~~~~

Offline

 

#67 2011-09-12 12:57:27

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Web Coding Questions

scimonster wrote:

sparks wrote:

Yeah, you can't do that  tongue  It thinks you've left the quotes and re-entered them!

;'s appear at the end of almost every line in php unless the line is part of a statement or function (such as an if statement or the closing curly bracket of a statement.) You get used to just typing them automatically. If you don't, you'll get a "php error, expecting ';' on line x" message.

And now I'm going to bed. Adieu.

Just like I automatically type 4 tildes at the end of a post on the wiki.  tongue  ~~~~

Difference is, you don't need to do that, whereas in php, you do.


http://i.imgur.com/zeIZW.png

Offline

 

#68 2011-09-12 14:27:37

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Web Coding Questions

rookwood101 wrote:

scimonster wrote:

sparks wrote:

Yeah, you can't do that  tongue  It thinks you've left the quotes and re-entered them!

;'s appear at the end of almost every line in php unless the line is part of a statement or function (such as an if statement or the closing curly bracket of a statement.) You get used to just typing them automatically. If you don't, you'll get a "php error, expecting ';' on line x" message.

And now I'm going to bed. Adieu.

Just like I automatically type 4 tildes at the end of a post on the wiki.  tongue  ~~~~

Difference is, you don't need to do that, whereas in php, you do.

Well, you do usually get in trouble if you don't on talk pages.  tongue  ~~~~

Offline

 

#69 2011-09-12 15:41:59

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Web Coding Questions

About the quotes...
Use a backslash to insert a double quote inside a PHP string. It's much better practice.

For example,
echo "<a href=\"http://scratch.mit;edu/\">Scratch</a>";

Last edited by LS97 (2011-09-12 15:42:45)

Offline

 

#70 2011-09-13 04:38:29

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

Thanks for the advice, LS97  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer