PHP - Db Structure Needs To Be Changed Up!
Alright guys.. I need some advice, some recommendations and definitely some help.
I've got a submission form for users to upload an image and some basic personal information. The client wanted the information to be divided by the North America (specifically N.A. and not U.S.) and Europe.. so I created a database table with the typical structu a row for the user's name, email, etc. I also added a row labeled "regionid" in which "1" would equal North America and "2" would equal Europe. This "regionid" row would obviously organize the submission by their country. The client specifically wanted to label North America but mentioned only users from the States would probably only submit images, etc. Users could choose if they were submitting a form for US or Europe and "regionid" would be filled by which form was chosen. Recently, the client threw a curveball and now wants Canada as part of the North America submission form. Now, I don't want to add Canada as another option for my "regionid" row because it does belong under North America. However, I need to alter the structure of the database I currently have so that it can now organize if under North America or Europe, and if under North America, if the submission falls under the United States or Canada. I was thinking of adding a drop down menu under the North America form with the options US or Canada. Do you guys have any advice or other directions you would take to solve this problem.. that is, if my situation is even understandable? I found it pretty difficult to explain! Apologies! Similar TutorialsHi all, I created a page template at http://www.durgeshsound.com/gallery/ Here my pagination buttons are not working. this issue arises when permalink format is http://www.example.com/sample-post/ But when I set permalink format to default (www.example.com/?p=123) then it starts to work and creates a working pagination link like this http://www.durgeshso...e_id=81&paged=2. I want this format http://www.example.com/sample-post/ in the links. Please help. When having different levels of directories, using relative paths will not work anymore, for example: controller - authentication File 1: include('../../model/header.php') model File 2: header.php view File 3. style.css The header.php file includes the css file with a relative path, but the problem is it includes it as follows: ../view/style.css When now the header.php file gets included into File 1 in the folder "authentication", then the css file will not be accessible anymore, for it to be accessible you would have to go two directories up. In this sense my question is, what would be the proper path structure for a folder structure with multiple levels? Should I rather use absolute paths, I am not so prone of absolute path. What if the folders changes a bit, or the domain changes, or the location changes? Hello everybody,
I have a form like that:
<form method="post" action="x.php"> <input type="hidden" name="pubid" value="<?php echo $_SESSION["public_id"][$a]; ?>" /> <input type="submit" name="update" />The public id is an id that every user have and that I use for get and post, imagine that this form is in a php "for" that print all this forms with public_id. Then I have a code like that: if(isset($_POST["update])){ if($_POST["pubid"]!==(There are some checks to avoid mysql injection)){ mysql_query=update from xxx set x=1 where pubid=$_POST["pubid"])(EXEMPLE) }}I want to avoid any change of form, because if someone change the value of the hidden input can modify information of mysql, someone know any method to do that? A friend told me to use js to compare form fields, but the user can modify js too I think, then I need to check it with php I think, correct me if Im wrong. Someone help me please. Ive created a process which automatically creates a form for all of the "courses" that are listed in a database. This table shows the name, the course code, the current program the course is under and an option to delete the course. I have created a drop down menu for the user to select any of the current programs to switch the course into. My problem is I have X amount of select fields and radio buttons and I dont know how to tell which one has been changed below is my code, appreciate the help!: case "ep": if (isset ($_GET['id'])){ $id = $_GET['id']; echo "Below lists all of the current courses under this program. Once you have made all of the changes click the submit button at the bottom of the page. <br><br><br>"; $query = "SELECT * FROM courses WHERE cid = $id"; $result = mysql_query($query) or die (mysql_error()); echo "<form action=\"course_process.php\" method=\"post\">"; echo "<table><tr><td><strong>Course Name</strong></td><td><strong>Course Code</strong></td><td><strong>Change Course Program</strong></td><td><strong>Delete</strong></td></tr>"; $i = 0; while ($row = mysql_fetch_assoc($result)){ $r = $row['id']; $query2 = "SELECT * from catagories"; $result2 = mysql_query($query2) or die (mysql_error()); echo "<tr><td> ". $row['name']. " </td><td> ".$row['code']." </td><td><select name=\"".$row['id']."\">"; while ($row2 = mysql_fetch_assoc($result2)){ echo "<option value=".$row2['id'].">".$row2['name']. "</option>"; } echo "</select></td><td><input name=\"".$row['id']."\" type=\"radio\" value=\"Click to delete\" /></td></tr>"; } echo "<tr><td></td><td></td><td></td><td><input name=\"submit\" type=\"submit\" value=\"Commit Changes\" /> </td></tr></table></form>"; }else{ echo "Invalid action request. ERROR CODE 1"; } break; I have an upload script that has been working just fine for months now.. I didn't change a thing,, now people are saying they are getting a internal server error... I checked it myself and I am getting the same thing. There is no error number,, so I can't look it up.. My upload script is good for 30mb's and has been just fine up til now.. Any ideas? Could GoDaddy just be having probs? The error is only shown after the upload is started.. the upload starts, then about 30 seconds later, it appears. OK I'm 98% new to PHP. I'm trying to do my own website and my idea will work something like this: index.php ____________________ Header + Nav {PHP INCLUDE} Footer ____________________ The content will reside in another *.php page If you look at www.avlscotland.com/test 'temporary' It loads default.php when you go to the page which is perfect. I have it working in basic form although only the hyperlinks HOME - ABOUT AVL - DEAD LINK are active at this moment. So it works this way with everything in the same directory, but I want it to load the content from a subdirectory /test/pages/content.php This is the PHP code I am using <?php // Check if page has been requested if (!isset($_GET['content'])) { // Page has not been requested, show default page $content = 'default.php'; } else { // Page has been requested, validate page exists, show page $content = $_GET['content'].'.php'; } // End if page has been requested // Check to see if page exists if (file_exists($content)) { // Page exists // Show page include("$content"); } else { // Page doesn't exist echo '<br>'; echo '<br>'; echo '<br>'; echo 'Sorry, the page that you are trying to access does not exist.<br>'; echo 'Please return to <a href="http://www.avlscotland.com/test/index.php">AVL Scotland</a><br>'; echo '<br>'; echo 'Thank you.<br>'; } // End if page exists ?> I'm accessing the pages using links like <a class="menuactive" href="test/index.php?content=avl">Home</a> What I'm struggling to do is make the PHP look for the content files in a sub-directory. Look forward to any help you can offer. Thanks, Ross After switching from PHP 5.3 on Windows Server 2003 to PHP 7.4.3 on Linux Mint 19.3 (Tricia Cinnamon), I find that the output of print_r() has changed. If we look at the documentation (https://www.php.net/manual/en/function.print-r.php), the provided example output is as it was on my earlier machine: <pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) </pre> However, on the second machine, the output is: <pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) <blank line> ) </pre> Note the unexpected new line after each recursed array's closing parenthesis. The new line is not present after the outermost array closing parenthesis. Also to note, there is a newer version of XDebug installed. My question is: Is this a bug? (Follow-on question: if possible to determine at which version the output changed, what version would that be?) This difference is causing existing code to not be able to correctly parse that output. I have no idea if this is possible or not, but I've got a form that searches a DB for a record. If that record is found, it displays a form that people can edit the record. Now, if that person wants to change (for example) 1 record out of 16 called "status" from "lost" to "found" but leave all the rest as they are, how would I go about this? Basically, I need to check all the fields ON SUBMIT if they're different from the original values in the DB and only update if they are. Any help would be appreciated. Cheers, Dave Hey Guys,
I'm doing some coding and I've managed to snip something off....
This is the original code
<form method="post" action="{$systemsslurl}cart.php?a=add&domain=register"> <table class="table table-striped table-framed"> <thead> <tr> <th></th> <th>{$LANG.domainname}</th> <th class="textcenter">{$LANG.domainstatus}</th> <th class="textcenter">{$LANG.domainmoreinfo}</th> </tr> </thead> <tbody> {foreach from=$availabilityresults key=num item=result} <tr> <td class="textcenter">{if $result.status eq "available"}<input type="checkbox" name="domains[]" value="{$result.domain}" {if $num eq "0" && $available}checked {/if}/><input type="hidden" name="domainsregperiod[{$result.domain}]" value="{$result.period}" />{else}X{/if}</td> <td>{$result.domain}</td> <td class="textcenter {if $result.status eq "available"}domcheckersuccess{else}domcheckererror{/if}">{if $result.status eq "available"}{$LANG.domainavailable}{else}{$LANG.domainunavailable}{/if}</td> <td class="textcenter">{if $result.status eq "unavailable"}<a href="http://{$result.domain}" target="_blank">WWW</a> <a href="#" onclick="popupWindow('whois.php?domain={$result.domain}','whois',650,420);return false">WHOIS</a>{else}<select name="domainsregperiod[{$result.domain}]">{foreach key=period item=regoption from=$result.regoptions}<option value="{$period}">{$period} {$LANG.orderyears} @ {$regoption.register}</option>{/foreach}</select>{/if}</td> </tr> {/foreach} </table> <p align="center"><input type="submit" value="{$LANG.ordernowbutton} »" class="btn btn-danger" /></p> </form>and I've changed it to: <form method="post" action="{$systemsslurl}cart.php?a=add&domain=register"> {foreach from=$availabilityresults key=num item=result} {if $result.status eq "available"} <div style="width: 400px; color: #339933; font-size:14px;"><img src="/templates/dj/yes.jpg" style="float:left" />{$tld}<br />Available</div> <div style="width: 100px;" >{$name}<p style="color: #339933;">{$tld}</p></div> <div style="width: 200px;" ><select name="domainsregperiod[{$result.domain}]">{foreach key=period item=regoption from=$result.regoptions}<option value="{$period}">{$period} {$LANG.orderyears} @ {$regoption.register}</option>{/foreach}</select> <input type="submit" value="{$LANG.ordernowbutton} »" class="btn btn-danger" /></div> {/if} {if $result.status eq "unavailable"} <div style="width: 400px; color: #cc0000; font-size:14px;"><img src="/templates/dj/no.jpg" style="float:left" />{$tld}<br />Taken</div> <div style="width: 100px;" >{$domain}<p style="color: #cc0000;">{$tld}</p></div> <div style="width: 200px;" ><a href="http://{$result.domain}" target="_blank">WWW</a> <a href="#" onclick="popupWindow('whois.php?domain={$result.domain}','whois',650,420);return false">WHOIS</a></div> {/if} {/foreach}</form>The original code works fine and add to my cart, the new "updated" version fails... What have I done wrong? I have 3 set of pages. The first html page only contains a search textbox and a submit button which then call up the second page search.php which populate html table with search result. The third page is update.php which allows to update the records populated by search.php. The problem is that it when it update the records it automatically updates all rows in the table making all records look the same. I do not know where I have made a mistake please help. When I use phpadmin to update the records no problem as I can specifically input the cf_id number directly. Search.php code Code: [Select] <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("^/[A-Za-z]+/", $_POST['name'])){ $name=$_POST['name']; } } else{ echo "<p>Please enter a search query</p>"; } } //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $cf_uid = $row[0]; $Firstname = $row[6]; $lastname = $row[7]; $Address = $row[8]; $Postcode = $row[9]; $Phone = $row[10]; $Email = $row[11]; $Customer_Type = $row[12]; $Computer_type = $row[13]; $Computer_maker = $row[14]; $Model = $row[15]; $OS = $row[16]; $Appointment_date = $row[17]; $Problem = $row[18]; $Solution = $row[19]; $Comment = $row[20]; ?> <form action="updatecus.php" method="post"> <table width="100%" border="2" cellspacing="0" cellpadding="8"> <tr><td width="45%" class="FormText">Customer ID:</td> <td width="55%"><?php echo $row[0];?></td></tr> <tr><td width="45%" class="FormText">First name:</td> <td width="55%"><input name="Firstname" type="text" value="<?php echo $Firstname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Last name:</td> <td width="55%"><input name="lastname" type="text" value="<?php echo $lastname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Address:</td> <td width="55%"><input name="Address" type="text" value="<?php echo $Address; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Postcode:</td> <td width="55%"><input name="Postcode" type="text" value="<?php echo $Postcode; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Phone:</td> <td width="55%"><input name="Phone" type="text" value="<?php echo $Phone; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Email:</td> <td width="55%"><input name="Email" type="text" value="<?php echo $Email; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Customer:</td> <td width="55%"><input name="Customer_Type" type="text" value="<?php echo $Customer_Type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Computer :</td> <td width="55%"><input name="Computer_type" type="text" value="<?php echo $Computer_type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Manufactural:</td> <td width="55%"><input name="Computer_maker" type="text" value="<?php echo $Computer_maker; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Model:</td> <td width="55%"><input name="Model" type="text" value="<?php echo $Model; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Operating System:</td> <td width="55%"><input name="OS" type="text" value="<?php echo $OS; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Appointment:</td> <td width="55%"><input name="Appointment_date" type="text" value="<?php echo $Appointment_date; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Problem:</td> <td width="55%"><textarea name="Problem" rows="10" cols="20" ><?php echo $Problem; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Solution:</td> <td width="55%"><textarea name="Solution" rows="10" cols="20" ><?php echo $Solution; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Comment:</td> <td width="55%"><textarea name="Comment" rows="10" cols="20" ><?php echo $Comment; ?></textarea></td></tr> <td width="55%"><input name="submit" value="submit" type="submit" <br> <input type="Submit" value="Cancel"</br></td> </form> <?php ?> update.php code Code: [Select] <?php //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); //if (isset($_POST['submit'])) { $cf_id = $_POST['cf_id']; $Firstname = $_POST['Firstname']; $lastname = $_POST['lastname']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $Phone = $_POST['Phone']; $Email = $_POST['Email']; $Customer_Type = $_POST['Customer_Type']; $Computer_type = $_POST['Computer_type']; $Computer_maker = $_POST['Computer_maker']; $Model = $_POST['Model']; $OS = $_POST['OS']; $Appointment_date = $_POST['Appointment_date']; $Problem = $_POST['Problem']; $Solution = $_POST['Solution']; $Comment = $_POST['Comment']; if (isset($_POST['submit'])) { $query ="UPDATE Customer_Registration SET Firstname='$Firstname',lastname='$lastname',Address='$Address',Postcode='$Postcode',Phone='$Phone',Email='$Email',Customer_Type='$Customer_Type',Computer_type='$Computer_type',Computer_maker='$Computer_maker',Model='$Model',OS='$OS', Appointment_date='$Appointment_date',Problem='$Problem',Solution='$Solution',Comment='$Comment' WHERE cf_id=cf_id"or die (mysql_error()); echo $query; mysql_query($query) or die(mysql_error()); //mysql_close($con); echo "<p>Congrats Record Updated</p>"; } ?> Thank you in advance for your help I have just upgraded PHP on my ISP server and none of the php scripts work. I was using 5.2. And I am now on 5.4. Why would the scripts stop working? Are there and patches or changes I need to make to make them work? I need an answer urgently! I'm trying to get some code to work that will update a field to show a checkbox either checked or not checked.
The field either uses a Y or N. Y is checked, N not checked. A code that I have tried displays the correct result for the box either checked or not checked.
input type="checkbox" name="obcDisplay" value="Y" <?=($r['obcDisplay'] == 'Y') ? 'checked="checked"' : ''; ?>/>But I want the ability to change when the form is submitted. so if I bring up a page and the checkbox is checked (Y) and I submint, I want the database to update to N and the other way around. Hey all, I would like to know the best way to determine whether a value has been changed in a multi select transfer. For example, I have two select fields. User clicks on button to add an item to the right select element with id of select2 from the left select element with an id of select1. When they click update, it posts to a php method. This is where I am uncertain what to do. How can I check that they indeed added or removed items from the right select element and if they did, determine which ones were removed or added to make the reflected changes in the database? This is what I have, but it's bad solution because it deletes all related records before it adds the ones it finds to the right select element: Code: [Select] public function update(){ $subcategory = new Category(); $subcategory->where('id',$this->uri->segment(4))->get(); $subcategory->delete($subcategory->related_category->get()->all); $new_parents = $this->input->post('catupload'); $parent_category = new Category(); $parent_category->where_in('controller',$new_parents)->get(); $subcategory->save($parent_category->all); } This is what the form elements look like: Code: [Select] echo "You can add or remove one or many parents associated with this category:"; echo "<div class='multiselect-transfer'>"; echo form_multiselect('catadd[]',$other_cats,'','id="select1"'); echo anchor('#','add >>','id="add"'); echo "</div>"; echo "<div class='multiselect-transfer'>"; echo form_multiselect('catupload[]',$default_cats,'','id="select2"'); echo anchor('#','<< remove','id="remove"'); echo "</div>"; echo form_submit('submit','Update'); echo form_close(); $other_cats variable holds array of categories that have not been asssociated with the current category being updated when this category was first created. The $default_cats variable holds an array of categories that have been associated with the current category being updated when this category was first created. And the javascript: Code: [Select] $().ready(function() { $('#add').click(function() { return !$('#select1 option:selected').remove().appendTo('#select2'); }); $('#remove').click(function() { return !$('#select2 option:selected').remove().appendTo('#select1'); }); }); Thanks for response. Hello, I'm using curl to grab a new solar image once an hour or so from the Solar Dynamics Observatory (example below). I'm trying to archive new images and am struggling with that. If I download an image, the filetime() function returns the current time since I downloaded it and wrote it to a fresh file. The result is that the file is always "new", even if the image hasn't changed on the SDO website. Do you have an idea on how to check the last modified time of a file through curl or other means so that I'm not downloading duplicate images? Thanks a ton! //fetch image $ch = curl_init("http://www.somewebsite.com/theimage.jpg"); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); $file = "../images/latest/theimage.jpg"; $fp = fopen($file, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); //this part is no good... //get last modified date if (file_exists($file)) { $filetime = filemtime($file); } I have multiple forms within one php file. What is the best structure to use? Code: [Select] if (isset($_POST["one"])) { include... } if (isset($_POST["two"])) { include... } if (isset($_POST["three"])) { include... } OR Code: [Select] if (isset($_POST["one"])) { include... } else if (isset($_POST["two"])) { include... } else if (isset($_POST["three"])) { include... } thanks Hey guys ;-) I got a client that asked me today to create him an MLM type website. The first part of my work would be to test if there system works so I need to run a full demo of the multilevel structure. The MLM structure works as follow: 1 person finds 2 members and they then find 2 more each and so on until we reach 100 level deep. If i got this right, At level 5 there will be 25 members At level 10 there will be 100 members At level 20 there will be 400 members At level 40 there will be 1.600 members At level 100 there will be 10.000 members So at the end of the demo there should be 10k members inserted into the table The table looks like this: id, parent, level, under Parent is the ID of the guy that recruited him, level is the level that guy is at (level 1, 2 , 3, 4 or 5) and under is the number of people under him. I need to run a script that will insert all the data into that table so that we can run some test on the liability of the project so we can set the rates right. At first I thought it would be a piece of cake ... but when I started I found out very fast that populating the MLM network 5 level deep is gona be tricky ... my first attempt gave me a result that looks like this: Code: [Select] |0| |1|2| |x|x|3|4| x|x|x|x|x|x|5|6| As you can see the script only grab the last id then adds 2 new members then uses the last one as the parent and starts over ... So my script is useless and I did not figer out how to do everything in 1 step ... Any help would be appreciated. Hi all, I am working on php project and willing to use the "everything as a plugin" idea so alot of people can easily contribute. I am wondering how I can make a php page that includes my plugins, without having to hardcode them(as in require_once, ...). And afterwards it should be possible to execute a function on each of the enabled plugins. Especially the "hardcode" part I am not sure on how to fix it. As for executing a function for each plugin (so that will be a Class object), I wonder how I can make an object of each class from an interface and then execute a function without hardcoding the creation of all objects. Any one ideas or experience with something like this? Thanks in advance. I'm currently working on a site that has about 4 separate panels on the page that all use an include to populate. Each include is interacting with the database and I'm thinking that it might congest the databse to have each panel connecting to the same data base and getting data when the page loads. I was wondering if it would be good practice to take all the connections and functions and put them on a 5th include at the top of the page. This way the connections and functions would be available to each include. Is this a good idea? Will it be a problem for the 4 includes to ask the php function list include for data? Is it better to just let each include contain only the code it needs? Also, say I have 20 functions on the php include and one site page only needs to use 1 function. Would the php function include still loop thru and connect to the database for all 20 functions just because it is included or will it only use the bandwidth needed to execute the 1 function it is being asked to use? Hope that's not over confusing. Thanks! Hi. I am creating a database where a user can store up to 50 names of their family members. I have two table structures in mind and curious which one is the more efficient structure. ==================================================================================================== TABLE A: userid-firstfamilymemberid-firstfamilymembername-secondfamilymemberid-secondfamilymembername Note:(the columns would repeated until the fiftiethfamilymemberid and fiftiethfamilymembername for a total of 101 columns) TABLE B: userid-familymemberid-familymembername ====================================================================================================== which is more efficient... Table A which would have more columns but less rows or Table B which would have less rows but more columns.. also keep in mind that the fixed amount is 50 family members per a user. Thanks in advance. Hello dear friends, Let say we have Code: [Select] $to = "gigi"; then we have link like this Code: [Select] mysite.com/file.php?id=$1 We can change it to new form by add rule at .htaccess codes Code: [Select] RewriteRule -(.*)\.htm file.php?id=$1 So that the link be like this Code: [Select] mysite.com/$to-$id.htm it will works , Now what if i want to make the link like this Code: [Select] mysite.com/$id/$to.htm what will be the .htaccess code in this way ??? thanks |