Text field not posting properly to DB... getting stuck @ '

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rprins
Forum Commoner
Posts: 31
Joined: Sat Jun 21, 2003 5:46 pm

Text field not posting properly to DB... getting stuck @ '

Post by rprins »

Ok, I have made an online application that has a part where the users enter in text into a text area. The text and everything gets entered in just fine... but when it tries to post to the DB it gets all messed up. For instance: If the user enters in
This is a test to see if I'm doing this properly.
The DB will post
This is a test to see if I\
I have

Code: Select all

<?php 
addslashes($string);
?>
in the script and it sill does not post properly to the mySQL DB. Any assistance you could offer would be of great help! Thanks in advance!
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Crapola! double postage!
Last edited by Drachlen on Tue Jul 08, 2003 1:35 am, edited 1 time in total.
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Code: Select all

<?php
$txt = str_replace("''", "'", $txt);
$txt = str_replace('"', '"', $txt);
echo "$txt";
?>
This also includes using " because that also wacks out.. I knew what i was trying to find, so i went to phpbb source code... phpbb helps with everything :D

Just throw those 2 lines in before you add it to the DB :D
User avatar
rprins
Forum Commoner
Posts: 31
Joined: Sat Jun 21, 2003 5:46 pm

Post by rprins »

Doesn't the addslashes($string) do the exact same thing?

http://us2.php.net/manual/en/function.addslashes.php

Also, it is adding the slashes into the text in the script. So I'm is turning into I''m. But for some reason it is not posting to the DB properly. I am using PHPMyAdmin for checking the DB... could it be a problem w/ that software?
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

