NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help Please... this doesnt make sense (PHP)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-17-2003, 12:56 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: Feb 2003
Posts: 13
ivcho is an unknown quantity at this point
 



Help Please... this doesnt make sense (PHP)


Hi guys,

I can't describe how frustrated this has made me.. and it's the littlest thing but I can't go any further without it working..

I have a simple form with a textfield and a submit button

The main goal is to send the value of the textfield to the database when you click Submit..

Problem is that when I click submit it updates the database but it inserts a blank instead of the value I typed in the textfield..
When I do my INSERT command where I use the textfield variable I'm also using a CURDATE() to insert a date into the database which actually works and the dates shows up in the database.

Given that I can now narrow it down to the fact that php just won't recognize the value of my textfield... BUT.. when I use a post method for my form to see the URL values passed the value for my textfield (which PHP doesn't recognize) is in fact displayed in the URL..
????: NamePros.com http://www.namepros.com/programming/14567-help-please-doesnt-make-sense-php.html

here is the full code
<html>
<head><title>WORK!!!!</title>
</head>
<body>
<form action="<?=$PHP_SELF?>" method="get">
<p>Type your name here:<br />
<input type = "text" name = "initial"><br />
<input type="submit" name="submitjoke" value="SUBMIT" /></p>
</form>
<?php // Default page display
// Connect to the database server
$dbcnx = @mysql_connect("localhost", "root", "");
if (!$dbcnx) { echo( "<p>Unable to connect to the " . "database server at this time.</p>" ); exit();

}else {
echo("Connected to Dabase Server");
}

// Select the employee database
if (! @mysql_select_db("employee") ) {
echo( "<p>Unable to locate the employee " . "database at this time.</p>" );
exit();
}
else {
echo("Connected to database employee");
}


this part right now does not execute since I'm once again trying to use a variable from my form. If I remove the first condition where I check for SUBMIT it processes the sql INSERT statement and inserts the date but of course not the Name
if ($submitjoke == "SUBMIT") {
$sql = "INSERT INTO hrdata SET Name = '$initial', Hired = CURDATE()";
if (@mysql_query($sql)) {
echo("<p>Your name has been added.</p>"); }
else {
echo("<p>Error adding name: " . mysql_error() . "</p>");
}
}


echo("<p> Here are all the names in our database: </p>");
$result = @mysql_query("SELECT Name, Hired FROM hrdata");
if (!$result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit();
} // Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) { echo("<p>" . $row["Name"] . " " . $row["Hired"] ."</p>"); }
?>
</body>
</html>



does anybody know what's going on here?

Thank you kindly in advance
ivcho is offline  
Old 02-17-2003, 06:22 PM   #2 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



Hi I'm know mysql or php guru, but I think your problem may be with the first line in this section of your code:

if ($submitjoke == "SUBMIT") {
$sql = "INSERT INTO hrdata SET Name = '$initial', Hired = CURDATE()";
if (@mysql_query($sql)) {
echo("<p>Your name has been added.</p>"); }
else {
echo("<p>Error adding name: " . mysql_error() . "</p>");
????: NamePros.com http://www.namepros.com/showthread.php?t=14567
}
}


Right here you have:
if ($submitjoke == "SUBMIT")


This is saying if the text entered into the textbox equals "SUBMIT" so unless somebody enters "SUBMIT" in your text box then it will go on to the else statement.

I think it should just be:
if ($submitjoke)

with out the == operator in there.

This way it's saying if anything is in the textbox instead of if "SUBMIT" is in the textbox.

I could be wrong though. Let us know if you get it working.
deadserious is offline  
Old 02-17-2003, 07:35 PM   #3 (permalink)
NamePros Regular
Join Date: Sep 2002
Location: Canada
Posts: 481
DarkDevil is an unknown quantity at this point
 



Your right deadserious, i'm not to sure if thats the only problem or not. I can't really think straight as of now because I'm learning Visual Basic in school and i'm thinking a little of both languages. Plus i never bothered learning SQL stuff.
__________________
Sometimes I lay awake at night and I ask "Where have I gone wrong?" Then a little voice says "This is going to take more than one night"
DarkDevil is offline  
Old 02-20-2003, 01:46 PM   #4 (permalink)
New Member
Join Date: Feb 2003
Posts: 2
bmiddleton is an unknown quantity at this point
 



$HTTP_GET_VARS


This may be your problem. In the most recent versions of PHP, you have to use $HTTP_POST_VARS or $HTTP_GET_VARS for variables passed from a form to a php page.

Since you are using GET, you will format your variables passed like $HTTP_GET_VARS['variable_name'].

More info can be found here:

http://www.php.net/manual/en/languag...predefined.php

Also, you might wanna replace

if ($submitjoke == "SUBMIT")

with

if (isset($HTTP_POST_VARS['SUBMIT']))

Try it out and let us know if it works.

-brian
bmiddleton is offline  
Old 02-24-2003, 07:16 PM   #5 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



Hey bmiddleton I 'm not really familiar with php beyond the basics, just a question about this code:

if (isset($HTTP_POST_VARS['SUBMIT']))


Does this say if the submit button is pressed or what does it do

I guess I need to read up on that stuff.
deadserious is offline  
Old 02-26-2003, 09:25 AM   #6 (permalink)
New Member
Join Date: Feb 2003
Posts: 2
bmiddleton is an unknown quantity at this point
 



Quote:
Originally posted by deadserious
if (isset($HTTP_POST_VARS['SUBMIT']))


Does this say if the submit button is pressed or what does it do
yeah..if the submit button was pressed it will do the following..that is what it says..
????: NamePros.com http://www.namepros.com/showthread.php?t=14567

let us know if it works..

-b
bmiddleton is offline  
Old 02-27-2003, 07:41 PM   #7 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



Cool thanks! I'm used to checking each field individually and going off that rather than processing something just because the form was submitted. This way you don't let the user get past your forms unless they fill in all required information and don't use illegal characters and such. But that could be useful I suppose.
deadserious is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:04 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger