Page 1 of 1
HTML Form Troubles
Posted: Wed Aug 17, 2005 5:06 pm
by camhabib
I'm trying to write a script to post information from a HTML form to a MySQL database. I wrote this, it executes when the submit button is pressed, that much I got it to do. However nothing happens. It doesn't return any message, doesn't post any information. I changed the password and username for posting, but it logs in fine, just nothing happens.
Code: Select all
<?php
$password="password";
$username="username";
$database="mysql";
$Quote=$_POST['quote'];
$FName=$_POST['fname'];
$LName=$_POST['lname'];
$City=$_POST['city'];
$State=$_POST['state'];
$Country=$_POST['country'];
$Age=$_POST['age'];
$Gender=$_POST['age'];
$Marital=$_POST['marital'];
$Occupation=$_POST['occu'];
$Education=$_POST['edu'];
$Mail=$_POST['email'];
mysql_connect($database,$username,$password);
@mysql_select_db($database) or die("Unable to connect to database");
$query="INSERT INTO Submissions.info SET Quote='$quote', FName='$fname', LName='$lname',
city='$city', state='$state', country='$country', age='$age', gender='$gender',
marital='$marital', occupation='$occupation', education='$education', mail='$mail';
mysql_query($query)" = $conf;
if ($conf) echo"Sucsessful entry";
else echo"Entry failure";
mysql_close();
?>
feyd | Please use Code: Select all
tags when posting php code.[/color][/size]
Posted: Wed Aug 17, 2005 5:12 pm
by feyd
uhm.. you need a mysql_query() call.
Posted: Wed Aug 17, 2005 5:13 pm
by camhabib
I have one, 5th line from the bottom, or are you talking about something else?
Re: HTML Form Troubles
Posted: Wed Aug 17, 2005 5:19 pm
by nielsene
Code: Select all
<?php
$password="password";
$username="username";
$database="mysql";
$Quote=$_POST['quote'];
$FName=$_POST['fname'];
$LName=$_POST['lname'];
$City=$_POST['city'];
$State=$_POST['state'];
$Country=$_POST['country'];
$Age=$_POST['age'];
$Gender=$_POST['age'];
$Marital=$_POST['marital'];
$Occupation=$_POST['occu'];
$Education=$_POST['edu'];
$Mail=$_POST['email'];
mysql_connect($database,$username,$password);
@mysql_select_db($database) or die("Unable to connect to database");
$query="INSERT INTO Submissions.info SET Quote='$quote', FName='$fname', LName='$lname',
city='$city', state='$state', country='$country', age='$age', gender='$gender',
marital='$marital', occupation='$occupation', education='$education', mail='$mail'";
$conf = mysql_query($query);
if ($conf) echo"Sucsessful entry";
else echo"Entry failure";
mysql_close();
?>
Your double quotes were extending to include the mysql_query and you had the function call on the wrong side of an equality.
Posted: Wed Aug 17, 2005 5:20 pm
by feyd
your code specifically says it's not there. You notice how mysql_query() is red? That means it's inside a string.
and assignments go right to left, not left to right (swap $conf and mysql_query()'s location in the line after fixing the string issue.)
Posted: Wed Aug 17, 2005 5:25 pm
by camhabib
WOW, I feel really pretty stupid right now. So it was just the order of the variable being defined and the "" that screwed that whole script up?
Posted: Wed Aug 17, 2005 5:28 pm
by nielsene
Failing to close a quote will always wreck havoc on a script. Its one reason why a lot of people use tools that will highlight the different parts of the code in different colors, makes it very easy to see when you've got an unclosed quote somewhere.
Ditto for "side-ness" (left versus right) on assignments.
Posted: Wed Aug 17, 2005 7:26 pm
by Ambush Commander
Of course, when you're typing, and then the colors start flashing, you know that your syntax highlighting is hypersensitive.

Posted: Wed Aug 17, 2005 11:48 pm
by camhabib
Alright, so the script was working. I then decided to add a function that made it so that if any field was left blank it would redirect to another page instead of continuing to post to the database. However, when I use this new script, nothing happens. Its just like before. I checked all of the "" and {} not to menion the order of everything. I think I'm going to have to quite this whole PHP thing if this keeps up.
Code: Select all
<?php
$password="password";
$username="username";
$database="mysql";
$Quote=$_POST['quote'];
$FName=$_POST['fname'];
$LName=$_POST['lname'];
$City=$_POST['city'];
$State=$_POST['state'];
$Country=$_POST['country'];
$Age=$_POST['age'];
$Gender=$_POST['age'];
$Marital=$_POST['marital'];
$Occupation=$_POST['occu'];
$Education=$_POST['edu'];
$Mail=$_POST['email'];
mysql_connect($database,$username,$password);
@mysql_select_db($database) or die("Unable to connect to database. Please contact the webmaster for further assistance.");
$incor=""
if (strcmp($Quote,$incor) != 0) {
require("incomp.html");
} else if (strcmp($FName,$incor) != 0) {
require("incomp.html");
} else if (strcmp($LName,$incor) != 0) {
require("incomp.html");
} else if (strcmp($City,$incor) != 0) {
require("incomp.html");
} else if (strcmp($State,$incor) != 0) {
require("incomp.html");
} else if (strcmp($Country,$incor) != 0) {
require("incomp.html");
} else if (strcmp($Age,$incor) != 0) {
require("incomp.html");
} else if (strcmp($Gender,$incor) != 0) {
require("incomp.html");
} else if (strcmp($Marital,$incor) != 0) {
require("incomp.html");
} else if (strcmp($Occupation,$incor) != 0) {
require("incomp.html");
} else if (strcmp($Education,$incor) != 0) {
require("incomp.html");
} else if (strcmp($Mail,$incor) != 0) {
require("incomp.html");
} else {
$query="INSERT INTO Submissions.info SET Quote='$quote', FName='$fname', LName='$lname', city='$city', state='$state', country='$country', age='$age', gender='$gender', marital='$marital', occupation='$occupation', education='$education', mail='$mail'";
$conf = mysql_query($query);
if ($conf) {
require("form_comf.html");
}
else {
require("form_deny.html");
}
}
mysql_close();
?>
Posted: Thu Aug 18, 2005 1:55 am
by pentiumhead
instead of setting:
$inCor = "";
then comparing with each variable
myadvice is use:
if (!strlen($variable_name))
{
require("error_page.html");
}
That might just solve it.
Kay
Posted: Thu Aug 18, 2005 7:22 am
by camhabib
Forgot a ; on the $incorr statement. Plus changed != to ==. Stupid mistakes as usual that I didn't catch until I posted.