azukah Posted March 14, 2010 Share Posted March 14, 2010 My checkbox works: when i check it I see "new" and when not checked is see nothing ("") what i can't figure out is how do i make stick so when i go into modify view, if checked to stayed checked. right now, when i go to modify a record that has the box checked, it shows unchecked. i'd like to keep it checked if checked... makes sense? any ideas woudl be greatly appreciate it! <?php ob_start(); require_once('../cms_config.php'); require_once('../cms_functions/ximageupload.php'); mysql_select_db($database, $makeconnection); $sql_get_cats="SELECT * FROM tbl_cat ORDER BY cat_name ASC"; $get_cats = mysql_query($sql_get_cats, $makeconnection) or die(mysql_error()); $row_get_cats = mysql_fetch_assoc($get_cats); $totalRows_get_cats = mysql_num_rows($get_cats); if(isset ($_GET['prod'])&& $_GET['prod']!=""){ $prod_id=$_GET['prod']; mysql_select_db($database, $makeconnection); $sql_find_prod = "SELECT * FROM tbl_products WHERE prod_id = $prod_id"; $find_prod = mysql_query($sql_find_prod, $makeconnection) or die(mysql_error()); $row = mysql_fetch_assoc($find_prod); $totalRows = mysql_num_rows($find_prod); $prod_name = $_POST['prod_name']; $prod_artist = $_POST['prod_artist']; $prod_price = $_POST['prod_price']; $prod_desc = $_POST['prod_desc']; $prod_cat = $_POST['prod_cat']; $prod_new = (isset($_POST['prod_new']) && $_POST['prod_new'] == '1')? "NEW" : ""; if (isset($_POST['submitted'])&&($_POST['submitted'] == "yes")) { $register_query = "SELECT prod_name FROM tbl_products WHERE prod_name='$prod_name'"; mysql_select_db($database, $makeconnection); $register_check=mysql_query($register_query, $makeconnection); $register_found_prod = mysql_num_rows($register_check); if($register_found_prod>1){ header ("Location: prod_modify.php?error=prodnameexists&prod=$prod_id"); }else{ if(isset($_POST['change_img']) && $_POST['change_img']=='yes'){ $prod_img=upload_prod_img(); $sql_modify = "UPDATE tbl_products SET prod_new = '$prod_new', prod_name = '$prod_name', prod_artist = '$prod_artist', prod_price = '$prod_price', prod_cat = '$prod_cat', prod_desc = '$prod_desc', prod_img='$prod_img' WHERE prod_id = '$prod_id'"; }else{ $sql_modify = "UPDATE tbl_products SET prod_new = '$prod_new', prod_name = '$prod_name', prod_artist = '$prod_artist', prod_price = '$prod_price', prod_cat = '$prod_cat', prod_desc = '$prod_desc' WHERE prod_id = '$prod_id'"; } mysql_select_db($database, $makeconnection); $Result1 = mysql_query($sql_modify, $makeconnection) or die(mysql_error()); header ("Location: prod_view.php"); } } } ?><!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=UTF-8" /> <title>Kuy:to CMS | Modify Vectors</title> <script src="../../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="../../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <link href="../../css/cssBackEnd.css" rel="stylesheet" type="text/css"> </head> <body> <div id="cmswrapper"> <?php include("../xcmsnav.php");?> <div id="cms_heading"> <div id="cms_title"> <h1>Modifying Detailes for: <? echo $row['prod_name']?></h1> <p>Change vectors' name, price, category, description and/or image.</p> </div><!--END OF DIV CMS_TITLE--> <div id="cms_cancel"> <a href="prod_view.php"><img src="../cms_images/bg_icons3.png" id="myCancelIcon"/></a> <p><a href="prod_view.php"> CANCEL</a></p> </div><!--END OF DIV CMS_ADD--> </div><!--END OF DIV CMS_HEADING--> <div class="myclear"></div> <div id="cms_table"> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table width="800" border="0" align="left" cellpadding="5" cellspacing="10" class="mytbltxt"> <tr> <td colspan="2" class="myloginerror"><?php if($_GET['error']=="catnameexists"){ echo ' <strong>Sorry... there is a problem with your category:</strong><br/>Already in use. Please try again.<br/><br/>'; } ?></td> </tr> <tr valign="top"> <td width="200" align="right" valign="middle" class="formtext">New Vector </td> <td width="600"><input name="prod_new" type="checkbox" class="mycheck" id="prod_new" value="1" /></td> </tr> <tr valign="top"> <td width="200" align="right" valign="middle" class="formtext">Vector Name<font color="#FF0000">*</font></td> <td width="600"><label><span id="sprytextfield1"> <input name="prod_name" type="text" class="myfield" id="prod_name" value="<? echo $row['prod_name']?>"> <span class="textfieldRequiredMsg">required!</span></span></label></td> </tr> <tr valign="top"> <td width="200" align="right" valign="middle" class="formtext">Artist Name<font color="#FF0000">*</font></td> <td width="600"><label><span id="sprytextfield4"> <input name="prod_artist" type="text" class="myfield" id="prod_artist" value="<? echo $row['prod_artist']?>"/> <span class="textfieldRequiredMsg">required!</span></span></label></td> </tr> <tr valign="top"> <td align="right" class="formtext">Price<font color="#FF0000">*</font></td> <td><p><span id="sprytextfield2"> <input name="prod_price" type="text" class="myfield" id="prod_price" value="<? echo $row['prod_price']?>" /> <span class="textfieldRequiredMsg">required!</span><span class="textfieldInvalidFormatMsg">invalid format!</span></span></p></td> </tr> <tr valign="top"> <td align="right" class="formtext">Category<font color="#FF0000">*</font></td> <td align="left" class="fieldtext"><select name="prod_cat" class="mylist" id="prod_cat"> <?php do { if($row_get_cats['cat_id']==$row['prod_cat']){ $makestelcted=' selected="selected" '; }else{ $makestelcted=''; } ?> <option <?php echo $makestelcted; ?> value="<?php echo $row_get_cats['cat_id']; ?>"> <?php echo $row_get_cats['cat_name']; ?> </option> <?php } while ($row_get_cats = mysql_fetch_assoc($get_cats)); ?> </select> <span class="ptext1_emph"> <?php if($_GET['error']=="nocat"){ echo "<strong>Please, select a category for this vector</strong>"; } ?> </span></td> </tr> <tr valign="middle"> <td align="right" valign="top" class="formtext">Desctiption</td> <td align="left" class="fieldtext"><textarea name="prod_desc" cols="45" rows="5" class="mycomments" id="prod_desc"><? echo $row['prod_desc']?></textarea></td> </tr> <tr valign="middle"> <td align="right" valign="top" class="formtext">Image</td> <td align="left" class="fieldtext"><p><img src="../../images/products/<? echo $row['prod_img']?>" alt="" name="img_modify" height="100" id="img_modify" /></p> <p> <input name="change_img" type="checkbox" class="mycheck" id="change_img" value="yes" /> check for new image <em>(leave <strong>unchecked</strong> if you want to keep the current image)</em></p> <p><input name="prod_img" type="file" class="myfield" id="prod_img"/><br/> <em>Formats: jpg, gif, png</em></p></td> </tr> <tr valign="middle"> <td align="left" class="formtext"> </td> <td align="left" class="fieldtext"> <input name="button" type="submit" class="mybutton" id="button" value="Modify" /> <input name="submitted" type="hidden" id="submitted" value="yes" /></td> </tr> </table> </form> </div><!--END OF CMS_TABLE--> </div><!--NEND OF WRAPPER--> <script type="text/javascript"> <!-- var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "none", {validateOn:["blur"]}); var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur"]}); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "currency"); //--> </script> </body> </html> Link to comment https://forums.phpfreaks.com/topic/195197-help-with-php-mysql-checkbox/ Share on other sites More sharing options...
5kyy8lu3 Posted March 14, 2010 Share Posted March 14, 2010 you'll probably want to post that in [ php ] [ /php ] tags to get helped =) p.s. those tags only without the spaces Link to comment https://forums.phpfreaks.com/topic/195197-help-with-php-mysql-checkbox/#findComment-1025928 Share on other sites More sharing options...
GalaxyTramp Posted March 14, 2010 Share Posted March 14, 2010 <?php $prod_new="yes"; ?> <input name="change_img" type="checkbox" class="mycheck" id="change_img" value="yes" <?php if($prod_new=="yes"){echo" checked";}?> /> Link to comment https://forums.phpfreaks.com/topic/195197-help-with-php-mysql-checkbox/#findComment-1025968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.