I dont know what I am missing. I am trying to update my database but it shows that the variable is not being passed on.
What I see when I echo the $query
UPDATE `new_equip` SET `itemname`='',`manufacture`='',`model`='' 'WHERE `id`='0' LIMIT 1
Here is my EditPost.php (stripped to save room)
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$insert_data = mysql_real_escape_string($input_data);
$id= intval($_POST['EditID']);
$itemname= mysql_real_escape_string($_POST['itemname']);
$manufacture= mysql_real_escape_string($_POST['manufacture']);
$model= mysql_real_escape_string($_POST['model']);
$query = "UPDATE `new_equip` SET `itemname`='$itemname',`manufacture`='$manufacture',`model`='$model'" . $UF . "WHERE `id`='$id' LIMIT 1";
and my edit-item.php
<form method="post" action="EditPost.php" enctype="multipart/form-data" class="form-horizontal" accept-charset="UTF-8">
<div class="form-group">
<label class="col-md-3">Item ID</label>
<div class="col-md-8">
<input type="text" name="EditID" value="<?php echo $row['id']; ?>" class="form-control" />
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Item Name</label>
<div class="col-md-8">
<input type="text" name="itemname" value="<?php echo $row['itemname']; ?>" class="form-control" />
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Manufacture</label>
<div class="col-md-8">
<input type="text" name="manufacture" value="<?php echo $row['manufacture']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showmanu" id="showmanu">
<option value="1"<?php if ($row['showmanu'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showmanu'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
Also, I know mysql is being depreciated and I slowly converting my site over, I just need this to work while I get it all switched.
Echo out each variable before your insert statement. Let me know what is being echod.
If that all echos out correctly then we can deduce it to the insert statement (then you can run phpmyadmin query and just manually try inserting the values in without the variables to even further reduce the issues.
Do you have error reporting on? Any errors in your log file? Warnings?
when I add
echo $id;
echo $itemname;
echo $manufacture;
It shows 0’s (zeros)
Also, I added this
if (!mysql_error()) print 'all is fine';
but it is coming back “all is fine”
Are you sure your data being inputted is right? What are you passing through the $_POST form?
Here is my entire code
edit-item.php
<?php
$SQL_GetProduct = "SELECT * FROM `new_equip` WHERE id='$eid' LIMIT 1";
$row = mysql_fetch_assoc(mysql_query($SQL_GetProduct, $Link));
$condition = $row['condition'];
$featured = $row['featured'];
$showmanu = $row['showmanu'];
$showmodel = $row['showmodel'];
$showserial = $row['showserial'];
$showyear = $row['showyear'];
$showdem = $row['showdem'];
$showelec = $row['showelec'];
$showran = $row['showran'];
$showloca = $row['showloca'];
$showown = $row['showown'];
$showpur = $row['showpur'];
$showsale = $row['showsale'];
?>
<hr />
<br />
<form method="post" action="EditPost.php" enctype="multipart/form-data" class="form-horizontal" accept-charset="UTF-8">
<div class="form-group">
<label class="col-md-3">Item ID</label>
<div class="col-md-8">
<input type="text" name="eid" value="<?php echo $row['id']; ?>" class="form-control" />
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Item Name</label>
<div class="col-md-8">
<input type="text" name="itemname" value="<?php echo $row['itemname']; ?>" class="form-control" />
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Manufacture</label>
<div class="col-md-8">
<input type="text" name="manufacture" value="<?php echo $row['manufacture']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showmanu" id="showmanu">
<option value="1"<?php if ($row['showmanu'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showmanu'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Model</label>
<div class="col-md-8">
<input type="text" name="model" value="<?php echo $row['model']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showmodel" id="showmodel">
<option value="1"<?php if ($row['showmodel'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showmodel'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Serial</label>
<div class="col-md-8">
<input type="text" name="serial" value="<?php echo $row['serial']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showserial" id="showserial">
<option value="1"<?php if ($row['showserial'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showserial'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Year</label>
<div class="col-md-8">
<input type="text" name="year" value="<?php echo $row['year']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showyear" id="showyear">
<option value="1"<?php if ($row['showyear'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showyear'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Category</label>
<div class="col-md-8">
<select name="category" id="category">
<option value="">Choose Category</option>
<option value=""></option>
<option value="">NEW ITEMS</option>
<option value="">----------</option>
<option value="BulkDealletizers" <?php if ($row['category'] == 'BulkDealletizers') echo 'selected = "selected"'; ?>>Bulk Depalletizers</option>
<option value=""></option>
<option value="">USED ITEMS</option>
<option value="">----------</option>
<option value="Bins"<?php if ($row['category'] == 'Bins') echo 'selected = "selected"'; ?>>Bins</option>
<option value="Cappers"<?php if ($row['category'] == 'Cappers') echo 'selected = "selected"'; ?>>Cappers</option>
</select>
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Condition</label>
<div class="col-md-8">
<select name="condition">
<option value="New"<?php if ($row['condition'] == 'New') echo 'selected = "selected"'; ?>>New</option>
<option value="LikeNew"<?php if ($row['condition'] == 'LikeNew') echo 'selected = "selected"'; ?>>Like New</option>
<option value="Excellent"<?php if ($row['condition'] == 'Excellent') echo 'selected = "selected"'; ?>>Excellent</option>
<option value="VeryGood"<?php if ($row['condition'] == 'VeryGood') echo 'selected = "selected"'; ?>>Very Good</option>
<option value="Good"<?php if ($row['condition'] == 'Good') echo 'selected = "selected"'; ?>>Good</option>
<option value="Fair"<?php if ($row['condition'] == 'Fair') echo 'selected = "selected"'; ?>>Fair</option>
<option value="Rough"<?php if ($row['condition'] == 'Rough') echo 'selected = "selected"'; ?>>Rough</option>
</select>
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Description</label>
<div class="col-md-8">
<textarea class="my_tiny" name="desc" rows="10" cols="55" wrap="physical" value="" type="text" id="about-textarea"><?php echo $row['desc']; ?></textarea>
<script>
tinyMCE.get('my_tiny').setContent(<?php echo $desc; ?>);
</script>
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Dimensions</label>
<div class="col-md-8">
<input type="text" name="dimensions" value="<?php echo $row['dimensions']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showdem" id="showdem">
<option value="1"<?php if ($row['showdem'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showdem'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Previously Ran</label>
<div class="col-md-8">
<input type="text" name="ran" value="<?php echo $row['ran']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showran" id="showran">
<option value="1"<?php if ($row['showran'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showran'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Electrical</label>
<div class="col-md-8">
<input type="text" name="electrical" value="<?php echo $row['electrical']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showelec" id="showelec">
<option value="1"<?php if ($row['showelec'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showelec'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Owner</label>
<div class="col-md-8">
<input type="text" name="owner" value="<?php echo $row['owner']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showown" id="showown">
<option value="1"<?php if ($row['showown'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showown'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Item Location</label>
<div class="col-md-8">
<input type="text" name="location" value="<?php echo $row['location']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showloca" id="showloca">
<option value="1"<?php if ($row['showloca'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showloca'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Purchase Price</label>
<div class="col-md-8">
<input type="text" name="purchase" value="<?php echo $row['purchase']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showpur" id="showpur">
<option value="1"<?php if ($row['showpur'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showpur'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Sales Price</label>
<div class="col-md-8">
<input type="text" name="price" value="<?php echo $row['price']; ?>" class="form-control" />
</div> <!-- /.col -->
<select name="showsale" id="showsale">
<option value="1"<?php if ($row['showsale'] == '1') echo 'selected = "selected"'; ?>>Show</option>
<option value="2"<?php if ($row['showsale'] == '2') echo 'selected = "selected"'; ?>>Hide</option>
</select>
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Featured</label>
<div class="col-md-8">
<select name="featured" id="featured">
<option value="1"<?php if ($row['featured'] == '1') echo 'selected = "selected"'; ?>>Yes</option>
<option value="2"<?php if ($row['featured'] == '2') echo 'selected = "selected"'; ?>>No</option>
</select>
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<p style="color: red; padding: 15px 0; font-weight: bold">Below is for our records and will not be shown on the item page.</p>
<div class="form-group">
<label class="col-md-3">Added by</label>
<div class="col-md-8">
<input type="text" name="addedby" value="<?php echo $row['addedby']; ?>" class="form-control" />
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<div class="form-group">
<label class="col-md-3">Notes</label>
<div class="col-md-8">
<textarea name="notes" rows="10" cols="55" wrap="physical" value="" type="text" id="about-textarea"><?php echo $row['notes']; ?></textarea>
<script>
tinyMCE.get('my_tiny').setContent(<?php echo $notes; ?>);
</script>
</div> <!-- /.col -->
</div> <!-- /.form-group -->
<br />
<div class="form-group">
<div class="col-md-7 col-md-push-3">
<button type="submit" name="Submit" class="btn btn-primary" >Save Changes</button>
<button type="reset" class="btn btn-default">Cancel</button>
</div> <!-- /.col -->
</div> <!-- /.form-group -->
EditPost.php
<?php
ob_start();
// contact to database
$host = "localhost";
$username = "admin";
$password = "pass";
$database="database";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$insert_data = mysql_real_escape_string($input_data);
$id = $_POST['eid'];
//echo $id;exit();
$itemname= mysql_real_escape_string($_POST['itemname']);
$model= mysql_real_escape_string($_POST['model']);
$serial= mysql_real_escape_string($_POST['serial']);
$year= mysql_real_escape_string($_POST['year']);
$desc= mysql_real_escape_string($_POST['desc']);
$dimension= mysql_real_escape_string($_POST['dimension']);
$location= mysql_real_escape_string($_POST['location']);
$price= intval($_POST['price']);
$purchase= mysql_real_escape_string($_POST['purchase']);
$year= intval($_POST['year']);
$addedby= intval($_POST['addedby']);
$notes= mysql_real_escape_string($_POST['notes']);
$ran= mysql_real_escape_string($_POST['ran']);
$electrical= mysql_real_escape_string($_POST['electrical']);
$owner= mysql_real_escape_string($_POST['owner']);
$manufacture= mysql_real_escape_string($_POST['manufacture']);
$condition= mysql_real_escape_string($_POST['condition']);
$category= mysql_real_escape_string($_POST['category']);
$redirect = "inventory.php?Msg=Update";
$featured = $_POST['featured'];
$showmanu = $_POST['showmanu'];
$showmodel = $_POST['showmodel'];
$showserial = $_POST['showserial'];
$showyear = $_POST['showyear'];
$showdem = $_POST['showdem'];
$showelec = $_POST['showelec'];
$showran = $_POST['showran'];
$showloca = $_POST['showloca'];
$showown = $_POST['showown'];
$showpur = $_POST['showpur'];
$showsale = $_POST['showsale'];
$query = "UPDATE `new_equip` SET `itemname`='$itemname',`manufacture`='$manufacture',`model`='$model',`serial`='$serial',`year`='$year',`category`='$category',`electrical`='$electrical',`desc`='$desc',`dimension`='$dimension',`location`='$location',`price`='$price',`condition`='$condition',`ran`='$ran',`addedby`='$addedby',`purchase`='$purchase',`notes`='$notes',`owner`='$owner',`featured`='$featured',`showmanu`='$showmanu',`showmodel`='$showmodel',`showserial`='$showserial',`showyear`='$showyear',`showdem`='$showdem',`showelec`='$showelec',`showran`='$showran',`showloca`='$showloca',`showown`='$showown',`showpur`='$showpur',`showsale`='$showsale'" . $UF . "WHERE `id`='$eid' LIMIT 1";
mysql_query($query) or die(mysql_error() . "<br />" . $query);
//echo $query;
// Redirect
header("Location: " . $redirect);
ob_flush();
?>
hello
$query = "UPDATE `new_equip` SET `itemname`='$itemname',`manufacture`='$manufacture',`model`='$model'" . $UF . "WHERE `id`='$id' LIMIT 1";
this variable is not declared ! chek it
$UF
and does not containt value.
That is for the images.
That code is this, but up to 15
$UF = "";
if (strlen($_FILES['image']['name']) > 1)
{
$FName = md5($_FILES['image']['name'] . time()) . "." . end(explode('.', $_FILES['image']['name']));
$NewFile = "../UImages/" . $FName;
if (!move_uploaded_file($_FILES['image']['tmp_name'], $NewFile))
{
die("Failed to move file " .$_FILES['image']['tmp_name']." to " . $FName);
}
$UF .= ",`image`='$FName'";
}
if (strlen($_FILES['image2']['name']) > 1)
{
$FName = md5($_FILES['image2']['name'] . time()) . "." . end(explode('.', $_FILES['image2']['name']));
$NewFile = "../UImages/" . $FName;
if (!move_uploaded_file($_FILES['image2']['tmp_name'], $NewFile))
{
die("Failed to move file " .$_FILES['image2']['tmp_name']." to " . $FName);
}
It is happening to every form I try to send. The contact form, the quote form. Nothing is being passed to the database, everything is coming in blank.
system
Closed
June 9, 2015, 12:08am
9
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.