Jump to content

Jekyl1

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jekyl1's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. THAT TOTALLY WORKED! Thank you so much. Such a simple fix for something that turned me gray, then made all the gray fall out and leave me bald. Thanks!
  2. Hi there. I have a from so the administrator can edit records. The form is populated with the current record information. There is a drop down menu which is populated from the table "shows" The user can select an option, click submit, and the record is changed. It all works, except if the user chooses the first option from the drop down menu. I have tried changing which option is listed first, I have tried changing the text in the database (thinking maybe there were some "illegal" characters), but nothing. If I do a simple echo of each record in the table, everything shows up normal, so it is definitely something to do with the drop down menu or how I am pulling information into it. If you go to www.workjuice.net/cms/all.php you can click on "edit" to get to the form. From the form, click "Update" and you will see a list of the "new" info that would be inserted into the table. You'll see, that for all options, except the first, chosen from the drop down, an id number is returned. For some reason, the first option will not return an id. And don't worry, no data will actually be changed, I disabled that part. Thanks!! Here is the code for the whole page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Edit An Epsiode</title> </head> <body> <?php if (!$_POST['submit']) { // check for record ID if ((!isset($_GET['id']) || trim($_GET['id']) == '')) { die('Missing record ID!'); } // open database connection include '../connections/medianstrip.php'; // generate and execute query $id = $_GET['id']; $this_show = $_GET['show_name']; $this_show_id = $_GET['this_show_id']; $query = "SELECT perf_date, ep_title, ep_summary, guests FROM previouslies WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if a result is returned if (mysql_num_rows($result) > 0) { // turn it into an object $row = mysql_fetch_object($result); //$this_show_id = $row->show_id; } } ?> <h3> Edit Epsiode </h3> <table width="600" cellspacing="5" cellpadding="5" bgcolor="#FFE8B7"> <form action="insertEditEpisode.php" method="POST"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <tr> <td valign="top"><h2>Performance Date </h2></td> <td> <input size="50" maxlength="250" type="text" name="perf_date" value="<?php echo $row->perf_date; ?>"> </td> </tr> <tr> <td valign="top"><h2>Episode Title </h2></td> <td> <input size="50" maxlength="250" type="text" name="ep_title" value="<?php echo $row->ep_title; ?>"> </td> </tr> <tr> <td valign="top"><h2>Summary</h2></td> <td> <textarea name="ep_summary" cols="37" rows="5"><?php echo $row->ep_summary; ?></textarea> </td> </tr> <tr> <td valign="top"><h2>Guest Stars </h2></td> <td> <input size="50" maxlength="250" type="text" name="guests" value="<?php echo $guests; ?>"> </td> </tr> <tr> <td valign="top"><h2>Show</h2></td> <td> <?php /////// HERE'S WHERE I THINK THE PROBLEM BEGINS ///////////// $query = "SELECT show_id, show_name FROM shows ORDER BY show_name ASC"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); $options=""; while ($row=mysql_fetch_array($result)) { $show_name=$row["show_name"]; $show_id=$row["show_id"]; $options.="<OPTION VALUE=\"$show_id\">".$show_name; } ?> <input type="text" name="show_id" value="<?php echo $this_show_id; ?>"> <select maxlength="60" type="text" name="new_show_name" class="formText"> <option value="<?php echo $this_show_id; ?>"><?php echo $this_show; ?></option> <option value="<?php echo $options; ?>"></option> </select> </td> </tr> <tr> <td align="" colspan=2> <input type="Submit" name="submit" value="Update"> </td> </tr> </form> </table> </body> </html>
  3. Thanks for the help... But it didn't work.
  4. Okay, so here goes... I have two MySQL tables (cookies and images). cookies contains info about cookies (name, description, price) and images contains image info for that cookie (path, name, size). I have a form, add.php which allows me to add new records. I can choose an image from my computer, upload it to the server, and then the filename is stored in the images table, while the other cookie info is stored in cookies. This part works perfectly. I have another form, edit.php, where I want to be able to update this info. The user clicks on a link, which passes an id to edit.php and populates all the text boxes with the correct information for that record. Then, the user can change the info, click Submit, and the record is updated with the new info. This too works perfectly... as long as I do not include the image portion. What I want is for the current image associated with the chosen record to be displayed (that part works, too!) and for the user to be able to change the image if desired. Either by uploading a new file, or by choosing an already uploaded file. Then the new file info should be updated in the images table. This is the part that isn't working. :-\ Here's what I got. The problem lies somewhere around: if(isset($_POST['update'])) because if I take that out, I get the "Error Uploading File" error. If I leave it in, everything is skipped and nothing gets updated. And like I said, if I take out the "image uploading" portions of the code, it works just fine. Ripping my hair out now... <?php // form not yet submitted // display initial form with values pre-filled if (!$_POST['update']) { // check for record ID if ((!isset($_GET['id']) || trim($_GET['id']) == '')) { die('Missing record ID!'); } // open database connection include '../includes/connect.php'; include '../includes/functions.php'; // generate and execute query $id = $_GET['id']; //this gets the selected record and all related values $query = "SELECT cookies.c_name, cookies.description, cookies.signature, cookies.price, images.name_img FROM cookies LEFT JOIN images ON cookies.id = images.id WHERE cookies.id = '$id'" OR DIE ('Unable to connect to database! Please try again later.'); $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if a result is returned if (mysql_num_rows($result) > 0) { // turn it into an object $row = mysql_fetch_object($result); // print form with values pre-filled ?> <table cellspacing="5" cellpadding="5" bgcolor="#FFE8B7"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <tr> <td valign="top"><h1>Cookie</h1></td> <td colspan="2"> <input size="50" maxlength="250" type="text" name="c_name" value="<?php echo $row->c_name; ?>"> </td> </tr> <tr> <td valign="top"><h1>Description</h1></td> <td colspan="2"><textarea name="description" cols="38" rows="10"><?php echo $row->description; ?></textarea></td> </tr> <tr> <td valign="top"><h1>Price</h1></td> <td colspan="2"> <input size="50" maxlength="250" type="text" name="price" value="<?php echo $row->price; ?>"> </td> </tr> <tr> <td valign="top"><h1>Featured?</h1></td> <td colspan="2"> <select maxlength="3" type="text" name="signature"> <option value="Current"><?php echo $row->signature; ?></option> <option value="Yes">Yes</option> <option value="No">No</option> </select> </td> </tr> <tr> <td width="129" valign="middle"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <h1>Image</h1></td> <td width="240" valign="middle"><input name="userfile" type="file" id="userfile"> <?php echo $row->name_img; ?> <td width="100" valign="top"> Current Image <br /> <?php echo "<img class='thumbs' src='http://www.cookiesbycourtney.com/cookie_pics/" . $row->name_img . "' />" ; ?> </td> </tr> <tr> <td></td> <td> <input type="Submit" name="update" value="Update"> </td> </tr> </form> </table> <? //////////////////////////////////////////////////////////////////////////////////////////////////////////// //update image // you can change this to any directory you want // as long as php can write to it $uploadDir = '/home/content/c/o/u/courtscookies/html/cookie_pics/'; if(isset($_POST['update'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "<div class='resultBox'>"; echo "Error uploading file"; echo "</div>"; exit; } ///////////////////////////////////////////////////////////////////////////////////// } // no result returned // print graceful error message else { echo '<h2>That cookie could not be located in our database.</h2>'; } } // form submitted // start processing it else { // set up error list array $errorList = array(); $c_name = $_POST['c_name']; $description = $_POST['description']; $price = $_POST['price']; $signature = $_POST['signature']; $id = $_POST['id']; // check for record ID if ((!isset($_POST['id']) || trim($_POST['id']) == '')) { die ('Missing record ID!'); } // validate text input fields if (trim($_POST['c_name']) == '') { $errorList[] = 'Invalid entry: Cookie'; } if (trim($_POST['description']) == '') { $errorList[] = "Invalid entry: Description"; } if (trim($_POST['signature']) == '') { $errorList[] = "Invalid entry: Featured"; } // set default value for price if (trim($_POST['price']) == '') { $price = $def_price; } // check for errors // if none found... if (sizeof($errorList) == 0) { include '../includes/connect.php'; // generate and execute query $query = "UPDATE cookies SET c_name = '$c_name', description = '$description', price = '$price', signature = '$signature' WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); //////////////////////////////////////////////////////////// include '../includes/connect.php'; if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query = "UPDATE images SET (name_img, size, type, path) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath') WHERE id = '$id'"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // print result echo '<div class="resultBox"><span class="resultText">Update Successful! <br /><br /><a href=list_cookies.php><u>Back to cookies List</u></a> <br /> <a href="index.php"><u>Back to Main Menu</u></a> <br /> <a href="../index2.php"><u>Back to Site</u></a> </span></div>'; // close database connection mysql_close; } else { // errors occurred // print as list echo '<font size=-1>The following errors were encountered:'; echo '<br>'; echo '<ul>'; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul>'; } } } ?>
×
×
  • 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.