Jump to content

PHP entering phantom charecture in MYSQL query


advancedfuture

Recommended Posts

So I am creating a form to generate an invoice. and for some reason it the query that it generates enters a phantom charecture

 

Here is the output I get from printing the query... i have bolded the error!

 

INSERT INTO invoices (apartmentName, apartmentAddress, apartmentCity, apartmentState, apartmentZip, apartmentReferral, clientName, apartmentManager, apartmentPhone) VALUES ('Test Apartment', '7 Via Arribo', 'Rancho Santa Margarita', 'CA', '92688','', 'jason miller', 'cindy sheen', '949-555-1234')

 

Notice it is the " inbetween '92688' and 'jason miller' I have NO IDEA where this is coming from. I have checked the database and there are no quote marks to be found!

 

Here is the code for the invoice generation page.

 

<?php
include 'dbconnect.php';
$apartmentId = $_GET['apartmentId'];
$clientId = $_GET['clientId'];

$query = "SELECT * FROM apartments WHERE apartmentId = '$apartmentId'";
$results = mysql_query($query);

while($row = mysql_fetch_array($results))
{
$query2 = "SELECT * FROM inquiry WHERE clientId = '$clientId'";
$results2 = mysql_query($query2);
while($row2 = mysql_fetch_array($results2))
{
	$apartmentName = $row['apartmentName'];
	$apartmentAddress = $row['apartmentAddress'];
	$apartmentCity = $row['apartmentCity'];
	$apartmentState = $row['apartmentState'];
	$apartmentZip = $row['apartmentZip'];
	$apartmentReferral = $row['apartmentReferral'];
	$apartmentManager = $row['apartmentManager'];
	$apartmentPhone = $row['apartmentPhone'];
	$clientName = $row2['firstName']." ".$row2['lastName'];

	$query3 = "INSERT INTO invoices (apartmentName, apartmentAddress, apartmentCity, apartmentState, apartmentZip, apartmentReferral, clientName, apartmentManager, apartmentPhone) VALUES ('$apartmentName', '$apartmentAddress', '$apartmentCity', '$apartmentState', '$apartmentZip','$apartmentReferral', '$clientName', '$apartmentManager', '$apartmentPhone')";
	echo $query3;
	$results3 = mysql_query($query3) or die("error");
}
}
?>

Not that it should make a difference but see this:

 

$apartmentState', '$apartmentZip','$apartmentReferral',

 

Try changing:

'$apartmentZip','$apartmentReferral',

 

to:

'$apartmentZip', '$apartmentReferral',

 

See if it makes a difference.

Since it's your database I can't really help you, but I did this:

 

<?php

$apartmentName = 'Test Apartment';
	$apartmentAddress = '7 Via Arribo';
	$apartmentCity = 'Rancho Santa Margarita';
	$apartmentState = 'CA';
	$apartmentZip = '92688';
	$apartmentReferral = 'jason miller';
	$apartmentManager = 'cindy sheen';
	$apartmentPhone = '949-555-1234';
	$clientName = 'James'." ".'West';


	$query3 = "INSERT INTO invoices (apartmentName, apartmentAddress, apartmentCity, apartmentState, apartmentZip, apartmentReferral, clientName, apartmentManager, apartmentPhone) VALUES ('$apartmentName', '$apartmentAddress', '$apartmentCity', '$apartmentState', '$apartmentZip', '$apartmentReferral', '$clientName', '$apartmentManager', '$apartmentPhone')";
	echo $query3;


?>

 

It was fine like that which suggests it's the coding above query3.

ok this is EXTREMELY bizzare I switches all the single quotes to double quotes and enclosed the query in single quotes.

 

so it looks like

 

$query3 = 'INSERT INTO invoices (apartmentName, apartmentAddress, apartmentCity, apartmentState, apartmentZip, apartmentReferral, clientName, apartmentManager, apartmentPhone) VALUES ("$apartmentName", "$apartmentAddress", "$apartmentCity", "$apartmentState", "$apartmentZip", "$apartmentReferral", "$clientName", "$apartmentManager", "$apartmentPhone")';

 

and now the phantom double quotes went away!! What the heck??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.