SirChick Posted August 27, 2007 Author Share Posted August 27, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335606 Share on other sites More sharing options...
sasa Posted August 27, 2007 Share Posted August 27, 2007 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!'); } Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335630 Share on other sites More sharing options...
SirChick Posted August 27, 2007 Author Share Posted August 27, 2007 right thats changed though not the $query just yet cos i don't see any difference with what you posted to what i already have? EDIT: Oh i see it! Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335643 Share on other sites More sharing options...
sasa Posted August 27, 2007 Share Posted August 27, 2007 you have $GetUserName = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); it puts result objects in variable $GetUserName, but in next line you fatch variable $GetUserID Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335649 Share on other sites More sharing options...
Barand Posted August 27, 2007 Share Posted August 27, 2007 $GetUserName = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); if (!($row = mysql_fetch_assoc($GetUserID))) { I don't believe this guy - I told him about that one 28 posts ago. (reply #1) Why waste our time? Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335669 Share on other sites More sharing options...
SirChick Posted August 27, 2007 Author Share Posted August 27, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335677 Share on other sites More sharing options...
Barand Posted August 27, 2007 Share Posted August 27, 2007 So I guess you want is to debug your code a second time? Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335688 Share on other sites More sharing options...
SirChick Posted August 27, 2007 Author Share Posted August 27, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/66795-solved-any-one-see-whats-wrong-with-my-query/page/2/#findComment-335692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.