What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [urgent] PHP isn't working

[urgent] PHP isn't working
Author: Message:
Baggins
Full Member
***

Avatar
B000ALFAZO

Posts: 387
Reputation: 13
29 / Male / Flag
Joined: Oct 2006
O.P. Sad  [urgent] PHP isn't working
I need help with this php script, it is for my science fair progect which is due on monday.

When i enter the [access] code, no matter what, it just gives a blank page.

code:
<?php
if(isset($_POST['code']))
{
    $dbh = mysql_connect ("localhost", "user", "passwurd") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("science");
    mysql_real_escape_string($code);
    $query = mysql_query("SELECT * FROM codes WHERE code='$code'");
    if(mysql_num_rows($query) != 0)
    {
        mysql_query("DELETE FROM codes WHERE code='$code'");
        session_start();
        header("Location: http://foo.com/1.php");
    }
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
  <title></title>
</head>
<body>
Welcome,<br>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="validate">Enter
your access code: <input maxlength="6" name="code"><br>
  <br>
  <input type="submit"><br>
</form>
</body>
</html>
<?php
}
?>

Please and thankyou this is really important

This post was edited on 01-30-2007 at 11:45 PM by Baggins.
01-30-2007 11:33 PM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: [urgent] PHP isn't working
Replace...
code:
mysql_real_escape_string($code);
With...
code:
$code = mysql_real_escape_string($_POST['code']);
That's the first obvious problem I spotted. :P
01-30-2007 11:47 PM
Profile PM Web Find Quote Report
brian
Senior Member
****

Avatar

Posts: 819
Reputation: 43
– / Male / –
Joined: Sep 2004
RE: [urgent] PHP isn't working
Attached code is a cleaned up/removed pointless stuff edition.  It'll should at least produce an error this time.

.txt File Attachment: baggins.txt (946 bytes)
This file has been downloaded 127 time(s).
01-30-2007 11:48 PM
Profile PM Find Quote Report
Baggins
Full Member
***

Avatar
B000ALFAZO

Posts: 387
Reputation: 13
29 / Male / Flag
Joined: Oct 2006
O.P. RE: [urgent] PHP isn't working
Ah... I thought it modified the passed argument, that's how it was on php.net.

Also i meant to define $code from $_POST
01-30-2007 11:49 PM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: [urgent] PHP isn't working
quote:
Originally posted by Baggins
Ah... I thought it modified the passed argument, that's how it was on php.net.
Nope, mysql_real_escape_string() doesn't modify the passed argument. You must have misread the manual... :p
01-30-2007 11:54 PM
Profile PM Web Find Quote Report
Baggins
Full Member
***

Avatar
B000ALFAZO

Posts: 387
Reputation: 13
29 / Male / Flag
Joined: Oct 2006
O.P. RE: [urgent] PHP isn't working
I took brians code and removed all the typing errors, used WDZ's new $code decleration and it is still returning a blank page.

I don't think my query is returning anything

EDIT: I ran it from another script and it returned the rows.

When i run the first script it does not delete the row so i think my if statement is wrong?

EDIT 2: I got it to work by modifying the if statement to be: rows > 0

EDIT 3: tThanks WDZ and brian! :bow:

EDIT 4: actually, to anyone wondering, it was seeing code as set and not preforming the else

This post was edited on 01-31-2007 at 12:55 AM by Baggins.
01-31-2007 12:07 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On