[urgent] PHP isn't working - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [urgent] PHP isn't working (/showthread.php?tid=71218)
[urgent] PHP isn't working by Baggins on 01-30-2007 at 11:33 PM
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
RE: [urgent] PHP isn't working by WDZ on 01-30-2007 at 11:47 PM
Replace...
code: mysql_real_escape_string($code);
With...
code: $code = mysql_real_escape_string($_POST['code']);
That's the first obvious problem I spotted.
RE: [urgent] PHP isn't working by brian on 01-30-2007 at 11:48 PM
Attached code is a cleaned up/removed pointless stuff edition. It'll should at least produce an error this time.
RE: [urgent] PHP isn't working by Baggins on 01-30-2007 at 11:49 PM
Ah... I thought it modified the passed argument, that's how it was on php.net.
Also i meant to define $code from $_POST
RE: [urgent] PHP isn't working by WDZ on 01-30-2007 at 11:54 PM
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...
RE: [urgent] PHP isn't working by Baggins on 01-31-2007 at 12:07 AM
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!
EDIT 4: actually, to anyone wondering, it was seeing code as set and not preforming the else
|