PHP - Can You Generate Variable Labels Eg $s1 $s2 $s3.......
I have a recursive sql query. I'm doing this with an sql query as a function.
Here is the function: function select() { $sql="SELECT cat FROM $scat"; if($result=$mysqli->query($sql)){ if($result->num_rows>0){ $level =+1; echo<<<HTML <div class="menutitles"> onmouseover="document.getElementById('$scat').style.display='block';document.getElementById('$scat2').style.display='block';" onmouseout="document.getElementById('$scat').style.display='none';document.getElementById('$scat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$scat"></a><br/> <div class="contain" id="$scat"> <div class="menuitems" id="$scat2"> HTML; select(); }else{$level=-1; if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$scat'></a><br/> "; }else{ While($row=$result->fetch_array()){ $scat=replace($row[cat]); echo" <a class='topseltxt2' href='gem.php?cat=$scat'></a><br/> ";} } } } } and this is the database query with the function added to it: $level=1; $count=0; $sql = "SELECT cat FROM dczcat1 ORDER BY position"; if ($result = $mysqli->query($sql)){ if ($result->num_rows > 0){ $count=+1; while ($row = $result->fetch_array()){ $scat=replace($row[cat]); $scat2=replace($row[cat]) . 2; $cat=$row[cat]; $sql="SELECT cat FROM $scat"; if($result=$mysqli->query($sql)){ $count=+1; if($result->num_rows>0){ $level =+1; echo<<<HTML <div class="menutitles"> onmouseover="document.getElementById('$scat').style.display='block';document.getElementById('$scat2').style.display='block';" onmouseout="document.getElementById('$scat').style.display='none';document.getElementById('$scat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$scat"></a><br/> <div class="contain" id="$scat"> <div class="menuitems" id="$scat2"> HTML; select(); }else{$level=-1; if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$scat'></a><br/> "; }else{ While($row=$result . $count->fetch_array()){ $scat=replace($row[cat]); echo" <a class='topseltxt2' href='gem.php?cat=$scat'></a><br/> ";} } } }echo"</div> </div> </div>"; } } } I get the error: Fatal error: Call to a member function fetch_array() on a non-object in /home/kangerc1/public_html/zleftsidebar.php on line 60 I think this is because I am using $result more than once and I need to call it $result1 $result2 $result3 etc. but how can I generate the name of the variable? Similar TutorialsHi, im trying to apply a random css class to a div so that a random image is generated on each refresh. This is the code i am using to apply the class. Code: [Select] <div class="<?php echo($randomimage); ?>"> Say i have an array of $image1 $image2 $image3 etc, how can i make $randomimage = 1 of these at random on each refresh? I've found lots of tutorials that generate a random number online but none that generate a random variable and am having trouble piecing this together. Any help would be hugely appreciated. Richard Hi there! I found this code to parse a MySQL query to PDF, but it's for small address labels and I was wondering how to make it for 4x6 labels? <?php define('FPDF_FONTPATH','/home/directory/public_html/sub/font/'); require_once('fpdf.php'); //Connect to your database mysql_connect("localhost", "db_user","db_pw") or die ("Could not connect to database"); mysql_select_db("database_name") or die ("Could not select database"); $query = "SELECT employee_name, street_address, City, state, zip_code FROM employees ORDER BY `employee_name` "; $result = mysql_query($query) or die('Error, query failed'); $num_rows = mysql_num_rows($result); function PrintAddressLabels($result){ $pdf=new FPDF(); $pdf->Open(); $pdf->AddPage(); $pdf->SetFont('Arial','B',14); $pdf->SetMargins(0,0); $pdf->SetAutoPageBreak(false); $x = 0; $y = 0; $i=0; while (TRUE) { if ($row=$result[$i]) { //positions set above $LabelText = sprintf("%s\n%s %s\n%s, %s, %s", $row['employee_name'], $row['street_address'], $row['City'], $row['state'], $row['zip_code']); Avery5160($x,$y,&$pdf,$LabelText); $y++; // next row if ($y == 10 ) { // end of page wrap to next column $x++; $y = 0; if ($x == 3 ) { // end of page $x = 0; $y = 0; $pdf->AddPage(); } } $i++; //counter through result } else { // Error quit printing break; } { $pdf->Output('mailing_labels.pdf','D'); } ?> Does anyone know where I can find some good resources/tutorials that covers how to use the PDF stuff with PHP or know how I can change this up to match for 4x6 at all? Any help or info is greatly appreciated! Thanks! hi, whats the best way to print labels. I have already tried the script from fpdf.de but i can not get my dot matrix printer (dot matrix is needed for this purpose) the correct layout. Its continuous paper, with size 110 height x 62mm width (for each label). I am not able to select a self-adjustable paper-size. so i hope to solve this with PHP / PDF if possible. anyone have experience with this? cheerz!! Like many projects, this started small, and keeps growing! I am building a photo gallery and would now like to add labels/captions below each photo, HOWEVER, I really don't want to have to build a database and do all the related coding. (I know how, but its a PITA.) To display photos in the gallery, I read in files from my "images/" directory, store them in a simple array, and then iterate through the array to display the thumbnails in a gallery. I am wondering if there would be an easy way that I could merge photo metadata (e.g. a brief caption) with my array or something like that? If I could type up the file names and a brief description/caption in a Text File or Spreadsheet and then somehow slurp that into my code and merge it with my array or something like that, then I would be willing to type up captions. (This is for like 600 photos which is why I don't want to do a database as data entry in phpMyAdmin is a PITA!) Any suggestions how I could do this and add a "cherry on the top" of this mini project I am doing for my co-workers? Thanks!
Hope I'm not in the wrong forum here as javascript is required, BUT my page is written in PHP and will need to work from any number of records from the database. Basically, I have a drop-down box that contains product sizes, for example:- Small Medium Large Extra Large If the user selects Large for example, I want to change 'Was Price', 'Now Price' and 'Product Code' displayed on the page. If they select another size from drop-down the prices and code need to change again. Posted in the PHP section as PHP code is needed as well. Any help much appreciated. I use the following code to generate a scrollable checkbox list of options: Code: [Select] <html> <form action="SCRIPT.php"> <?php $expList = array('Engineering ','Science', 'Art', 'IT', 'Electronics', 'Communications'); sort($expList); $tmp = array(); $i = 1; $tmp[] = '<ul style="height: 95px; overflow: auto; width: 200px; border: 1px solid #480091; list-style-type: none; margin: 0; padding: 0;">'; foreach ($expList as $option) { $tmp[] = '<li id="li' . $i . 'b"><label for="chk' . $i . 'b"><input name="chk' . $i . 'b" id="chk' . $i . 'b" type="checkbox" onchange="Enable(\'chk' . $i . 'b\',\'li' . $i . 'b\')">' . $option . '</label></li>'; $i++; } $tmp[] = '</ul>'; echo implode("\n",$tmp) . "\n"; ?> <input type="submit"> </form> </html> But there are in fact over 50 options (not just 6) and they are in fact stored in an array $expList in an external php file called LISTS.php. As you can see, the checkbox list consists of checkboxes chk1b, chk2b, chk3b, etc. with associated labels (Art, Communications, Electronics, etc.). What I need in SCIPT.php is code that will insert each of the labels where the associated checkbox has been checked in my MySQL database. E.g. in this particular case: if chk1b & chk3b have been checked, 'Art' & 'Electronics' will be inserted. Also, I want the label of the first checked checkbox to be inserted in the (database) table column 'Exp1', the 2nd one in 'Exp2'.........25th one in 'Exp25' (I already have a script that allows a maximum of 25 checkboxes to be checked). I'm guessing some sort of 'foreach' loop is required, but I can't quite work it out. Pls help! Many thanks! Can this be done with php? aaa aab aac ... zzz Hi, can someone help me to understand this? What i want to do is to write some information in a form and after i submit the form that data will be in a new php page. Thanks in advance I have tried sitemap.org and a few others but have not found anything that will give the results I am after. I have a blog site that has a URL and a Description for the URL and wish to have the description show as the anchor text which is linked to the URL, all data is taken from MySQL. Does anyone have a code that will generate something like this ? <?php if(isset($_POST['submit'])){ //collect form data $location = $_POST['location']; $ID = $_POST['ID']; $section = $_POST['section']; //check name is set if($location ==''){ $error[] = 'Name is required'; } //if no errors carry on if(!isset($error)){ # Title of the CSV $Content = "location, ID, section\n"; //set the data of the CSV $Content .= "$location, $ID, $section\n"; # set the file name and create CSV file $my_file = ("$location$ID$section.cvs"); $handle = fopen("$my_file", "w") or die('Cannot open file: '.$my_file); header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename="' . $FileName . '"'); echo $Content; exit(); } } //if their are errors display them if(isset($error)){ foreach($error as $error){ echo "<p style='color:#ff0000'>$error</p>"; } } ?> <form action='' method='post'> <p><label>Location:</label><br><input type='text' name='location' value=''></p> <p><label>ID:</label><br><input type='text' name='ID' value=''></p> <p><label>Section:</label><br><input type='text' name='section' value=''></p> <p><input type='submit' name='submit' value='Submit'></p> </form>I have wrote a .php file which is a form with 3 different fields, in these fields I want to write entries which lateron will be submitted into a .csv generating a csv file on my server with the name of the entries. The issue is that the file is not being generated on my server. With the current code the entries are being recognized and being placed in the filename of the csv. The point is not to make it downloadable sinds I want to have it on my webserver and keep editing information in it. My code is top of this post. My .php file replies that: Cannot open file: BOD10Buffer.csv Pardon my sloppy code everyone, I am not really a person that codes but this "form" may save me a lot of time in the longrun, just difficult and I am asking for help on this. Is there anyone that may be kind enough to help me? and as to what I might be doing wrong? All help is much appreciated! Hi guys, so i have this file upload script. When i upload a file it gets stored in /uploads and keeps the same file name. So if i upload a file "test.exe" the file will be available at uploads/test.exe
What i want is that it generates a new file name like: "9daln292os.exe" so upload/9daln292os.exe
This is my code:
<?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; ?> <?php $file_type = $_FILES['userfile']['type']; $file_name = $_FILES['userfile']['name']; $file_ext = strtolower(substr($file_name,strrpos($file_name,"."))); if (!in_array($file_type, $FILE_MIMES) && !in_array($file_ext, $FILE_EXTS) ) $message = "Sorry, $file_name($file_type) is not allowed to be uploaded."; else $message = do_upload_function_here($upload_path_here, $upload_ur_upload_url_herel); ?> <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded. Here is the link to your file: <a href=uploads/". basename( $_FILES['uploadedfile']['name']). ">". basename( $_FILES['uploadedfile']['name'])."</a>"; } else{ echo "There was an error uploading the file, please try again!"; } ?>I don't know any basic php i really need someone to give me the code ready please. Thanks much appreciated. Edited by darox, 21 July 2014 - 01:07 PM. hi, im trying to create a website and only now started thinking about the security part(noob mistake). say for example i have home.php page and an index.php page. index.php is where users would sign up/log in. the login and sign up processes are all done but i was thinking of creating a unique id of some sort for when the user logs in. or something like this site (forum.phpfreaks) when we sign in, you are signed but the url stays the same = forums.phpfreaks.com. like if we were signed out we will be permanantly signed out and typing in forums.phpfreaks.com would just land us at the main page where we need to sign in.
right now ,my home.php can be accessed with or without logging in even with sessions.
hope im making sense, thanks in advanced!
**haha that rhymed.
i tried adding:
<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?> in the index.php:
<?php ob_start(); session_start(); if(isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['pass']; require "connection.php"; $emails = mysqli_real_escape_string($con, $email); $query = "SELECT id, name, email, password, salt FROM users WHERE email = '$emails';"; $result = mysqli_query($con, $query); if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again. { echo "<script>alert(\"User does not exist!\")</script>"; } $userData = mysqli_fetch_array($result, MYSQLI_ASSOC); $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) ); if($hash != $userData['password']) { echo "<script>alert(\"Incorrect Password!\")</script>"; }else{ session_regenerate_id(); $_SESSION['sess_user_id'] = $userData['id']; $_SESSION['sess_name'] = $userData['name']; session_write_close(); header('Location: home.php?user='); } } ob_flush(); ?> <!DOCTYPE html> <form name="login" method="post" action="<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?>">but i got access forbidden! Edited by noobdood, 19 May 2014 - 10:05 PM. How do you generate a random number like say, 0 through 10? I want to select random sites from my database that have IDs 0 through 10. Hi, I'm quite new to PHP so please forgive me if this is a bit simple! I have a form on my website, which uses PHP to generate an email to me, the recipient. It works, but there are two new modifications I need help with. First of all, I want the PHP to generate a 'thank you' email to the person who has submitted the email. Please could somebody show me the code, and where to add it? Secondly, I want the email to come through to me from the email address of the person submitting the form (i.e. replacing the donotreply email address currently). Again, could somebody please show me how to do that? Many thanks in advance Here's the code: <?php // Website Contact Form Generator // http://www.tele-pro.co.uk/scripts/contact_form/ // This script is free to use as long as you // retain the credit link // get posted data into local variables $EmailFrom = "donotreply@simplyskillsgroup.co.uk"; $EmailTo = "robin@trillodigital.co.uk"; $Subject = "Simply Skills Franchise Application"; $name = Trim(stripslashes($_POST['name'])); $surname = Trim(stripslashes($_POST['surname'])); $telephone = Trim(stripslashes($_POST['telephone'])); $email = Trim(stripslashes($_POST['email'])); $dob = Trim(stripslashes($_POST['dob'])); $add1 = Trim(stripslashes($_POST['add1'])); $add2 = Trim(stripslashes($_POST['add2'])); $add3 = Trim(stripslashes($_POST['add3'])); $town = Trim(stripslashes($_POST['town'])); $postcode = Trim(stripslashes($_POST['postcode'])); $where = Trim(stripslashes($_POST['where'])); $employment = Trim(stripslashes($_POST['employment'])); $trade = Trim(stripslashes($_POST['trade'])); $drive = Trim(stripslashes($_POST['drive'])); $crb = Trim(stripslashes($_POST['crb'])); $firstaid = Trim(stripslashes($_POST['firstaid'])); $protect = Trim(stripslashes($_POST['protect'])); $convict = Trim(stripslashes($_POST['convict'])); $coach = Trim(stripslashes($_POST['coach'])); $other = Trim(stripslashes($_POST['other'])); $faca = Trim(stripslashes($_POST['faca'])); $other2 = Trim(stripslashes($_POST['other2'])); $other3 = Trim(stripslashes($_POST['other3'])); $hear = Trim(stripslashes($_POST['hear'])); $confirm = Trim(stripslashes($_POST['confirm'])); // validation $validationOK=true; if (Trim($email)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=http://clientzone.trillodigital.co.uk/simplyskills/error.html\">"; exit; } // prepare email body text $Body = ""; $Body .= "PERSONAL DETAILS"; $Body .= "\n"; $Body .= "\n"; $Body .= "First Name: "; $Body .= $name; $Body .= "\n"; $Body .= "\n"; $Body .= "Surname: "; $Body .= $surname; $Body .= "\n"; $Body .= "\n"; $Body .= "Contact Number: "; $Body .= $telephone; $Body .= "\n"; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "\n"; $Body .= "Date of Birth: "; $Body .= $dob; $Body .= "\n"; $Body .= "\n"; $Body .= "Address Line 1: "; $Body .= $add1; $Body .= "\n"; $Body .= "\n"; $Body .= "Address Line 2: "; $Body .= $add2; $Body .= "\n"; $Body .= "\n"; $Body .= "Address Line 3: "; $Body .= $add3; $Body .= "\n"; $Body .= "\n"; $Body .= "Town or City: "; $Body .= $town; $Body .= "\n"; $Body .= "\n"; $Body .= "Post Code: "; $Body .= $postcode; $Body .= "\n"; $Body .= "\n"; $Body .= "\n"; $Body .= "FRANCHISE DETAILS"; $Body .= "\n"; $Body .= "\n"; $Body .= "Where in the United Kingdom would you like to operate a Simply Skills franchise: "; $Body .= $where; $Body .= "\n"; $Body .= "\n"; $Body .= "Your current employment or business: "; $Body .= $employment; $Body .= "\n"; $Body .= "\n"; $Body .= "In a position to trade within: "; $Body .= $trade; $Body .= "\n"; $Body .= "\n"; $Body .= "Driving licence: "; $Body .= $drive; $Body .= "\n"; $Body .= "\n"; $Body .= "Enhanced CRB disclosure (within 3 years): "; $Body .= $crb; $Body .= "\n"; $Body .= "\n"; $Body .= "Current first-aid qualification (within 3 years): "; $Body .= $firstaid; $Body .= "\n"; $Body .= "\n"; $Body .= "Child protection training (within 3 years): "; $Body .= $protect; $Body .= "\n"; $Body .= "\n"; $Body .= "Any convictions that would affect your ability to work within schools: "; $Body .= $convict; $Body .= "\n"; $Body .= "\n"; $Body .= "\n"; $Body .= "EXPERIENCE"; $Body .= "\n"; $Body .= "\n"; $Body .= "Highest football coaching qualification: "; $Body .= $coach; $Body .= "\n"; $Body .= "\n"; $Body .= "Other football coaching qualifications: "; $Body .= $other; $Body .= "\n"; $Body .= "\n"; $Body .= "Member of the Football Association Coaches Association: "; $Body .= $faca; $Body .= "\n"; $Body .= "\n"; $Body .= "Other sports/disciplines you are qualified to deliver: "; $Body .= $other2; $Body .= "\n"; $Body .= "\n"; $Body .= "Personal qualities and experience that you feel is beneficial to operating a Simply Skills franchise: "; $Body .= $other3; $Body .= "\n"; $Body .= "\n"; $Body .= "\n"; $Body .= "How did you hear about Simply Skills: "; $Body .= $hear; $Body .= "\n"; $Body .= "\n"; $Body .= "Confirm all information provided is correct: "; $Body .= $confirm; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://clientzone.trillodigital.co.uk/simplyskills/thankyou.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://clientzone.trillodigital.co.uk/simplyskills/error.html\">"; } ?> I use this program on the server. It does not work. <?php $pdf= pdf_new(); ?> This is the problem of the program or the problem of the server. http://www.ptiimaging.ca/pdf.php Hello
I am using fpdf to generate pdf files based on certain csv files. Now the client wants certain fields of the generated pdf file to be 'interactive' .
Is this possible ? Googling about editable (interactive pdf's) only confused me . any help ?
btw by interactive I mean fields that can be typed into directly by the client and then saved into the pdf .
Hi.. I have code for auto generate but I got encountered problem that the SR number did not generate they still 120330001 even though I already save that SR number in my database. I want to happen is after I click the save button the SR number will be 120330002. here is my code: Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sql = "SELECT sr_number FROM receiving_materials ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_num'],0,3)); $currentSRYear = (int)(substr($row['sr_num'],2,2)); $currentSRMonth = (int)(substr($row['sr_num'],0,2)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); if ($currentYear == $currentSRYear) { if ($currentMonth == $currentSRMonth) { $currentSRNum = $currentSRNum + 1; } if ($currentMonth > $currentSRMonth) { $currentSRNum = 1; } if ($currentDay > $currentSRDay) { $currentSRNum = 1; } } if ($currentYear > $currentRefYear) { $currentSRNum = 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $yearMonth . sprintf("%04d", $currentSRNum); $sr_date = $_GET['sr_date']; $sr_number = $_GET['sr_number']; $si_num = $_GET['si_num']; $s_name = $_GET['s_name']; $po_num = $_GET['po_num']; $qty = $_GET['qty']; $mat_code = $_GET['mat_code']; $mat_desc = $_GET['mat_desc']; $wh_code = $_GET['wh_code']; $bin_loc = $_GET['bin_loc']; ?> <html> <title>Stock Requisition</title> <head> <style type="text/css"> #ddcolortabs{ margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs a span{ float:none; } #ddcolortabs a:hover{ background-color: #678b3f; } #ddcolortabs a:hover span{ background-color: #678b3f ; } #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style> #SR_date{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #SR_number{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 410px; top : 10px; } table { margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: .9em; border: 1px solid #DDD; } th { font-family: Arial, Helvetica, sans-serif; font-size: .7em; background: #694; color: #FFF; padding: 2px 6px; border-collapse: separate; border: 1px solid #000; } td { font-family: Arial, Helvetica, sans-serif; font-size: .7em; border: 1px solid #DDD; text-align: left; } #RequestedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #ApprovedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #ReceivedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #SI_number{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 10px; width: auto; height: auto; float: left; top : 20px; } .LLabelRM { display: block; float: left; width: 7em; margin-right: 10px; } .LLabelSecRM { display: block; float: left; width: 7.7em; margin-left : 0px; } .LFieldRM { float: left; margin-right: 595px; } .LFieldSecRM { float: left; margin-right: 15px; } .LFieldSec1RM { float: left; margin-right: 350px; } #save_btn { position: relative; top: 25px; margin-left: 7px; } </style> <script type="text/javascript"> function save_rm(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var si_num = document.getElementById("si_num").value; var s_name = document.getElementById("s_name").value; var po_num = document.getElementById("po_num").value; var qty = document.getElementById("qty").value; var mat_code = document.getElementById("mat_code").value; var mat_desc = document.getElementById("mat_desc").value; var wh_code = document.getElementById("wh_code").value; var bin_loc = document.getElementById("bin_loc").value; document.receiving_form.action="ReceivingMaterialsSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&si_num="+si_num+ "&s_name="+s_name+"&po_num="+po_num+"&qty="+qty+"&mat_code="+mat_code+"&mat_desc="+mat_desc+"&wh_code="+wh_code+ "&bin_loc="+bin_loc; document.receiving_form.submit(); } </script> </head> <body> <form name="receiving_form"> <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li id="current"><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>RM# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="9" readonly="readonly" style="font-weight: bold; border: none;"> </div> <div id="SI_number"> <label class="LLabelRM">SI/DR# :</label> <input type="text" name="si_num" id="si_num" class="LFieldRM" value="" size="25"> <label class="LLabelRM">Supplier Name :</label> <input type="text" name="s_name" id="s_name" class="LFieldRM" value="" size="25"> <label class="LLabelSecRM">PO # :</label> <input type="text" name="po_num" id="po_num" class="LFieldSecRM" value="" size="25"> <label class="LLabelSecRM">Quantity :</label> <input type="text" name="qty" id="qty" class="LFieldSec1RM" value="" size="25"> <label class="LLabelSecRM">Material Code :</label> <input type="text" name="mat_code" id="mat_code" class="LFieldSecRM" value="" size="25"> <label class="LLabelSecRM">Material Desc. :</label> <input type="text" name="mat_desc" id="mat_desc" class="LFieldSec1RM" value="" size="25"> <label class="LLabelSecRM">WH Code :</label> <input type="text" name="wh_code" id="wh_code" class="LFieldSecRM" value="" size="25"> <label class="LLabelSecRM">BIN Location :</label> <input type="text" name="bin_loc" id="bin_loc" class="LFieldSec1RM" value="" size="25"> </div> <div id="save_btn"> <input type="button" name="save" value="save" onclick="save_rm()"> </div> </form> </body> </html> <?php $sql = "INSERT INTO receiving_materials (sr_date, sr_number, si_num, s_name, po_num, qty, mat_code, mat_desc, wh_code, bin_loc) VALUES ('$sr_date', '$sr_number', '$si_num', '$s_name', '$po_num', '$qty', '$mat_code', '$mat_desc', '$wh_code', '$bin_loc') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', si_num = '$si_num', s_name = '$s_name', po_num = '$po_num', qty = '$qty', mat_code = '$mat_code', mat_desc = '$mat_desc', wh_code = 'wh_code', bin_loc = '$bin_loc'"; $res_receiving = mysql_query($sql, $con) or die(mysql_error()); ?> any help is highly appreciated. Thank you Hi, I have a script to add images to my tabel and and upload them to my server, I have managed to get the upload script to rename the image with a 5 digit random number on the end to prevent overwriting, the only problem I can't seem to be able to add the same name to my tabel. Any ideas? Thanks in advance. Code: [Select] <?php $idir = "uploads/"; // Path To Images Directory if (isset ($_FILES['fupload'])){ //upload the image to tmp directory $url = $_FILES['fupload']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload']['type'] == "image/jpg" || $_FILES['fupload']['type'] == "image/jpeg" || $_FILES['fupload']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['fupload']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload']['tmp_name'], $idir. basename($_FILES['fupload']['name'], $file_ext).rand(10000 , 99999).$file_ext); // Move Image From Temporary Location To Perm } } if (isset ($_FILES['fupload2'])){ //upload the image to tmp directory $url = $_FILES['fupload2']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload2']['type'] == "image/jpg" || $_FILES['fupload2']['type'] == "image/jpeg" || $_FILES['fupload2']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['fupload2']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload2']['tmp_name'], "$idir" . $_FILES['fupload2']['name'] $file_ext).rand(10000 , 99999).$file_ext); // Move Image From Temporary Location To Permanent Location } } if (isset ($_FILES['fupload3'])){ //upload the image to tmp directory $url = $_FILES['fupload3']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload3']['type'] == "image/jpg" || $_FILES['fupload3']['type'] == "image/jpeg" || $_FILES['fupload3']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['fupload3']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload3']['tmp_name'], "$idir" . $_FILES['fupload3']['name'] $file_ext).rand(10000 , 99999).$file_ext); // Move Image From Temporary Location To Permanent Location } } if (isset ($_FILES['fupload4'])){ //upload the image to tmp directory $url = $_FILES['fupload4']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload4']['type'] == "image/jpg" || $_FILES['fupload4']['type'] == "image/jpeg" || $_FILES['fupload4']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['fupload4']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload4']['tmp_name'], "$idir" . $_FILES['fupload4']['name'] $file_ext).rand(10000 , 99999).$file_ext); // Move Image From Temporary Location To Permanent Location } } $usr = "user"; $pwd = "pass"; $db = "db"; $host = "host"; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } if ($_POST['submit']) { $logo = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']); $image1 = mysql_real_escape_string("$idir" . $_FILES['fupload2']['name']); $image2 = mysql_real_escape_string("$idir" . $_FILES['fupload3']['name']); $image3 = mysql_real_escape_string("$idir" . $_FILES['fupload4']['name']); $SQL = " INSERT INTO mhhire "; $SQL .= " image1, image2, image3, logo) VALUES "; $SQL .= " ('$image1', '$image2', '$image3', '$logo') "; $result = mysql_db_query($db,$SQL,$cid); $last=mysql_insert_id(); if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } header("location:thanks.php"); exit(); } ?> Hi all, I am using php to allow users to create a new directory e.g. www.website.com/theirname/ and would like to auto generate an index.php (or index.html) page if possible within this directory. Any tips on how to do it would be appreciated. The code I have for generating the directory is: <?php function handleError() { trigger_error('MY ERROR'); /** usage sample @handleError(); echo $php_errormsg; */ } // detect slash/backslash nomenclature dirname $path = dirname( __FILE__ ); $slash = '/'; (stristr( $path, $slash )) ? '' : $slash = '\\'; define( 'BASE_DIR', $path . $slash ); $folder = $_POST['reg']; // folder name $dirPath = BASE_DIR . $folder; // folder path // print results echo $slash; echo '<hr>'; $rs = @mkdir( $dirPath, 0777 ); @handleError(); if( $rs ) { // print success information echo 'was done!'; echo '<br>folder: <a href="' . $folder . '">' . $folder . '</a>'; echo '<br>dirPath: ' . $dirPath; }else{ // print error information echo "This webpage <b>www.website.com/".$folder."</b> appears to have been already been created. Please try another web name. If the problem persists please report it to us."; } ?> |