Jump to content

[SOLVED] PHP MySQL Help


cmaclennan

Recommended Posts

Hi Guys,

 

I'm new here and am really hoping someone can offer me a bit of assistance as I'm not sure what I'm missing. I am/have created a page for my company to log serial numbers of our products before they are sent out, I have thus far been able to create the form have it submit to the database and when the values contain only numbers I am able to search them and edit them as necessary, however when the values contain a letter and number combination I can search but am not able to edit anything. The error I believe or would assume is on the edit page?? Below is the code from the edit page, really hoping someone can help I'm kind of running out of time/patience at this point.

 

<?php 

$page_title = 'Edit a node';
include ('style.html');

// Check for a valid Node ID, through GET or POST.
if ( (isset($_GET['id'])) ) { // Accessed through active_search.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) ) { // Form has been submitted.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<div id="title">Page Error</div>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; 
exit();
}

require_once ('mysql_connect.php'); // Connect to the db.

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

$errors = array(); // Initialize error array.

// Check for a Master Serial.
if (empty($_POST['master_serial'])) {
	$errors[] = 'You forgot to enter the Master Serial.';
} else {
	$ms = trim($_POST['master_serial']);
}

// Check for a Charger Serial.
if (empty($_POST['charger'])) {
	$errors[] = 'You forgot to enter the Charger Serial.';
} else {
	$ch = trim($_POST['charger']);
}

// Check for a Battery Serial.
if (empty($_POST['battery'])) {
	$errors[] = 'You forgot to enter the Battery Serial.';
} else {
	$bt = trim($_POST['battery']);
}

// Trim address2
#{
#	$ad2 = trim($_POST['address2']);
#}

// Check for a ABC Serial.
if (empty($_POST['abc'])) {
	$errors[] = 'You forgot to enter the ABC Serial.';
} else {
	$abc = trim($_POST['abc']);
}

// Check for a DC Serial.
if (empty($_POST['dc1'])) {
	$errors[] = 'You forgot to enter the 1st DC Serial.';
} else {
	$dc1 = trim($_POST['dc1']);
}

// Check for a 2nd DC Serial.
if (empty($_POST['dc2'])) {
	$errors[] = 'You forgot to enter the 2nd DC Serial.';
} else {
	$dc2 = trim($_POST['dc2']);
}

// Check for a Radio Serial.
if (empty($_POST['radio'])) {
	$errors[] = 'You forgot to enter a Radio Serial.';
} else {
	$rd = trim($_POST['radio']);
}

// Check for a Network Serial.
if (empty($_POST['network'])) {
	$errors[] = 'You forgot to enter the Network Serial.';
} else {
	$nt = trim($_POST['network']);
}

// Check for a SR2-1.
if (empty($_POST['sr2_1'])) {
	$errors[] = 'You forgot to enter the SR2-1 Serial.';
} else {
	$sr2 = trim($_POST['sr2_1']);
}

	// Check for a SR2-2.
if (empty($_POST['sr2_2'])) {
	$errors[] = 'You forgot to enter the SR2-2 Serial.';
} else {
	$sr21 = trim($_POST['sr2_2']);
}

	// Check for a SR5-1.
if (empty($_POST['sr5_1'])) {
	$errors[] = 'You forgot to enter the SR5-1 Serial.';
} else {
	$sr5 = trim($_POST['sr5_1']);
}

	// Check for a SR5-2.
if (empty($_POST['sr5_2'])) {
	$errors[] = 'You forgot to enter the SR5-2 Serial.';
} else {
	$sr51 = trim($_POST['sr5_2']);
}

	// Check for a Ethernet.
if (empty($_POST['ethernet'])) {
	$errors[] = 'You forgot to enter the Ethernet Serial.';
} else {
	$et = trim($_POST['ethernet']);
}

