Closed Thread Icon

Topic awaiting preservation: php if statement not working? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12527" title="Pages that link to Topic awaiting preservation: php if statement not working? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: php if statement not working? <span class="small">(Page 1 of 1)</span>\

 
Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 11-26-2002 05:30

hi there people,

Having recently installed and getting to grips with php4.2.2, mysql4.0.1 alpha & apache2.0.39....

I am desparate for some help here. When I run my forms / scripts, they do not seem to recognise that all the fields have been completed properly, I always get the die statement
("You have not completed the form correctly, Please go back and try again.") every single time.
I fill the form in correctly every time. so what is the problem? Maybe you could try running
these files on your installation and let me know if it works for you. I have checked and rechecked the code but cannot seem to find any problems with it. Maybe you can? If it works for you then it must be something to do with my installation. (If it is - maybe you know what I should change?)

I have created the following simple php form called getdetails.php.

[UBB]
<html>
<head>
<title> Submit Lecture details </title>
</head>
<body bgcolor="#FFFFFF">

<form action="grabdetails.php" method="POST">

</a>
<table border="0" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">
<tr>
<td width="100%" bgcolor="#FF9900" height="22" colspan="2">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
Upload a File</font></b></td>
</tr>
<tr>
<td width="100%" bgcolor="#FFE3BB" colspan="2">
<p style="margin-left: 10; margin-right: 10"><font face="Verdana" size="2">
<br>Please insert all the information regarding the lecture video you have
chosen to upload. The file will not upload if all fields are not filled in
correctly. Once you have chosen the lecture video file, please click on the
&quot; Upload this file&quot; button below.&nbsp;
&nbsp;<br>&nbsp;</font></td>
</tr>
<tr>
<td width="15%" bgcolor="#FFE3BB">
<p style="margin-left: 10"><font face="Verdana" size="2">
Module Code:</font></td>
<td width="85%" bgcolor="#FFE3BB">
<input type="text" name="ModCode" size="20" maxlength="50"></td>
</tr>
<tr>
<td width="15%" bgcolor="#FFE3BB">
<p style="margin-left: 10"><font face="Verdana" size="2">Module Title:</font></td>
<td width="85%" bgcolor="#FFE3BB">
<font face="Verdana" size="2">
<input type="text" name="Title" size="20" maxlength="50"></td>
</tr>
<tr>
<td width="15%" bgcolor="#FFE3BB">
<p style="margin-left: 10"><font face="Verdana" size="2">Lecturer Name:</font></td>
<td width="85%" bgcolor="#FFE3BB">
<font face="Verdana" size="2">
<input type="text" name="Lecturer" size="20" maxlength="50"></td>
</tr>
<tr>
<td width="15%" bgcolor="#FFE3BB">
<p style="margin-left: 10"><font face="Verdana" size="2">Week:</font></td>
<td width="85%" bgcolor="#FFE3BB">
<font face="Verdana" size="2">
<input type="text" name="Week" size="20" maxlength="50"></td>
</tr>
<tr>
<td width="15%" bgcolor="#FFE3BB">
<p style="margin-left: 10"><font face="Verdana" size="2">Topics Covered:</font></td>
<td width="85%" bgcolor="#FFE3BB">
<font face="Verdana" size="2">
<input type="text" name="Topics" size="20" maxlength="255"></td>
</tr>
/*<!--<tr>
<td width="15%" bgcolor="#FFE3BB">
<p style="margin-left: 10"><font face="Verdana" size="2">File Location:</font></td>
<td width="85%" bgcolor="#FFE3BB">
<font face="Verdana" size="2">
<input type="file" name="fileUpload" size="20"></font></td>
</tr>-->*/
<tr>
<td width="33%" bgcolor="#FFE3BB">
<p style="margin-left: 10"><font face="Verdana" size="2">
<br>
<br>
&nbsp;</font></td>
<td width="67%" bgcolor="#FFE3BB">
<font face="Verdana" size="2">
<input type="submit" value="Submit"></font></td>
</tr>
</table>
</form>

