Jump to content

[SOLVED] No Errors but Data not Submitting???


cmaclennan

Recommended Posts

Hey Guys,

 

I have a form that at one time was submitting to a database as it should and for some reason it is submitting ok and not giving any kind of errors yet the data isnt ending up in the table?? What could i be missing? when I echo out the statement to see if the data is being posted by the script everything shows up normal but it's not getting entered.

 

Thanks for your help

Link to comment
Share on other sites

Sorry one other thing i have just noticed the form submits to 2 tables and the data is going into the second table ok but not the first, below is the query.

 

// Make the query.		
	$query = "INSERT INTO rma (rma_id, date, store_company, address, address2, city, state_prov, zip_postal, country, phone, ext, contact) VALUES ('$ri', '$dt', '$co', '$ad' , '$ad2', '$ct', '$sp', '$zp', '$cou', '$ph', '$ex', '$cn')";
	$result = @mysql_query ($query); // Run the query.
	$rma_id = mysql_insert_id();

	$result = @mysql_query ($query); // Run the query.
	foreach($_POST as $key => $value)
{
	//looping through all posted fields
	if(strpos($key, 'item_') !== false)
	{
		//found a part field, need to find out the _x number, then insert the entire row
		$suffix = substr($key, -1); //this gets the _x number
		$item = $_POST['item_' . $suffix];
		$description = $_POST['description_' . $suffix];
		$qty = $_POST['qty_' . $suffix];
		$serial = $_POST['serial_' . $suffix];
		$mfg = $_POST['mfg_' . $suffix];
		$tariff = $_POST['tariff_' . $suffix];
		$value = $_POST['value_' . $suffix];

		$query = "INSERT INTO rma_parts (item, description, qty, serial, mfg, tariff, value, rma_id) VALUES ('$item', '$description', '$qty', '$serial', '$mfg', '$tariff', '$value', '$rma_id')";
		$result = mysql_query($query);
	}
}
	if ($result) { // If it ran OK.

		// Send an email, if desired.

		// Print a message.
		echo '<h1 id="mainhead">Thank you!</h1>
	<p>Your entry has now been registered.</p><p><br /></p>';	

		// Include the footer and quit the script (to not show the form).

		exit();

	} else { // If it did not run OK.
		echo '<h1 id="mainhead">System Error</h1>
		<p class="error">Your entry could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Public message.
		echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message.

		exit();
	}

	mysql_close(); // Close the database connection.

} else { // Report the errors.

	echo '<h1>Error!</h1>
	<p class="error">The following error(s) occurred:<br />';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p><p><br /></p>';

} // End of if (empty($errors)) IF.

} // End of the main Submit conditional.

Link to comment
Share on other sites

And remove the @ in front of the mysql_query() statements. If you are getting a php error generated on a mysql_query() statement, it means that your database connection is not present and you should never get to the point of executing a mysql_query() statement. What php errors where you getting before you put the @ in the code?

Link to comment
Share on other sites

This is the same query structure as i am using succesfully on a number of other forms, I have just noticed that when i try to enter the query directly in the database it seems to think it's creating a duplicate entry for the primary key and won't allow it to go in.

Link to comment
Share on other sites

Gah... that's not what I meant.

 

First of all, mysql_insert_id isn't a tag, whatever that means. It's a function.

 

Anyways, the point is you ran the same query twice. Forget about mysql_insert_id(). If you looked at the code, you will see you ran the same query twice. Why would you run it twice? That's the error you described. You're inserting rma_id twice, which caused a duplicate conflict because I'm guessing it's a PK. Though, you never really need to insert anything into a PK column.

 

And don't remove the mysql_insert_id() line either because you'll need it in your second query.

Link to comment
Share on other sites

Ok I removed the second submit of the query as you described not the mysql_insert_id () so it is not submitting twice however I am still having the same problem, and the only reason I have anything in the rma_id field is a function to generate a unique id number as opposed to just auto incrementing a basic number.

Link to comment
Share on other sites

Still not getting any error as at all and here is the code for the queries again, if you would like me to post the page just let me know.

 

// Make the query.		
	$query = "INSERT INTO rma (rma_id, date, store_company, address, address2, city, state_prov, zip_postal, country, phone, ext, contact) VALUES ('$ri', '$dt', '$co', '$ad' , '$ad2', '$ct', '$sp', '$zp', '$cou', '$ph', '$ex', '$cn')";
	$result = mysql_query ($query); // Run the query.
	$rma_id = mysql_insert_id();

	foreach($_POST as $key => $value)
{
	//looping through all posted fields
	if(strpos($key, 'item_') !== false)
	{
		//found a part field, need to find out the _x number, then insert the entire row
		$suffix = substr($key, -1); //this gets the _x number
		$item = $_POST['item_' . $suffix];
		$description = $_POST['description_' . $suffix];
		$qty = $_POST['qty_' . $suffix];
		$serial = $_POST['serial_' . $suffix];
		$mfg = $_POST['mfg_' . $suffix];
		$tariff = $_POST['tariff_' . $suffix];
		$value = $_POST['value_' . $suffix];

		$query = "INSERT INTO rma_parts (item, description, qty, serial, mfg, tariff, value, rma_id) VALUES ('$item', '$description', '$qty', '$serial', '$mfg', '$tariff', '$value', '$rma_id')";
		$result = mysql_query($query);
	}
}
	if ($result) { // If it ran OK.

		// Send an email, if desired.

		// Print a message.
		echo '<h1 id="mainhead">Thank you!</h1>
	<p>Your entry has now been registered.</p><p><br /></p>';	

		// Include the footer and quit the script (to not show the form).

		exit();

	} else { // If it did not run OK.
		echo '<h1 id="mainhead">System Error</h1>
		<p class="error">Your entry could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Public message.
		echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message.

		exit();
	}

	mysql_close(); // Close the database connection.

} else { // Report the errors.

	echo '<h1>Error!</h1>
	<p class="error">The following error(s) occurred:<br />';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p><p><br /></p>';

} // End of if (empty($errors)) IF.

} // End of the main Submit conditional.

Link to comment
Share on other sites

it would appear as though when i submit the form it's not creating a unique id for rma_id as i intended and it's trying to enter the same one over and over again which is not allowing it to submit to the first table but i have no idea why its doing that?

Link to comment
Share on other sites

Ok so i've now even removed anything that would enter anything into the rma_id field in hopes of just allowing it to auto incremement and it still will not go into that table, im at a loss as to what's going on here and what i should do as the next step?

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.