MYSQL + UPDATE RECORDS
Posted: Tue Jul 07, 2009 1:25 am
Okay so I'm writing a little script to update rows of a database.
I am able to update the records but ONLY with numbers. It is not allowing me to update with alpha chars, and this has nothing to do with MYSQL as far as I know. All of my fields are set properly ie: category is VARCHAR.
I am able to update the records but ONLY with numbers. It is not allowing me to update with alpha chars, and this has nothing to do with MYSQL as far as I know. All of my fields are set properly ie: category is VARCHAR.
Code: Select all
<?php
// Suppress all errors
error_reporting(0);
// Set all variables
$update = $_POST['update'];
$hostname = "mysqlhost";
$username = "xxxxxxxxxx";
$password = "xxxxxxxxxx";
$dbid="xxxxxxxxx";
// Attempt database connection
$connect = mysql_connect($hostname, $username, $password);
if($connect == false){
echo('<p class="error">We are having technical difficulties and apologize for the inconvenience. Please try again later.</p>');
}
// Select database
$db = mysql_select_db($dbid);
// Query the database
$select = "SELECT * FROM parts where id = ".$id."";
$result = mysql_query($select);
while($row = mysql_fetch_array($result)){
extract($row);
// do a whole bunch of nothing!
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="update" value="true" />
<label for="category">ID:</label>
<input type="text" name="id" id="id" value="<?php echo $id; ?>" readonly="readonly" />
<label for="category">Category:</label>
<input type="text" name="category" id="category" value="<?php echo $category; ?>" />
<label for="price">Price:</label>
<input type="text" name="price" id="price" value="<?php echo $price; ?>"/>
<label for="datein">Date In:</label>
<input type="text" name="datein" id="datein" value="<?php echo $datein; ?>" />
<label for="quantity">Quantity:</label>
<input type="text" name="quantity" id="quantity" value="<?php echo $quantity; ?>" />
<label for="image">Image:</label>
<input type="text" name="image" id="image" value="<?php echo $image; ?>"/>
<label for="description">Description:</label>
<textarea rows="5" name="description" cols="50" id="description"><?php echo $description; ?></textarea>
<br />
<button type="submit">Update</button>
</form>
<?php
// If user is trying to edit part...
if ($update == true) {
// wtf?
$category = $_POST['category'];
$price = $_POST['price'];
$datein = $_POST['datein'];
$quantity = $_POST['quantity'];
$image = $_POST['image'];
$description = $_POST['description'];
// Build query
$insert = "UPDATE parts SET category = ".$_POST['category']." WHERE id = ".$id."";
$result = mysql_query($insert);
if ($result == true) {
echo '<p class="success">Update complete.</p>';
} else {
echo '<p class="error">There was a problem editing this part.</p>';
}
}
?>
</body>
</html>