...

View Full Version : PHP/MySQL problem



Erreon
09-18-2006, 07:30 PM
I have written a very messy very quick kiosk registration for a company that I work for. I wrote it in PHP so that we could use it in different locations. I have gotten it to print the information, but I am having problems getting it to send the information to a MySQL table that's formed for it... and it gives me 0 errors. Here is the code:

<?php
include('db.php');

$errors = array();

if(!$_POST['fName'])
$errors[] = "Please enter your first name";
if(!$_POST['AgentCheck'])
$errors[] = "Please answer the question regarding an agent";
if (count($errors)>0){
echo "<strong>Required:<br>\n";
foreach($errors as $err)
echo "$err<br>\n";
} else {
$handle = printer_open("\\\\192.168.1.123\print");
mysql_query("INSERT INTO registration (firstName, lastName, streetAddress, city, state, phoneNumber, agent, emailAddress, lookingFor1, LookingFor2, date) values('$_POST[fName]','$_POST[lName]','$_POST[sAddress]','$_POST[City]','$_POST[State]',$_POST[ZipCode]','$_POST[PhoneNum]','$_POST[AgentCheck]','$_POST[Email]','$_POST[lookingfor]', now())");

$guestRegister = "A new guest has registered with Volente Realty on ".date("F j, Y")." at ".date("g:i a")."\n\r";
switch($_POST['AgentCheck'])
{
case 'Yes':
$guestRegister .= $_POST[fName].' '.$_POST[lName]." is working with another Real Estate Agent.\n\r";
break;
case 'No':
$guestRegister .= $_POST[fName].' '.$_POST[lName]." is not working with another Real Estate Agent.\n\r";
break;
default:
echo 'Somethings wrong call Jason!';
break;
}

if (!empty($_POST['lookingfor']))
{
if (!empty($_POST['lotPrice1']))
{
$guestRegister .= "Lot under $150,000\n\r";
}
if (!empty($_POST['lotPrice2']))
{
$guestRegister .= "Lot above $150,000\n\r";
}
if (!empty($_POST['lotPrice3']))
{
$guestRegister .= "Waterfront lot above $350,000\n\r";
}
if (!empty($_POST['housePrice1']))
{
$guestRegister .= "House under $250,000\n\r";
}
if (!empty($_POST['housePrice2']))
{
$guestRegister .= "House above $250,000\n\r";
}
}

$guestRegister .= "\n\r".$_POST[fName]." ".$_POST[lName]."\n\r".$_POST[sAddress]."\n\r".$_POST[City]." ".$_POST[State].' '.$_POST[ZipCode]."\n\r";

$guestRegister .= "\n\r".$_POST[PhoneNum];
$guestRegister .= "\n\r".$_POST[Email];
printer_start_doc($handle, "Guest Registry");
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle, $guestRegister);
printer_end_doc($handle);
printer_close($handle);
}
?>

Any help and suggestions like nuke it and start over are more then welcome and I appreciate the input!

Taylor_1978
09-18-2006, 09:49 PM
You're right, it is messy - so I haven't looked deep into it.. but perhaps change this line:

mysql_query("INSERT INTO registration (firstName, lastName, streetAddress, city, state, phoneNumber, agent, emailAddress, lookingFor1, LookingFor2, date) values('$_POST[fName]','$_POST[lName]','$_POST[sAddress]','$_POST[City]','$_POST[State]',$_POST[ZipCode]','$_POST[PhoneNum]','$_POST[AgentCheck]','$_POST[email]','$_POST[lookingfor]', now())") or die(mysql_error());

And then you'll find that this query is in a bad order:

Eg. firstName, lastName, streetAddress, city, state AND

'$_POST[fName]','$_POST[lName]','$_POST[sAddress]','$_POST[City]','$_POST[State]',$_POST[ZipCode]'

The order is different.. Where is the field for ZipCode? You also have two LookingFor's (1 and 2) set only 1 in your values..

You should get in practise of adding or die(mysql_error()); as you should have been able to pick this up yourself.

Good luck :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum