Jump to content

Form entry issue - Adding record to mysql database


paulbray

Recommended Posts

I am trying to set up a item entry page form.png:thumb_17734.png

 

Upon submission it shows unsuccessful even though I have checked the fields on mysql table and seem to be good am I missing something?

 

<form action="" method="post" enctype="multipart/form-data" name="Product_Entry">
<TABLE>
<TR>
<TD>Product ID</TD><TD><input name="SKU_ProductID" value="<?php if (isset($_post['SKU_ProductID'])) echo $_POST['SKU_ProductID']; ?>" type="text" size="11" maxlength="11" /></TD>
</TR>
<TR>
<TD>Merchant SKU ID</TD><TD><input name="SKU_MerchSKUID" value="<?php if (isset($_post['SKU_MerchSKUID'])) echo $_POST['SKU_MerchSKUID']; ?>" type="text" size="18" maxlength="30" /></TD>
</TR>
<TR>
<TD>Game Title</TD><TD><input name="Game_Title" value="<?php if (isset($_post['Game_Title'])) echo $_POST['Game_Title']; ?>" type="text" size="40" maxlength="40" /></TD>
</TR>
<TR>
<TD>Platform</TD><TD><input name="Platform" value="<?php if (isset($_post['Platform'])) echo $_POST['Platform']; ?>" type="text" size="20" maxlength="20" /></TD>
</TR>
<TR>
<TD>Genre</TD><TD><input name="Genre" value="<?php if (isset($_post['Genre'])) echo $_POST['Genre']; ?>" type="text" size="11" maxlength="11" /></TD>
</TR>
<TR>
<TD>Weight</TD><TD><input name="Weight" value="<?php if (isset($_post['Weight'])) echo $_POST['Weight']; ?>" type="text" size="7" maxlength="7" /></TD>
</TR>
<TR>
<TD>Supplier</TD><TD><input name="Supplier" Value="<?php if (isset($_post['Supplier'])) echo $_POST['Supplier']; ?>" type="text" size="25" maxlength="25" /></TD>
</TR>
<TR>
<TD>Suppliers Price</TD><TD><input name="Supplier_Price" value="<?php if (isset($_post['Supplier_Price'])) echo $_POST['Supplier_Price']; ?>" type="text" size="10" maxlength="12" /></TD>
</TR>
<TR>
<TD>Cashback</TD><TD><input name="Cashback" value="<?php if (isset($_post['Cashback'])) echo $_POST['Cashback']; ?>" type="text" size="6" maxlength="8" /></TD>
</TR>
<TR>
<TD>Cashback Amount</TD><TD><input name="Cashback_Amount" value="<?php if (isset($_post['Cashback_Amount'])) echo $_POST['Cashback_Amount']; ?>" type="text" size="7" maxlength="11" /></TD>
</TR>
<TR>
<TD><input type="hidden" name="submitted" value="true"/></TD><TD><input name="Submit" type="submit" value="Add_Product" /></TD>
</TR></form></TABLE>

<?php # Product Entry

$page_title = 'Product Entry';

if (isset($_POST['Submit'])) {

$errors = array();

if (empty($_POST['SKU_ProductID'])) {
	$errors[] = 'Please enter Product ID.';
} else {
	$sid = trim($_POST['SKU_ProductID']);
}

if (empty($_POST['SKU_MerchSKUID'])) {
	$errors[] = 'Please enter Merchant SKU.';
} else {
	$mid = trim($_POST['SKU_MerchSKUID']);
}

if (empty($_POST['Game_Title'])) {
	$errors[] = 'Please enter Game Title.';
} else {
	$gt = trim($_POST['Game_Title']);
}

if (empty($_POST['Platform'])) {
	$errors[] = 'Please enter Platform.';
} else {
	$pl = trim($_POST['Platform']);
}

if (empty($_POST['Genre'])) {
	$errors[] = 'Please enter Genre.';
} else {
	$ge = trim($_POST['Genre']);
}

if (empty($_POST['Weight'])) {
	$errors[] = 'Please enter Weight.';
} else {
	$we = trim($_POST['Weight']);
}

if (empty($_POST['Supplier'])) {
	$errors[] = 'Please enter Supplier.';
} else {
	$sup = trim($_POST['Supplier']);
}

if (empty($_POST['Supplier_Price'])) {
	$errors[] = 'Please enter Supplier Price.';
} else {
	$sp = trim($_POST['Supplier_Price']);
}

if (empty($_POST['Cashback'])) {
	$errors[] = 'Please enter Cashback %.';
} else {
	$cb = trim($_POST['Cashback']);
}

if (empty($_POST['Cashback_Amount'])) {
	$errors[] = 'Please enter Cashback Amount.';
} else {
	$cba = trim($_POST['Cashback_Amount']);
}

if (empty($errors)) {

	require_once ('connect.php');

	[b]$q = "INSERT INTO `Products` (`SKU_ProductID`, `SKU_MerchSKUID`, `Game_Title`, `Platform`, `Genre`, `Weight`, `Supplier`, `Supplier_Price`, `Cashback`, `Cashback_Amount`) VALUES ('$sid', '$mid', '$gt', '$pl', '$ge', '$we', '$sup', '$sp', '$cb', '$cba')";
	$r = @mysql_query ($dbc, $q);

	if ($r) { // If it ran OK.

		// Print a message:
		echo '<h1>Thank you!</h1>
	<p>Product Inserted!</p><p><br /></p>';	

	} else { // If it did not run OK.

		// Public message:
		echo '<h1>System Error</h1>
		<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; 

		// Debugging message:
		echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';

	} // End of if ($r) IF.

	mysqli_close($dbc); // Close the database connection.[/b]		
	// Include the footer and quit the script:
	include ('includes/footer.html'); 
	exit();

} else {

	echo '<H1>Error!</H1>
	<p class="error">The Following error(s) occurred:<br />';

	foreach ($errors as $msg) {	

		echo " - $msg<br />\n";
	}

	echo '</p><p>Please try again.</p><p><br /></p>';

}

}

?>

 

If there is anything else needed let me know

Link to comment
Share on other sites

$_post and $_POST are not the same things. It should be $_POST (in your isset() statements in the form.)

 

The @ you put in front of the mysql_query() statement was probably to hide some errors due to what kickstart mentioned - mixing mysql and mysqli and trying to use the mysqli parameter order in the mysql_query statement.

Link to comment
Share on other sites

@kickstart,

 

He's got a thread that he started after this one where the code is using mysqli_query, but he didn't bother to come back to this thread to mention that the problems in it were corrected, mark it solved, or to more simply just continue with this thread for the same code. I also see that he has a thread prior to this one for the same code, but for a syntax error.

 

Edit: I marked this thread and the previous one as solved to prevent anyone from wasting time replying in them.

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.