Or what about Stripslashes :D
Returns a string with backslashes stripped off. ('' becomes ' and so on.) Double backslashes are made into a single backslash.
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

I don't know. I tried adding on the addslashes and it didnt make a difference... Did you try what i suggested? i tested it and it is writing it into the database fine..
User avatar
rprins
Forum Commoner
Posts: 31
Joined: Sat Jun 21, 2003 5:46 pm

Post by rprins »

Doing that str_replace was just the same as doing addslashes(). Sill when I echo it right before I post to the DB it shows I''m but still gets hung up in the same spot.

Here are the table names and their type:

Code: Select all

essay  text   
comp  text
WORK  mediumtext
educate  varchar(30)
background  longtext
contactime  text
comments  mediumtext
And here is the PHP:

Code: Select all

<?php
	if($action){
		switch($action){
			case "req":
				echo "<font size=4 face=verdana>Current Positions Accepting Applications</font><p><table border=0>";
					$jobquery = "SELECT * FROM `staff_jobs` WHERE open = '1' ORDER BY title ASC ";
					$result = mysql_query($jobquery, $connection) or die("Hill Gather Query Error");
					
					while($row = mysql_fetch_array($result)){
					$jid = $row['jid'];
					$jtitle = $row['title'];
					$jdescription = $row['desc'];
					$jbenefits = $row['benefits'];
					$jrequired = $row['req'];
					$jexpectations = $row['expect'];
					$jprereq = $row['prereq'];
					$jcommitment = $row['commit'];
					
					echo "<tr><td valign=top><b>$jtitle</b></td><td valign=top><font face=verdana size = 2>(<a href="javascript:MS_openJob('$PHP_SELF?jidd=$jid')">More Information</a>)</font></td></tr><p>
					";
					
					}
				echo "</table>Please ensure that you meet the requirements and prerequisites, as well as understand the expectations, for the position for which you are applying. Make any notes or comments in the comments section on the application<p>
				<a href='employ.php'>Previous Page</a> | <a href='$PHP_SELF?action=legal'>Next Page</a> | Page 1/5";
			break;
			
			case "legal":
				echo "<font size=4 face=verdana>Legal Statement</font><br>
						I have read the <a href="policy.php?policy=privacy" target="_blank">Midwestskier Online Privacy Policy</a> and <a href="policy.php?policy=company" target="_blank">Company Policy</a> listed on this website. By clicking I Agree I hear by affirm that I have read, understand, and agree to all conditions listed therein and will be held accountable for the content within.<p>";
				echo "<a href='$PHP_SELF?action=req'>Previous Page</a> | <a href='$PHP_SELF?action=app'>I Agree</a> | Page 2/5";
			break;
			
			case "app":
				echo"<font size=4 face=verdana>Application Form v1</font><br>
				<form name='userapply' method='post' action='$PHP_SELF?action=verify'>
				<table>
					<tr>
						<td>First Name*</td>
						<td><input name='firstname' type='text'size='30'></td>
					</tr>
					<tr>
						<td>Last Name*</td>
						<td><input name='lastname' type='text'size='30'></td>
					</tr>
					<tr>
						<td>Your MS Forum Login*</td>
						<td><input name='forum' type='text'size='30'></td>
					</tr>
					<tr>
						<td>Birthday*</td>
						<td>						
							<select name='birth_month' size='1'>";
							for($i = 1; $i <= 12; $i++){
							echo "<option value='$i'>$months[$i]</option>";
							}
							echo "</select>
							<select name='birth_day' size='1'>";
							for($i = 1; $i <= 31; $i++){
							echo "<option value='$i'>$i</option>";
							}
							echo "</select>
							<select name='birth_year' size='1'>";
							for($i = $byear_limit_old; $i <= $byear_limit_young; $i++){
							echo "<option value='19$i'>19$i</option>";
							}
							echo "</select>";
							$birthday = $birth_year . "-" . $birth_month . "-" . $birth_day;
							echo"
						</td>
					</tr>
					<tr>
						<td>Email Address*</td>
						<td><input name='email' type='text'size='30'></td>
					</tr>
					<tr>
						<td>Home Phone Number*</td>
						<td><input name='hphone' type='text'size='14' maxlength='14'></td>
					</tr>
					<tr>
						<td>Cell Phone Number</td>
						<td><input name='cphone' type='text'size='14' maxlength='14'></td>
					</tr>
					<tr>
						<td>Home Address*</td>
						<td><input name='streetadd' type='text'size='30'></td>
					</tr>
					<tr>
						<td>Apt Number</td>
						<td><input name='apt' type='text'size='30'></td>
					</tr>
					<tr>
						<td>City*</td>
						<td><input name='city' type='text'size='30'></td>
					</tr>
					<tr>
						<td>State*</td>
						<td>
							<select name='state' size='1'>";
							for($i = 0; $i <= count($states) - 1; $i++){
							echo "<option value='$states[$i]'>$states[$i]</option>";
							}
							echo "</select></td>
					</tr>
					<tr>
						<td>Zip Code*</td>
						<td><input name='zip' type='text'size='5' maxlength='5'></td>
					</tr>
					<tr>
						<td>Home Resort*</td>
						<td>
							<select name='homehill' size='1'>";
							for($i = 0; $i <= count ($hills) - 1; $i++){
								$sorted_hills = $ordered_hills[$i];
									echo "<option value='$ordered_hills[$i]'>$hills[$sorted_hills], $hillst[$sorted_hills]</option>";
							}
							echo "</select>
						</td>
					</tr>
					<tr>
						<td>Secondary Resort (if apply)</td>
						<td>
							<select name='homehill2' size='1'>
							<option value=0>None</option>";
							for($i = 0; $i <= count ($hills) - 1; $i++){
								$sorted_hills = $ordered_hills[$i];
									echo "<option value='$ordered_hills[$i]'>$hills[$sorted_hills], $hillst[$sorted_hills]</option>";
							}
							echo "</select>
						</td>
					</tr>
					<tr>
						<td>Years Skied</td>
						<td>
							<select name='yearski' size='1'>";
							for($i = 0; $i <= count ($skiyears) - 1; $i++){
							echo "<option value='$skiyears[$i]'>$skiyears[$i]</option>";
							}
							echo "</select>
						</td>
					</tr>
					<tr>
						<td>Position Applying For*</td>
						<td>
							<select name='jobapplied' size='1'>";
							for($job_id = 1; $job_id <= count ($available_jobs); $job_id++){
							if(!$open_jobs[$job_id]=='0'){
							echo "<option value='$job_id'>$available_jobs[$job_id]</option>";
							} }
							echo "</select> <font size=1 face=verdana>(<a href="javascript:MS_openJob('$PHP_SELF?jidd=list')">review positions</a>)</font>
						</td>
					</tr>
					<tr>
						<td>Current Education</td>
						<td>
							<select name='educate' size='1'>";
							for($i = 0; $i <= count ($education_level) - 1; $i++){
							echo "<option value='$education_level[$i]'>$education_level[$i]</option>";
							}
							echo "</select></td>
					</tr>
					<tr>
						<td>Why do you wish to work for Midwestskier?*</td>
						<td><textarea name='essay' rows='4' cols=50 wrap></textarea></td>
					</tr>
					<tr>
						<td>Competitions History*<br><font size=1 face=verdana>Brief overview (if any) of your history in competition, include top placing/s</font></td>
						<td><textarea name='comp' rows='4' cols=50 wrap></textarea></td>
					</tr>
					<tr>
						<td>Work History*<br><font size=1 face=verdana>include both ski and none skiing positions</font></td>
						<td><textarea name='work' rows='4' cols=50 wrap></textarea></td>
					</tr>
					<tr>
						<td>Background/Experience*<br><font size=1 face=verdana>related to the position applied for</font></td>
						<td><textarea name='background' rows='4' cols=50 wrap></textarea></td>
					</tr>
					<tr>
						<td>Best Time to Contact*<br><font size=1 face=verdana>and preferred method<br>(phone, email, AIM)</font></td>
						<td><textarea name='contactime' rows='4' cols=50 wrap></textarea></td>
					</tr>
					<tr>
						<td>Extra Comments<br><font size=1 face=verdana>Jokes, Web Sections desired (for web faculty), other positions to be reviewed for, height, anything else.</font></td>
						<td><textarea name='comments' rows='4' cols=50 wrap></textarea></td>
					</tr>
					<tr>
						<td colspan='2'>
							<div align='center'> '*' denotes required items<br>
							  <a href='$PHP_SELF?action=legal'>Previous Page</a> | <input name='submit_app' type='submit' value='Review Application'>
							   | <input type='reset' name='_reload' value='Clear Forms'> | Page 3/5
							</div>
						</td>
					</tr>
				</table>";
			break;
			
			case "verify":
			// Begin form data validation
			
			$validapp = 1;	// Application is valid unless it fails any of the following statements.
			if(!is_email($email)){
				if(empty($email)) $email = "No Email Entered";
				echo "<b>Error!</b> You have entered in an invalid email address ($email)<br>";
				$validapp = 0;
			}
			
			if(strlen($zip) < 5){
				if(empty($zip))	$zip = "No Zipcode Provided";
				echo "<b>Error!</b> You have entered in an invalied zip code ($zip)<br>";
				$validapp = 0;
			}
			
			if(empty($firstname)){
				echo "<b>Error!</b> You did not enter in a FIRST NAME.<br>";
				$validapp = 0;
			}

			if(empty($lastname)){
				echo "<b>Error!</b> You did not enter in a LAST NAME.<br>";
				$validapp = 0;
			}
			
			if(empty($forum)){
				echo "<b>Error!</b> You did not enter in a FORUM USER NAME.<br>";
				$validapp = 0;
			}
			
			if(empty($hphone)){
				echo "<b>Error!</b> You did not enter in a HOME PHONE NUMBER.<br>";
				$validapp = 0;
			}
		
			if(empty($streetadd)){
				echo "<b>Error!</b> You did not enter in a STREET ADDRESS.<br>";
				$validapp = 0;
			}	
			
			if(empty($hphone)){
				echo "<b>Error!</b> You did not enter in a HOME PHONE NUMBER.<br>";
				$validapp = 0;
			}
			
			if(empty($city)){
				echo "<b>Error!</b> You did not enter in a CITY.<br>";
				$validapp = 0;
			}
			
			if(empty($homehill)){
				echo "<b>Error!</b> You did not enter in a HOME RESORT.<br>";
				$validapp = 0;
			}
			
			if(empty($essay)){
				echo "<b>Error!</b> You did not enter in an response to the question "Why do you wish to work for Midwestskier?" .<br>";
				$validapp = 0;
			}
			
			if(empty($comp)){
				echo "<b>Error!</b> You did not enter in information about COMPETITIONS you have been in.<br>";
				$validapp = 0;
			}
			
			if(empty($background)){
				echo "<b>Error!</b> You did not enter in your BACKGROUND/EXPERIENCE.<br>";
				$validapp = 0;
			}
			
			if(empty($contactime)){
				echo "<b>Error!</b> You did not enter in times when we may CONTACT you. This is very IMPORTANT!<br>";
				$validapp = 0;
			}
						
			// End form data validation
			
			if($validapp){
				echo"<font size=4 face=verdana>Application Form Review</font><br>
					<form name='userapply' method='post' action='$PHP_SELF?action=post'>
					<table>
						<tr>
							<td>First Name</td>
							<td>$firstname</td>
						</tr>
						<tr>
							<td>Last Name</td>
							<td>$lastname</td>
						</tr>
						<tr>
							<td>Your MS Forum Login</td>
							<td>$forum</td>
						</tr>
						<tr>
							<td>Birthday</td>
							<td>$birth_month/$birth_day/$birth_year</td>
						</tr>
						<tr>
							<td>Email Address</td>
							<td>$email</td>
						</tr>
						<tr>
							<td>Home Phone Number</td>
							<td>$hphone</td>
						</tr>
						<tr>
							<td>Cell Phone Number</td>
							<td>$cphone</td>
						</tr>
						<tr>
							<td>Home Address</td>
							<td>$streetadd</td>
						</tr>";
						if(empty($apt)){}else{ echo "
						<tr>
							<td>Apt Number</td>
							<td>$apt</td>
						</tr>"; } echo"
						<tr>
							<td>City</td>
							<td>$city</td>
						</tr>
						<tr>
							<td>State</td>
							<td>$state</td>
						</tr>
						<tr>
							<td>Zip Code</td>
							<td>$zip</td>
						</tr>
						<tr>
							<td>Home Resort</td>
							<td>$hills[$homehill], $hillst[$homehill]</td>
						</tr>
						<tr>
							<td>Secondary Resort</td>
							<td>";
							 if($homehill2=='0'){ echo "None";
							 }else{ 
							echo "$hills[$homehill2], $hillst[$homehill2]";
							 }
							echo "</td>
						</tr>
						<tr>
							<td>Years Skied</td>
							<td>$yearski</td>
						</tr>
						<tr>
							<td>Education</td>
							<td>$educate</td>
						</tr>						
						<tr>
							<td>Job Applying For</td>
							<td>$available_jobs[$jobapplied]</td>
						</tr>
						<tr>
							<td>Why do you wish to work for Midwestskier?</td>
							<td><textarea name='essay' rows='4' cols=50 wrap readonly>$essay</textarea></td>
						</tr>
						<tr>
							<td>Competitions History<br><font size=1 face=verdana>Brief overview (if any) of your history in competition, include top placing/s</font></td>
							<td><textarea name='comp' rows='4' cols=50 wrap readonly>$comp</textarea></td>
						</tr>
						<tr>
							<td>Work History<br><font size=1 face=verdana>include both ski and none skiing positions</font></td>
							<td><textarea name='work' rows='4' cols=50 wrap readonly>$work</textarea></td>
						</tr>
						<tr>
							<td>Background/Experience<br><font size=1 face=verdana>related to the position applied for</font></td>
							<td><textarea name='background' rows='4' cols=50 wrap readonly>$background</textarea></td>
						</tr>
						<tr>
							<td>Best Time to Contact<br><font size=1 face=verdana>and preferred method<br>(phone, email, AIM)</font></td>
							<td><textarea name='contactime' rows='4' cols=50 wrap readonly>$contactime</textarea></td>
						</tr>
						<tr>
							<td>Extra Comments<br><font size=1 face=verdana>Jokes, Web Sections desired (for web faculty), other positions to be reviewed for, height, anything else.</font></td>
							<td><textarea name='comments' rows='4' cols=50 wrap readonly>$comments</textarea>";
									addslashes($essay);
			addslashes($comp);
			addslashes($work);
			addslashes($background);
			addslashes($contactime);
			addslashes($comments);
						echo"
						<input type='hidden' name='firstname' value='$firstname'>
						<input type='hidden' name='lastname' value='$lastname'>
						<input type='hidden' name='forum' value='$forum'>
						<input type='hidden' name='birthday' value='$birth_year-$birth_month-$birth_day'>
						<input type='hidden' name='email' value='$email'>
						<input type='hidden' name='hphone' value='$hphone'>
						<input type='hidden' name='cphone' value='$cphone'>
						<input type='hidden' name='streetadd' value='$streetadd'>
						<input type='hidden' name='apt' value='$apt'>
						<input type='hidden' name='city' value='$city'>
						<input type='hidden' name='state' value='$state'>
						<input type='hidden' name='zip' value='$zip'>
						<input type='hidden' name='homehill' value='$homehill'>
						<input type='hidden' name='homehill2' value='$homehill2'>
						<input type='hidden' name='yearski' value='$yearski'>
						<input type='hidden' name='jobapplied' value='$jobapplied'>
						<input type='hidden' name='essay' value='$essay'>
						<input type='hidden' name='comp' value='$comp'>
						<input type='hidden' name='work' value='$work'>
						<input type='hidden' name='educate' value='$educate'>
						<input type='hidden' name='background' value='$background'>
						<input type='hidden' name='contactime' value='$contactime'>
						<input type='hidden' name='comments' value='$comments'>
							</td>
						</tr>
						<tr>
							<td colspan='2'>
								<div align='center'>
								  <a href="javascript:history.back()">Previous Page</a> | 
								  <input name='submit_app' type='submit' value='Submit Application'> | 
								  <input type='reset' name='_reload' value='Clear Forms'> | Page 4/5
								</div>
							</td>
						</tr>
					</table>";
			}
			break;
			
			case "post":
			echo($valid_post);
					$addapp = "INSERT INTO staff_apply (firstname, lastname, forum, birthday, email, hphone, cphone, streetadd, apt, city, state, zip, homehill, homehill2, yearski, jobapplied, essay, comp, work, educate, background, contactime, comments) 
								 VALUES ('$firstname', '$lastname', '$forum', '$birthday', '$email', '$hphone', '$cphone', '$streetadd', '$apt', '$city', '$state', '$zip', '$homehill', '$homehill2', '$yearski', '$jobapplied', '$essay', '$comp', '$work', '$educate', '$background', '$contactime', '$comments')";
					$result = mysql_query($addapp, $connection) or die("Insert New Application Error - <b>Error Code 1</b>");
				if($result){
					echo "<font size=4 face=verdana>Application Submission Successful</font><br>
					Thank you for your interest in MidwestSkier.com and Cow Tipping Productions, LLC., and we are pleased to let you know that your application has successfully been received. <p>
					This process will run until August 16th, 2003 and you will be informed about or decision by the 23rd of August, 2003. Again thank you for your interest and support. <br>
					-MidwestSkier.com Staff
					<p align=center><a href=index.php>Return to MidwestSkier.com</a> | Page 5/5";
				}
			break;
	} //ending switch($action)
} //ending if($action_)

?>
Post Reply