PHp will not parse correctly and does not connect to Xampp database

First forgive me if the code is not in an organized manner, I have tried to insert code in a neat manner but by the time I fix it, the system times out, so I cant post and have to do it all over again…so this time I am not going to adjust the code… just copy past it into forum

I created a from called product_insert.html… and a php script called product_insert.php. They are both located in a sub folder called Final exam, in the htdoc folder of xampp.

After entering data into form, the next screen basically shows me the script of the product_insert.php. I cannot figure out why it does not make the connection. Also the database is called final_exam.

product_insert.php

[php]<?php
	$host = "localhost"; // change this as required
	$username = "root"; // change this as required
	$password = "password"; // change this as required
	$db = "final_exam"; // your DB  

		$DBConnect=mysql_connect("localhost", "root", "password") 
			or die("Could Not Connect");
		//echo "We have successfully connect to our DB.<br/>";
	
		mysql_select_db( "final_exam")
			or die(mysql_error());
		//echo "Successfully opened DB.<br/>";
	
		//pull values from the URL and put them each in a variable
		$Description = addslashes($_GET["Description"]);
		$Quantity = addslashes($_GET["Quantity"]);
		$Price = addslashes($_GET["Price"]);
		$Vend_id = addslashes($_GET["Vend_id"]);
		
		if($Description && $Quantity && $Price && $Vend_id)
		{
			echo "test1";
			
		}
		else
		{
			echo "test2";
		}
		
		if(isset($Description) && !empty($Description) 
			&& isset($Quantity) && !empty($Quantity)
			&& isset($Price) && !empty($Price)
			&& isset($Vend_id) && !empty($Vend_id))
		{			
			$SQLstring = "INSERT INTO student (id, first_name,last_name,address, e_mail, gpa)
				VALUES ('$Description', '$Quantity', '$Price', '$Vend_id')";
				
			$QueryResult = @mysql_query($DBConnect, $SQLstring)
				Or die("Insert Broke!!!");
				
			echo "insert complete";
		}	
		else
		{
			echo "You are missing some values...Please press the back button and retry!";
		}
		//redirect back to our list page since the insert worked
		header("location: product_list.php");		
		
	?>[/php]
	
	<a a href="product_insert.html">Click here</a> to go back to the list!-->
</body>

Do you have php installed? and do you have the server online? html pages don’t need a server to view them, but php/mysql pages need a php handler. Make sure php/mysql is installed and the xamp server is online (i think u just right click on the server icon by the clock to turn it on).

All is on… this is what I get as output when I click on the creat button from the html from page…

"; @mysqli_select_db( “final_exam”) or die(mysqli_error()); //echo "Successfully opened DB.
"; //pull values from the URL and put them each in a variable $Description = addslashes($_GET[“Description”]); $Quantity = addslashes($_GET[“Quantity”]); $Price = addslashes($_GET[“Price”]); $Vend_id = addslashes($_GET[“Vend_id”]); if($Description && $Quantity && $Price && $Vend_id) { echo “test1”; } else { echo “test2”; } /*if(isset($Description) && !empty($Description) && isset($Quantity) && !empty($Quantity) && isset($Price) && !empty($Price) && isset($Vend_id) && !empty($Vend_id)) { $SQLstring = “INSERT INTO product (vend_id, Quantity, Price, Vend_id) VALUES (’$Description’, ‘$Quantity’, ‘$Price’, ‘$Vend_id’)”; $QueryResult = @mysql_query($DBConnect, $SQLstring) Or die(“Insert Broke!!!”); echo “insert complete”; } else { echo “You are missing some values…Please press the back button and retry!”; } //redirect back to our list page since the insert worked header(“location: product_list.php”); */ ?> Click here to go back to the list!–>

Sponsor our Newsletter | Privacy Policy | Terms of Service