Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

Dougless on "PHP - Data to MySQL, through form - Newbie needs help"

$
0
0

Hi community.

I am working on developing my PHP skills while developing my WordPress site.

I did run into an issue when trying to get data into my MySQL database.

It has been working previously, but when i change table it does not seem to push data into my rows. Do anybody see or know why?

add_shortcode('map_location_report','map_location_report_form');

	function map_location_report_form()
	{
  		global $wpdb;

	  	$this_page  =  	$_SERVER['REQUEST_URI'];
	  	$page     	=   $_POST['page'];

		if ( $page == NULL )
		{
			echo '<form method="post" action="' . $this_page .'">

				  	<div class="formfield-report" id="formfield-report-firstname">
					  	<label for="first_name" id="first_name">Navn: </label>
						<input type="text" name="first_name" id="first_name" />
					</div>

					<div class="formfield-report" id="formfield-report-lastname">
						<label for="last_name" id="last_name">Efternavn: </label>
						<input type="text" name="last_name" id="last_name" />
					</div>

					<div class="formfield-report" id="formfield-report-locationtype">
					  	<label for="location_type" id="location_type">Rapport type: </label>
				  		<select name="location_type" />
							<option value="sigtmelding" selected>Sigtmelding</option>
							<option value="fangstrapport">Fangstrapport</option>
							<option value="jagtomraade">Jagtområde</option>
						</select>
					</div>

					<div class="formfield-report" id="formfield-report-latitude">
						<label for="location_latitude" id="location_latitude">Breddegrad: </label>
						<input type="text" name="location_latitude" id="location_latitude" />
					</div>

					<div class="formfield-report" id="formfield-report-longitude">
				  		<label for="location_longitude" id="location_longitude">Længdegrad: </label>
				  		<input type="text" name="location_longitude" id="location_longitude" />
			  		</div>

					<input type="hidden" value="1" name="page" />

					<div id="formfield-report-button">
						<input class="btn btn-default submit-form-button" type="Submit" />
					</div>

		  	</form>';
	  	}
		elseif ( $page == 1 )
		{
		  	$first_name   			=   $_POST['first_name'];
	  		$last_name    			=   $_POST['last_name'];
		  	$location_type			=	$_POST['location_type'];
		  	$location_latitude		=	$_POST['location_latitude'];
			$location_longitude		=	$_POST['location_longitude'];

	  		$page_one_table = 'maplocationreports';

	  		$page_one_inputs =  array
	  		(
		  		'first_name' 			=> $first_name,
		  		'last_name' 			=> $last_name,
	  			'location_type'			=> $location_type,
	  			'location_latitude'		=> $location_latitude,
				'location_longitude'	=> $location_longitude,
	  			'page' 					=> $page
		  	);

	  		$insert_page_one = $wpdb->insert($page_one_table, $page_one_inputs);

			echo '<h3>Mange tak for dit bidrag!</h3>';
			echo '<p>Der er sat stor pris på at du har taget dig tid til at registrere et punkt på kortet!</p>';

		}
  	};

Database has been created using following SQL:

CREATE TABLEmaplocationreports` (
id INT( 7 ) NOT NULL AUTO_INCREMENT,
first_name VARCHAR( 50 ) NOT NULL,
last_name VARCHAR( 50 ) NOT NULL,
report_type VARCHAR( 20 ) NOT NULL,
location_latitude VARCHAR( 12 ) NOT NULL,
location_longitude VARCHAR( 12 ) NOT NULL,
page INT( 1 ) NOT NULL,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ( id )
)`

Please let me know if you see any syntax errors or other mistakes.

Thank you in advance!


Viewing all articles
Browse latest Browse all 5527

Trending Articles