Jump to content

usrmd

Members
  • Posts

    11
  • Joined

  • Last visited

usrmd's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am so very lost after reading this, I really wish I could provide some feedback for you. Please try to re-word what it is you're looking for. If I really had to guess, I'd guess you were asking for help on coding HTML, and using some images you made with photoshop as the layout.
  2. I've been working on a project here oplinfo.hj.cx/insert_test.php When a user is adding a game and it's compatibly information to the database, I'm able to make check boxes and radio button selections mandatory, as well as specify the min/max characters for a text field. <script Language="Javascript"> <!-- function CheckGameCode() { // Check the length of the value of the element named text_name // from the form named form_name if it's < 10 and > 10 characters // display a message asking for different input if ((form1.gamecode.value.length < 10) || (form1.gamecode.value.length > 10)) { // Build alert box message showing how many characters entered mesg = "You have entered " + form1.gamecode.value.length + " character(s) for Game Code\n" mesg = mesg + "Valid Game Code entries are 10 characters.\n" mesg = mesg + "Please verify your input and submit again.\n" mesg = mesg + "Example: SLUS-12345" alert(mesg); // Place the cursor on the field for revision form1.gamecode.focus(); // return false to stop further processing return (false); } // If text_name is not null continue processing return (true); } --> </script> <script language="Javascript"> function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("gamename", "gamecode", "region", "comp", "vmc"); // Enter field description to appear in the dialog box var fieldDescription = Array("Game Name", "Game Code", "Region", "Result", "VMC Support"); // dialog message var alertMsg = "Complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } </script> and the form <table width="830" border="0" bgcolor="#003131" align="center"><form action="insert_action.php" method="post" name="form1" id="form1" onsubmit="return !!(CheckGameCode() & formCheck(this));"> <tr> <td width="174" height="38" bgcolor="#003a39"><strong> Game Name / Game Code</strong></td> <td width="438" bgcolor="#003a39"> <input name="gamename" type="text" id="" size="40" maxlength="35" /> <input name="gamecode" type="text" id="gamecode" size="10" maxlength="10" /></td> <td width="204" bgcolor="#003a39"> For gamecode: <a href="http://www.sonyindex.com/index.htm">Sony Index</a><br /> Enter using 10 chars: ABCD-12345</td> </tr> Now what I'd like to do is make the "gamecode" text field require a certain character such as "-", rather then only requiring 10 characters.. more specifically, I'd like the first 4 characters required to be a letter (A-Z), the 5th character to be a "-" and the last 5 to be integers.. else the form does not submit. I'd like to eventually use these gamecodes to guarantee no duplicate entries into the database, and also proper format (example: ABCD-12345) if I ever decide to loop and display the row on the web page. The required format would be help against people just typing 10 random characters or using different gamecode format (ABCD_123.45), since duplicate entry validation will depend on the accuracy of these gamecodes. Is this possible with Javascript? If yes, how might I go about implementing these requirements.
  3. I should have tried it without the for loop, I suppose. I assumed I would have needed it, though. Removing it did keep the same functionality. This is good, because I was confused as to why~ for or foreach would be needed for this (thanks to all the terrible examples throughout the internet). The way it is working makes much more sense without that line there Thanks.
  4. Bit of trial and error.. Here is the corrected code: <?php $boxes= explode(",", $row["mode"]); for($i=0; $i<sizeof($boxes); $i++); ?> <input type="checkbox" name="mode[]" id="mode1" value="1" <?=(in_array('1',$boxes))?('checked')'');?>> Imploded check boxes are now reflecting checked if their individual values exist within the column "mode". Thanks for all the help here.
  5. Fortunately I don't think I will run into any problems by keeping the values imploded inside the same columns, as the values will never exceed 8. After checking out explode and in_array, I came up with this <?php $modes = ($rows['mode']); $modexplode = explode(",", $modes); ?> 1 <input type="checkbox" name="mode[]" id="mode1" value="1" <? if (in_array("1", $modexplode)){echo 'checked="checked"';} ?>/> Though it comes up with no boxes checked. I tried a lot of different versions of this, also, and looked up examples from other people to try those as well. I also looked into creating a function to do the job, but I'm too tired to read that much right now. Would you say the method above will get the job done? If yes, how can I display the column values inside "$modes=" ? I can enter my own values there[1, 2, 3, 4, 5, 6, 7, 8] but that results in every box being checked.
  6. Hahahahaha... /bow. Way too much weed in my life right now. Very humbling. Echoing the same information and wondering why it isn't changing. I had it like this not long ago, but it wasn't working.. I must have had a different issue, so ended up changing it. Should have realized. The radio buttons and other check boxes are all working as needed now after correcting the code as shown below. <input type="radio" name="comp" id="comp" value="http://www.oplinfo.x11s.org/files/images/comp.gif" <?php echo ($row['comp'] == "http://www.oplinfo.x11s.org/files/images/comp.gif") ? "CHECKED='CHECKED'" : ''; ?> /> Now, those pesky mode checkboxes... Their values are imploded into a single column. What would enable the script to know which box checked=checked based off of specific values inside the column? eg column data is "1, 5, 7" so checkboxes 1, 5 and 7 would checked=checked.
  7. I figure if I can get one set working, I'd be able to get the others working in the same way.. except for the mode checkboxes, anyways.. as those are imploded values in a single column.. and I'm definitely not sure how to define which box get's checked depending on the specific values in the column. I'm inspecting the value, and I have tried different things.. for instance, removing the first echo $rows["comp"], but then no checked=checked happens for the radio button. I feel like I am missing something small, and when I figure it out I am going to feel awfully silly xD
  8. Thank you for that information. I will try this.. and yes you are correct in your assumption as to why I included the hidden checkboxes
  9. Ah, I don't have a code that correctly selects/checks fields Hmm.. I don't see that all the images are for comp.gif. I use the same name "comp" for 3 different radio buttons, because only 1 can be checked, and each one needs to represent a different image url within the same column. The long code I posted is pretty much a copy of the live code on the site you saw.. and yeah I don't know why I added [1] [2] etc for the modes, I was just sitting on my hands trying to make things work. it's just got a few small changes from the past hour trying to figure this checkbox stuff out. Here is the exact~ same code that is currently on the website you saw. <?php //CONNECT TO THE MYSQL DATABASE $link = mysqli_connect('host','user','password','database'); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } //CREATE THE VARIABLES TO IDENTIFY THE DIFFERENT FORM INPUTS $tbl_name="opl_comp"; //VARIABLE TO ASSIGN PRIMARY KEY VALUE SO THE FORM KNOWS WHICH ROW IS BEING EDITED $game_id = isset($_GET['game_id']) ? (int)$_GET['game_id'] : 0; //IMPLODE THE CHECKBOX SELECTIONS EG 1, 2, 3 if(isset($_POST['mode'])) { $mode = implode(",", $_POST['mode']); } else { $mode = "None"; } //VARIABLES TO ASSIGN THE FORMS INPUT VALUES TO WHICH COLUMN IT WILL BE INSERTED INTO $region=$_POST['region']; $vmc=$_POST['vmc']; $smb=$_POST['smb']; $hdd=$_POST['hdd']; $usb=$_POST['usb']; $notes=$_POST['notes']; $comp=$_POST['comp']; $oplver=$_POST['oplver']; $gamename=$_POST['gamename']; ?> <?php //ESCAPE THE VARIABLE INPUTS $gamename = mysqli_real_escape_string($link, $_POST['gamename']); $region = mysqli_real_escape_string($link, $_POST['region']); $notes = mysqli_real_escape_string($link, $_POST['notes']); $oplver = mysqli_real_escape_string($link, $_POST['oplver']); $usb = mysqli_real_escape_string($link, $_POST['usb']); $smb = mysqli_real_escape_string($link, $_POST['smb']); $hdd = mysqli_real_escape_string($link, $_POST['hdd']); $comp = mysqli_real_escape_string($link, $_POST['comp']); //ON SUBMIT, UPDATE THE MYSQL DATABASE TABLE WITH THE NEW DATA INSIDE THE FORM INPUTS if(isset($_POST['Submit'])) { $update="UPDATE $tbl_name SET notes='$notes', gamename='$gamename', region='$region', mode='$mode', smb='$smb', hdd='$hdd', usb='$usb', comp='$comp', vmc='$vmc', oplver='$oplver' WHERE id='".$game_id."'"; $result=mysqli_query($link,$update) or die("Error: ".mysqli_error($update)); } ?> <?php //SELECT ALL FROM SQL DATABASE TABLE WHERE THE id COLUMN IS THE PRIMARY KEY VALUE $sql = "SELECT * FROM $tbl_name WHERE id = '".$game_id."'"; //SUBMIT QUERY TO DATABASE $result = $link->query($sql) or die(mysqli_error($sql)); ?> <?php //LOOP RETREIEVED DATA TO BE DISPLAYED INSIDE OF THE FORM while ($row = $result->fetch_assoc()) { ?> <h2>Update Entry #<?php echo $game_id;?><BR /> PLEASE BE CONSIDERATE WHEN EDITING AN ENTRY<br /> Result, Region, OPL Version, VMC Support, Load Methods & Modes are not reflected here.<br /> Please double check the current submission's details <u>before</u> updating entry.</h2> <table width="543" border="0" bgcolor="#006699" align="center"> <form action="" method="post" name="form1" id="form1" onsubmit="return formCheck(this);"> <tr> <td width="171" height="35" bgcolor="#003333"><strong> Game Name</strong></td> <td width="362" bgcolor="#003333"> <input name="gamename" type="text" id="gamename" size="43" maxlength="40" value="<?php echo $row['gamename']; ?>"/></td> </tr> <tr> <td height="33" bgcolor="#003333"><strong> Region / OPL Ver</strong></td> <td bgcolor="#003333"> <select name="region" id="region"> <option value="http://www.oplinfo.x11s.org/files/images/U.png">NTSC-U</option> <option value="http://www.oplinfo.x11s.org/files/images/J.png">NTSC-J</option> <option value="http://www.oplinfo.x11s.org/files/images/E.png">PAL</option> <option value="http://www.oplinfo.x11s.org/files/images/O.png">OTHER</option> </select> <select name="oplver" id="oplver"> <option value="0.6">OPL 0.6</option> <option value="0.7">OPL 0.7</option> <option value="0.8">OPL 0.8</option> <option value="0.9">OPL 0.9</option> </select></td> </tr> <tr> <td height="25" bgcolor="#003333"><strong> Result</strong></td> <td bgcolor="#003333"><strong> Compatible</strong> <input type="radio" name="comp" id="comp" value="<?php echo $row["comp"]; ?>" <?php echo ($row['comp'] == "http://www.oplinfo.x11s.org/files/images/comp.gif") ? "CHECKED='CHECKED'" : ''; ?> /> <strong>Incompatible</strong> <input type="radio" name="comp" id="incomp" value="<?php echo $row["comp"]; ?>" <?php echo ($row['comp'] == "http://www.oplinfo.x11s.org/files/images/incomp.gif") ? "CHECKED='CHECKED'" : ''; ?> /> <strong>Issues</strong> <input type="radio" name="comp" id="issues" value="<?php echo $row["comp"]; ?>" <?php echo ($row['comp'] == "http://www.oplinfo.x11s.org/files/images/issues.gif") ? "CHECKED='CHECKED'" : ''; ?> /></td> </tr> <tr> <td height="28" bgcolor="#003333"><strong> VMC Support</strong></td> <td bgcolor="#003333"> Yay <input name="vmc" type="radio" id="vmc" value="VMC" /> Nay <input type="radio" name="vmc" id="mc" value="MC" /></td> </tr> <tr> <td height="31" bgcolor="#003333"><strong> Load Methods</strong></td> <td bgcolor="#003333"> <input type="hidden" name="smb" value="-" /> SMB <input type="checkbox" name="smb" id="smb" value="SMB" /> <input type="hidden" name="usb" value="-" /> USB <input type="checkbox" name="usb" id="usb" value="USB" /> <input type="hidden" name="hdd" value="-" /> HDD <input type="checkbox" name="hdd" id="hdd" value="HDD" /></td> </tr> <tr> <td height="25" bgcolor="#003333"><strong> Modes</strong></td> <td bgcolor="#003333"> 1 <input type="checkbox" name="mode[]" id="mode1" value="1" /> 2 <input type="checkbox" name="mode[]" id="mode2" value="2" /> 3 <input type="checkbox" name="mode[]" id="mode3" value="3" /> 4 <input type="checkbox" name="mode[]" id="mode4" value="4" /> 5 <input type="checkbox" name="mode[]" id="mode5" value="5" /> 6 <input type="checkbox" name="mode[]" id="mode6" value="6" /> 7 <input type="checkbox" name="mode[]" id="mode7" value="7" /> 8 <input type="checkbox" name="mode[]" id="mode8" value="8" /></td> </tr> <tr> <td height="34" bgcolor="#003333"><strong> Notes</strong></td> <td bgcolor="#003333"> <input name="notes" type="text" id="notes" size="43" maxlength="40" value="<?php echo $row['notes']; ?>"/> <br /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td height="34" bgcolor="#003333"> <input type="Submit" name="Submit" value="Update" /></td> <td bgcolor="#003333"><strong> *refrain from clicking submit more then once*</strong></td> </tr> </form> </table> <p><A href='index.php'><strong>VIEW GAME COMPATABILITY DATABASE</strong></A><br /> </p> </center> <?php //END THE LOOP OF DATA TO THE FORM } ?> <?php //CLOSE THE CONNECTION TO THE DATABASE mysqli_close($link); ?>
  10. Yes, the code at the top of my post does indeed check the checkbox named "smb" (itself) if the value "SMB" exists in $rows['comp'].. I can apply this code to any type of input simply by changing the parameters. I was just supplying the method I used to get my half way desired result, this is why I said "technically".. because that code does exactly what is stated in the title to this topic.Unfortunately, it doesn't do all of what I need. All it does is select the check boxes, but I think there is an underlying problem as to why when using that code for my inputs, the corresponding sql data cannot be updated with new values when selecting non checked boxes. Please view the live example I provided to get a 100% accurate idea of what I am trying to explain.
  11. I suppose technically I have already managed to get the checkboxes checked=checked if the data exists, but I did it using this code <input type="checkbox" name="smb" id="smb" value="<?php echo $row["comp"]; ?>" <?php echo ($row['comp'] == "SMB") ? "CHECKED='CHECKED'" : ''; ?> /> This does correctly check & select radio buttons, checkboxes, drop down menus and the like with the relative value specified with == "", though the problem with this method is that when the form is submitted, the database is not updated with the newly checked/selected values. Instead, the previous data will be used as the current selection.. or for the SMB/HDD/USB (see the code) checkboxes, replaced by the value of their hidden input counterparts. You can see a live example here oplinfo.x11s.org/opllist/update.php?game_id=105 Notice that the "compatible" radio button is already selected, but if you try to update that value by selecting "issues", for example, it will just revert back to the original selection. Here is the page's code for reference. <?php //CONNECT TO THE MYSQL DATABASE $link = mysqli_connect('host','user','pass','database'); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } //CREATE THE VARIABLES TO IDENTIFY THE DIFFERENT FORM INPUTS $tbl_name="opl_comp"; //VARIABLE TO ASSIGN PRIMARY KEY VALUE SO THE FORM KNOWS WHICH ROW IS BEING EDITED $game_id = isset($_GET['game_id']) ? (int)$_GET['game_id'] : 0; //IMPLODE THE CHECKBOX SELECTIONS EG 1, 2, 3 if(isset($_POST['mode'])) { $mode = implode(",", $_POST['mode']); } else { $mode = "None"; } //VARIABLES TO ASSIGN THE FORMS INPUT VALUES TO WHICH COLUMN IT WILL BE INSERTED INTO $region=$_POST['region']; $vmc=$_POST['vmc']; $smb=$_POST['smb']; $hdd=$_POST['hdd']; $usb=$_POST['usb']; $notes=$_POST['notes']; $comp=$_POST['comp']; $oplver=$_POST['oplver']; $gamename=$_POST['gamename']; ?> <?php //ESCAPE THE VARIABLE INPUTS $gamename = mysqli_real_escape_string($link, $_POST['gamename']); $region = mysqli_real_escape_string($link, $_POST['region']); $notes = mysqli_real_escape_string($link, $_POST['notes']); $oplver = mysqli_real_escape_string($link, $_POST['oplver']); $usb = mysqli_real_escape_string($link, $_POST['usb']); $smb = mysqli_real_escape_string($link, $_POST['smb']); $hdd = mysqli_real_escape_string($link, $_POST['hdd']); $comp = mysqli_real_escape_string($link, $_POST['comp']); //ON SUBMIT, UPDATE THE MYSQL DATABASE TABLE WITH THE NEW DATA INSIDE THE FORM INPUTS if(isset($_POST['Submit'])) { $update="UPDATE $tbl_name SET notes='$notes', gamename='$gamename', region='$region', mode='$mode', smb='$smb', hdd='$hdd', usb='$usb', comp='$comp', vmc='$vmc', oplver='$oplver' WHERE id='".$game_id."'"; $result=mysqli_query($link,$update) or die("Error: ".mysqli_error($update)); } ?> <?php //SELECT ALL FROM SQL DATABASE TABLE WHERE THE id COLUMN IS THE PRIMARY KEY VALUE $sql = "SELECT * FROM $tbl_name WHERE id = '".$game_id."'"; //SUBMIT QUERY TO DATABASE $result = $link->query($sql) or die(mysqli_error($sql)); ?> <?php //LOOP RETREIEVED DATA TO BE DISPLAYED INSIDE OF THE FORM while ($row = $result->fetch_assoc()) { ?> <h2>Update Entry #<?php echo $game_id;?><BR /> PLEASE BE CONSIDERATE WHEN EDITING AN ENTRY<br /> Result, Region, OPL Version, VMC Support, Load Methods & Modes are not reflected here.<br /> Please double check the current submission's details <u>before</u> updating entry.</h2> <table width="543" border="0" bgcolor="#006699" align="center"> <form action="" method="post" name="form1" id="form1" onsubmit="return formCheck(this);"> <tr> <td width="171" height="35" bgcolor="#003333"><strong> Game Name</strong></td> <td width="362" bgcolor="#003333"> <input name="gamename" type="text" id="gamename" size="43" maxlength="40" value="<?php echo $row['gamename']; ?>"/></td> </tr> <tr> <td height="33" bgcolor="#003333"><strong> Region / OPL Ver</strong></td> <td bgcolor="#003333"> <select name="region" id="region"> <option value="U.png">NTSC-U</option> <option value="J.png">NTSC-J</option> <option value="E.png">PAL</option> <option value="O.png">OTHER</option> </select> <select name="oplver" id="oplver"> <option value="0.6">OPL 0.6</option> <option value="0.7">OPL 0.7</option> <option value="0.8">OPL 0.8</option> <option value="0.9">OPL 0.9</option> </select></td> </tr> <tr> <td height="25" bgcolor="#003333"><strong> Result</strong></td> <td bgcolor="#003333"><strong> Compatible</strong> <input type="radio" name="comp" id="comp" value="comp.gif" /> <strong>Incompatible</strong> <input type="radio" name="comp" id="incomp" value="incomp.gif"/> <strong>Issues</strong> <input type="radio" name="comp" id="issues" value="issues.gif"/></td> </tr> <tr> <td height="28" bgcolor="#003333"><strong> VMC Support</strong></td> <td bgcolor="#003333"> Yay <input name="vmc" type="radio" id="vmc" value="VMC" /> Nay <input type="radio" name="vmc" id="mc" value="MC" /></td> </tr> <tr> <td height="31" bgcolor="#003333"><strong> Load Methods</strong></td> <td bgcolor="#003333"> <input type="hidden" name="smb" value="-" /> SMB <input type="checkbox" name="smb" id="smb" value="SMB" /> <input type="hidden" name="usb" value="-" /> USB <input type="checkbox" name="usb" id="usb" value="USB" /> <input type="hidden" name="hdd" value="-" /> HDD <input type="checkbox" name="hdd" id="hdd" value="HDD" /></td><?php } ?> </tr> <tr> <td height="25" bgcolor="#003333"><strong> Modes</strong></td> <td bgcolor="#003333"> 1 <input type="checkbox" name="mode[1]" id="mode1" value="1" /> 2 <input type="checkbox" name="mode[2]" id="mode2" value="2" /> 3 <input type="checkbox" name="mode[3]" id="mode3" value="3" /> 4 <input type="checkbox" name="mode[4]" id="mode4" value="4" /> 5 <input type="checkbox" name="mode[5]" id="mode5" value="5" /> 6 <input type="checkbox" name="mode[6]" id="mode6" value="6" /> 7 <input type="checkbox" name="mode[7]" id="mode7" value="7" /> 8 <input type="checkbox" name="mode[8]" id="mode8" value="8" /></td> </tr> <tr> <td height="34" bgcolor="#003333"><strong> Notes</strong></td> <td bgcolor="#003333"> <input name="notes" type="text" id="notes" size="43" maxlength="40" value="<?php echo $row['notes']; ?>"/> <br /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td height="34" bgcolor="#003333"> <input type="Submit" name="Submit" value="Update" /></td> <td bgcolor="#003333"><strong> *refrain from clicking submit more then once*</strong></td> </tr> </form> </table> Any info/direction greatly appreciated.
×
×
  • 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.