</body>
</html>

[/UBB]

I then created a php script to store the values from the form in mysql a database called projectg, table lecfiles. as below...

[UBB]

<html>
<head>
<title> this is a test </title>
</head>

<body>

<?

// Grabdetails.php:
//Takes all the details of the
//new file posted from the form
//and adds them to the lecfiles
//table of projectg DB.


//Make sure both a description and
//file have been entered
if (!$ModCode &#0124; &#0124; !$Title &#0124; &#0124; !$Lecturer &#0124; &#0124; !Week &#0124; &#0124; !$Topics)
{
echo "You have not completed the form correctly,
Please go back and try again.";
exit;
}

$ModCode = addslashes($ModCode);
$Title = addslashes($Title);
$Lecturer = addslashes($Lecturer);
$Week = addslashes($Week);
$Topics = addslashes($Topics);

$db = mysql_pconnect("localhost", "root", "password");

if (!$db)
{
echo "Error: Gee could not connect to database";
exit;
}

mysql_select_db("lecfiles");
$query = "insert into lecfiles VALUES
('".$ModCode."', '".$Title."', '".$Lecturer."', '".$Week."', '".$Topics."')";
$result = mysql_query($query);

if ($result)
echo mysql_affected_rows()." Data inserted into Database.";

?>

</body>
</html>

[/UBB]

Any offers???????????????

Please?????????

I keep runnin into brick walls with this stuff!

Gee.

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 11-26-2002 06:16

I would have covered my bases by writing:

if (!isset($variable1) OR !isset($variable2) OR ... )
{
statements
}

Your code looks like it ought to work, but try my more explicit version and see what you get.

Ooh, hey! Check your PHP info and see if Register_Globals is on! If it's not (which it probably shouldn't be, for your sake -- see here), you'll have to specifically dig your variables out of the GET or POST global array. I use the "pt_register" function provided in the comments by a helpful hacker.

Did you know there's a punk band living in my living room? Life is weird.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-26-2002 07:31

!Week

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-26-2002 09:31

well, if you were running your scripts on an older php version,
things have changed a bit.
Namely, incoming vars are now only in $HTTP_GET_VARS['varname'] , $HTTP_POST_VARS['varname'] or $_GET and $_POST respectively.
So just using $varname won't work anymore.
You'll probably want to change that.

So long,
Tyberius Prime

rickindy
Nervous Wreck (II) Inmate

From: Indianapolis, In USA
Insane since: Jan 2002

posted posted 11-26-2002 13:10

You can also get the variables from the form with $_REQUEST["variable_name"]

It's somewhat more portable in that it won't matter whether to submitting form uses the GET or POST method.



Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 11-26-2002 14:40

ThnX for the replys peoples, I am now gonna investigate further,

Ps. bitdamaged wrote...
"!week

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-26-2002 17:50

hokay a couple of tips for trouble shooting.

You're using post variables so I like sometimes to dump all my variables.

foreach ($_POST as $k => $v){
echo "<li> $k - $v \n";
}

That should dump everything so you can see what you've got (you may need to change $_POST to $HTTP_POST_VARS)

also I'd break down your ifs so you can see if one of them is broken

if (!$Mod_Code) echo "no mod code";
if (!$Week) echo "no week";


etc.




.:[ Never resist a perfect moment ]:.

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 11-26-2002 19:20

You said you just installed the whole setup, and you're using PHP 4.2.x, so I'll bet a dollar to a donut it's register_globals, like Tyberius Prime and I suggested. Read the link I posted and fiddle with your code accordingly. PHP has the best online manual I can think of, use it lovingly.

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 11-26-2002 23:12

ThnX again peoples,

I fixed my if statement by using $_POST['var'] declarations.

That function for echoing all varials is very handy as well, I will keep hold of that for future debugging.

Gee

« BackwardsOnwards »

Show Forum Drop Down Menu