if (empty($errors)) { // If everything's OK.

	//  Test for unique master serial.
	$query = "SELECT master_serial FROM activecontrol WHERE master_serial=$id";
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 0) {

		// Make the query.
		$query = "UPDATE activecontrol SET master_serial='$ms', charger='$ch', battery='$bt', abc='$abc', dc1='$dc1', dc2='$dc2', radio='$rd', network='$nt', sr2_1='$sr2', sr2_2='$sr21', sr5_1='$sr5', sr5_2='$sr51', ethernet='$et' WHERE master_serial=$id";
		$result = @mysql_query ($query); // Run the query.
		if (mysql_affected_rows() == 1) { // If it ran OK.

			// Print a message.
			echo '<div id="title">Success!</div>
			<p>The node has been edited.</p><p><br /><br /></p>';	

		} else { // If it did not run OK.
			echo '<div id="title">System Error</div>
			<p class="error">The node could not be edited 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();
		}

	} else { // Already registered.
		echo '<div id="title">Error!</div>
		<p class="error">The Serial has already been registered.</p>';
	}

} else { // Report the errors.

	echo '<div id="title">Error!</div>
	<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 submit conditional.

// Always show the form.

// Retrieve the node's information.
$query = "SELECT master_serial, charger, battery, abc, dc1, dc2, radio, network, sr2_1, sr2_2, sr5_1, sr5_2, ethernet FROM activecontrol WHERE master_serial=$id";		
$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { // Valid node ID, show the form.

// Get the user's information.
$row = mysql_fetch_array ($result, MYSQL_NUM);

// Create the form.
echo '<div id="title">Edit a Node</div>
<form action="active_edit.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Master Serial:</td><td><input type="text" name="master_serial" size="15" maxlength="15" value="' . $row[0] . '" /></td>
</tr>
<tr>
<td>Charger:</td><td><input type="text" name="charger" size="15" maxlength="30" value="' . $row[1] . '" /></td>
</tr>
<tr>
<td>Battery:</td><td><input type="text" name="battery" size="20" maxlength="40" value="' . $row[2] . '"  /> </td>
</tr>
<tr>
<td>ABC:</td><td><input type="text" name="abc" size="20" maxlength="40" value="' . $row[3] . '"  /> </td>
</tr>
<tr>
<td>DC 1:</td><td><input type="text" name="dc1" size="20" maxlength="40" value="' . $row[4] . '"  /> </td>
</tr>
<tr>
<td>DC 2:</td><td><input type="text" name="dc2" size="20" maxlength="40" value="' . $row[5] . '"  /> </td>
</tr>
<tr>
<td>Radio:</td><td><input type="text" name="radio" size="20" maxlength="40" value="' . $row[6] . '"  /> </td>
</tr>
<tr>
<td>Network:</td><td><input type="text" name="network" size="20" maxlength="40" value="' . $row[7] . '"  /> </td>
</tr>
<tr>
<td>SR2-1:</td><td><input type="text" name="sr2_1" size="20" maxlength="40" value="' . $row[8] . '"  /> </td>
</tr>
<tr>
<td>SR2-2:</td><td><input type="text" name="sr2_2" size="20" maxlength="40" value="' . $row[9] . '"  /> </td>
</tr>
<tr>
<td>SR5-1:</td><td><input type="text" name="sr5_1" size="20" maxlength="40" value="' . $row[10] . '"  /> </td>
</tr>
<tr>
<td>SR5-2:</td><td><input type="text" name="sr5_2" size="20" maxlength="40" value="' . $row[11] . '"  /> </td>
</tr>
<tr>
<td>Ethernet:</td><td><input type="text" name="ethernet" size="20" maxlength="40" value="' . $row[12] . '"  /> </td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" /><input type="hidden" name="submitted" value="TRUE" /></td>
<td><input type="hidden" name="id" value="' . $id . '" /></td></tr>
</form>';

} else { // Not a valid user ID.
echo '<div id="title">Page Error</div>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
}

mysql_close(); // Close the database connection.

?>

 

Thanks in advance for any help.

C

Link to comment
Share on other sites

$query = "SELECT master_serial, charger, battery, abc, dc1, dc2, radio, network, sr2_1, sr2_2, sr5_1, sr5_2, ethernet FROM activecontrol WHERE master_serial='$id'";  

 

When it contains a number and character, it is a string.  Strings have to be surrounded by quotes.

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.