Jump to content

[SOLVED] Any one see whats wrong with my query?


SirChick

Recommended Posts

Ok its alot of code though !

 

PHP processing:

 

<?
include ("include.php");
If (isset($_POST['SendInputLetter']))
{
$Selection = $_POST['UserID'];
If ($Selection = 1 ) {

$MessageText = mysql_real_escape_string($_POST['Letter']);
$Username = mysql_real_escape_string($_POST['Username']);
$Date = date("Y-m-d H:i:s",time());
$Subject = mysql_real_escape_string($_POST['Subject']);

$query = "SELECT * FROM userregistration WHERE Username='$Username'";
$GetUserName = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
if (!($row = mysql_fetch_assoc($GetUserID))) {
	die('This Username does not exist!');
}					
$UserID = $row["UserID"];					
$Sender = $_SESSION['Current_User'];

If ($UserID == $_SESSION['Current_User']){
Echo ' You cannot send messages to yourself!';

$query = "INSERT INTO `messages` (Reciever, Sender, Senttime, MessageText, Subject)
				Values ('$UserID', '$Sender', '$Date', '$MessageText', '$Subject')";
	mysql_query($query) or die(mysql_error(). " with query ". $query); // get useful error message

}


ElseIf ($Selection = 2 ) {

$UserID = mysql_real_escape_string($_POST['UserID']);
$Date = date("Y-m-d H:i:s",time());
$Subject = mysql_real_escape_string($_POST['Subject']);
$MessageText = mysql_real_escape_string($_POST['Letter']);

$CheckUserID = mysql_query("SELECT * FROM userregistration
                    WHERE UserID='$UserID'");
If (!($row = mysql_fetch_assoc($CheckUserID))) {

	Echo 'Username:';
	Echo $CheckUserID;
	Echo 'UserID:';
	Echo $UserID;
}

If ($UserID == $_SESSION['Current_User']){
Echo ' You cannot send messages to yourself!';


$Sender = $_SESSION['Current_User'];


$query = "INSERT INTO `messages` (Reciever, Sender, Senttime, MessageText, Subject)
				Values ('$UserID', '$Sender', '$Date', '$MessageText', '$Subject', '$Date')";
	mysql_query($query) or die(mysql_error());

}
}

Else {
Echo 'Please click the button to say which input box you are using!';
}
}


If (isset($_POST['SendAddressLetter'])){

$Area = $_POST['Region'];
$StreetName = $_POST['StreetName'];
$HouseNumber = mysql_real_escape_string($_POST['HouseNumber']);
$Subject = mysql_real_escape_string($_POST['Subject']);
$MessageText = mysql_real_escape_string($_POST['Letter']);
$Date = date("Y-m-d H:i:s",time());

If ($Area == ""){
Echo 'You must choose a region!';
}
ElseIf ($StreetName == ""){
Echo 'You must choose a street name!';
}
ElseIf ($StreetName && $Area == ""){
Echo 'You must choose a street name and region!';
}
ElseIf ($HouseNumber == ""){
Echo 'You must choose a house number that exists!';
}
Else{


$FindUser = mysql_query("SELECT UserID FROM houses
                    WHERE Area='$Area', StreetName='$StreetName', HouseNumber='$HouseNumber'");

				$Sender = $_SESSION['Current_User'];

$query = "INSERT INTO `messages` (Reciever, Sender, Senttime, MessageText, Subject)
				Values ('$FindUser', '$Sender', '$Date', '$MessageText', '$Subject', '$Date')";
	mysql_query($query) or die(mysql_error());
}
}
?>

 

 

HTML form:

 

<form name="" method="POST" action="" enctype="multipart/form-data" id="Form1" onsubmit="return ValidateForm1(this)">

<div id="bv_Text19" style="position:absolute;left:100px;top:0px;width:150px;height:16px;z-index:17" align="center">
<font style="font-size:13px" color="#282828" face="Arial"><b><u>Subject:</u></b></font>
<input type="text" id="Subject" style="position:absolute;left:200px;top:0px;width:144px;font-family:Courier;font-size:19px;z-index:16" size="16" name="Subject" value="">
</div>

<textarea name="Letter" id="TextArea1" style="position:absolute;left:29px;top:27px;width:462px;height:443px;border:1px #000000 solid;z-index:0" rows="26" cols="49"></textarea>
<input type="text" id="Username" style="position:absolute;left:31px;top:580px;width:144px;font-family:Courier;font-size:19px;z-index:1" size="16" name="Username" value="">
<div id="bv_Text10" style="position:absolute;left:71px;top:556px;width:65px;height:32px;z-index:2" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><b><u>Username</u></b></font></div>
<div id="bv_Text12" style="position:absolute;left:165px;top:478px;width:198px;height:22px;z-index:3" align="center">
<font style="font-size:19px" color="#000000" face="Arial"><b><u>Sending Methods</u></b></font></div>
<div id="bv_Text13" style="position:absolute;left:73px;top:636px;width:51px;height:16px;z-index:4" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><b><u>User ID</u></b></font></div>
<input type="text" id="UserID" style="position:absolute;left:29px;top:661px;width:144px;font-family:Courier;font-size:19px;z-index:5" size="16" name="UserID" value="">
<select name="Region" size="1" id="Combobox1" style="position:absolute;left:350px;top:555px;width:150px;font-family:MS Shell Dlg;z-index:6">
<option value=""> </option>
<option>North East</option>
<option>North West</option>
<option>South</option>
<option>South East</option>
<option>South West</option>
</select>
<input type="text" id="HouseNumber" style="position:absolute;left:349px;top:670px;width:144px;font-family:Courier;font-size:19px;z-index:7" size="16" name="Editbox3" value="">
<select name="StreetName" size="1" id="Combobox2" style="position:absolute;left:348px;top:610px;width:150px;font-family:MS Shell Dlg;z-index:8">
<option value=""> </option>
<option>Regent Street</option>
<option>Mayfair Street</option>
<option>Parklane Avenue</option>
<option>Oxford Street</option>
<option>Edgware Road</option>
<option>Downing Street</option>
<option>Old Kent Road</option>
<option>Northumberland Road</option>
<option>Maryelbone Street</option>
<option>Queens Road</option>
<option>The Strand</option>
<option>Brick Lane</option>
<option>Canden Road</option>
<option>Grenich Road</option>
<option>Liverpool Street</option>
</select>
<div id="bv_Text14" style="position:absolute;left:8px;top:618px;width:39px;height:16px;z-index:9" align="left">
<font style="font-size:13px" color="#000000" face="Arial">OR</font></div>
<div id="bv_Text15" style="position:absolute;left:347px;top:590px;width:150px;height:16px;z-index:10" align="center">
<font style="font-size:13px" color="#000000" face="Arial"><b><u>Street Name</u></b></font></div>
<div id="bv_Text16" style="position:absolute;left:346px;top:648px;width:150px;height:16px;z-index:11" align="center">
<font style="font-size:13px" color="#000000" face="Arial"><b><u>House Number</u></b></font></div>
<div id="bv_Text17" style="position:absolute;left:344px;top:537px;width:150px;height:16px;z-index:12" align="center">
<font style="font-size:13px" color="#000000" face="Arial"><b><u>Region</u></b></font></div>

<input type="submit" id="Button1" name="SendInputLetter" value="Send Letter By Username Or ID" style="position:absolute;left:10px;top:700px;width:210px;height:24px;z-index:13">
<input type="submit" id="Button2" name="SendAddressLetter" value="Send Letter By Address" style="position:absolute;left:340px;top:700px;width:170px;height:24px;z-index:13">


<input type="radio" id="RadioButton1" name="UserID" value="1" style="position:absolute;left:177px;top:582px;z-index:14">
<input type="radio" id="RadioButton2" name="UserID" value="2" style="position:absolute;left:179px;top:662px;z-index:15">


</form>

Link to comment
Share on other sites

1st

If ($Selection = 1 ) { ia allways true (do you mine $Selection == 1)

 

2nd

$query = "SELECT * FROM userregistration WHERE Username='$Username'";
$GetUserName = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
if (!($row = mysql_fetch_assoc($GetUserID))) { // change $GetUserID to $GetUserName see line before
die('This Username does not exist!');
}

Link to comment
Share on other sites

well what had happened was my notepad++ buggered up, i had changed it when you had spotted it. As i said it was a good spot but it didn't save when i thought it had so i was looking at the bigger picture rather than something like that for i had thought i already corrected it.

 

I had some annoying "config.xml wont load" error with notepad++ so i had to reinstall that which set me back cos a lot of code was lost ! Only now you guys have highlighted it didn't save from yesterday!

Link to comment
Share on other sites

No no it was just that one part was stumping me. I'm going to debug the rest now. It was mostly confusing cos it was working the night before but not the next day and i couldn't see it for the life of me even when i read through it for hours.

 

Anyway thanks for the help guys sorry for wasting your time on a silly mistake!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.