PHP - Creating A Test Script And Htm Page - Not Writing To Table
PHP code:
Code: [Select] <? //login variable $username = $_POST ['username']; $password = $_POST ['password']; $database = $_POST ['database']; //table variable $table = $_POST ['table']; //stats variables $name = $_POST ['name']; $force = $_POST ['force']; $armor = $_POST ['armor']; $strength = $_POST ['strength']; $value = $_POST ['value']; mysql_connect ("localhost","$username","$password"); @mysql_select_db ($database) or die ("no database name"); $query = "INSERT INTO `$database`.`$table` ('name', 'force', 'armor', 'strength', 'value') VALUES ('$name', '$force', '$armor', '$strength', '$value')"; mysql_query ($query); if (mysql_query($query)) { die('Error: ' . mysql_error()); } echo "1 record added<br>"; echo "<br>variable $name test"; echo "<br>variable $force test"; echo "<br>variable $armor test"; echo "<br>variable $strength test"; echo "<br>variable $value test"; mysql_close(); ?> HTML files code: Code: [Select] <form action = "datainput.php" method = "post"> <div align="center">Item Submission Form</div><br><br> <br> <div align="center"><input type="text" name="table" value="head neck back or chest" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="name" value="Type Name Here" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="force" value="Type force number" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="armor" value="Type armor value" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="strength" value="Type strength value" size="32" maxlength="32"></div> <br> <br> <div align="center"><input type="text" name="value" value="Type cost Here" size="32" maxlength="32"></div> <br> <br> <br> <div align="center"><input type="text" name="username" value="username here" size="32" maxlength="32"></div> <br> <div align="center"><input type="text" name="password" value="password here" size="32" maxlength="32"></div> <br> <div align="center"><input type="text" name="database" value="database Here" size="32" maxlength="32"></div> <br> <div align="center"><input type="submit" name="Submit_button" value="Submit"></div> </form> What is funky is the page seems to work, it says it writes a record but the record never appears in the database. I did verify MIME types were correct for HTML to be allowed to write as php if needed, any idea why it wouldn't create a record? Similar TutorialsHey guys i've been trying to find out how to create and and write in a file, so that you can for example add a nav button to your website by form (you know like a admin panel). It tried some things but it doesnt work cause it wont write to the file... here is the code i've used: $ourFileName = $_POST['sitename']; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); $myFile = $_POST['sitename']; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "test\n"; fwrite($fh, $stringData); $stringData = "test\n"; fwrite($fh, $stringData); fclose($fh); the "sitename" is the id from the form where you choose what the menu tab should be called. I would really glad if you could help me out with this one thanks! MinG I got this script for change language and don't know is it working. In this array are supported language s for this site, so if you come from some of this 7 country should open your language, for others english version. Don't know any other way to test it! http://www.lacman.hr/index.php Code: [Select] $jezici = array("hr", "en", "de", "it", "fr", "cz", "pl"); Is there any php function I can test how fast my server is performing, like how fast its carrying out a certain action so I can see its resource usage. In the database, I have a table called 'users' inside that I have email, nick (aka username), and balance. The individual aspects are set up, and work. My site is also successfully connecting to and reading / writing info in the database. So my question is: How would I go about having a box on the register page called 'refer' where the person would enter their referrers email (or nickname, one or the other) then it finds that person, and puts a value of 10 in 'balance'. Anyone with more experience than me have any ideas? All help is greatly appreciated. Hi All, I need some help blocking files that don't pass authentication from being uploaded to the server. Here is my script (below). It correctly throws errors, but regardless of error / no-error, the file is uploaded. For example, the only files allowed to be uploaded should be .png, .jpeg, .gif -- but I see .flv .docx etc in the destination folder. You'll see below a variable for each of the error messages. They basically say that the file name is too long, too big, not an allowed file type, or English characters only allowed in file title name. Again the errors work properly, but regardless files are uploaded to the "quiz_images" folder. What do I need to do to stop the upload if an error is triggered? Thank you for your help... here is the code snip: Code: [Select] $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'quiz_images/'; $fieldname = 'file'; if ($_POST[submit]) { if ($_POST[title] <> "") { $a = TRUE; } else { $a = FALSE; $content .= "<p>$enter_title</p>\n"; } if ($_POST[video] <> "") { $b = TRUE; } else { $b = FALSE; $content .= "<p>$enter_embed</p>\n"; } if ($_POST[description_text] <> "") { $c = TRUE; } else { $c = FALSE; $content .= "<p>$enter_description</p>\n"; } if ($_POST[submit] <> "") { $f = TRUE; } else { $f = FALSE; $content .= "<p>$sorry_error</p>\n"; } if (is_uploaded_file($_FILES[$fieldname]['tmp_name'])) { $g = TRUE; } else { $g = FALSE; $content .= "<p>$sorry_error</p>\n"; } if (getimagesize($_FILES[$fieldname]['tmp_name'])){ $h = TRUE; } else { $h = FALSE; $content .= "<p>$error2</p>\n"; } if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 50000)) { $i = TRUE; } else { $i = FALSE; $content .= "<p>$error2</p>\n"; } if(preg_match('#^[a-z0-9_\s-\.]*$#i', $pic) ) { $k = TRUE; } else { $k = FALSE; $content .= "<p>$error3</p>\n"; } $desc_length = strlen($pic); $limit = 40; if ($desc_length <= $limit) { $l = TRUE; } else { $l = FALSE; $content .= "<p>$error4</p>\n"; } $now = time(); while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])) { $now++; } if (move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)){ $j = TRUE; } else { $j = FALSE; $content .= "<p>$enter_thumb</p>\n"; } $pic=$now++.'-'.$_FILES[$fieldname]['name']; if ($a AND $b AND $c AND $f AND $g AND $h AND $i AND $j AND $k AND $l) {............ Hello. I have one programming problem. I have this log, from witch i have to read specific area of text: webtopay.log OK 123.456.7.89 [2012-03-15 09:09:59 -0400] v1.5: MIKRO to:"1398", from:"865458961", id:"13525948", sms:"MCLADM thing" So i need the script to extract word "thing" from that log. Also that script has to check if there is new entries in the log, and extract text from the last one. (Explaining in other words, that script should extract word AFTER MCLADM. Every time its a different word) p.s. I need that script to be integrated here (this has to send command to server "/manuadd (text from log)" : Code: [Select] <?php try{ $HOST = "178.16.35.196"; //the ip of the bukkit server $password = "MCLietuva"; //Can't touch this: $sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("error: could not create socket\n"); $succ = socket_connect($sock, $HOST, 4445) or die("error: could not connect to host\n"); //Authentification socket_write($sock, $command = md5($password)."<Password>", strlen($command) + 1) or die("error: failed to write to socket\n"); //Begin custom code here. socket_write($sock, $command = "/Command/ExecuteConsoleCommandAndReturn-SimpleBroadCast:broadcast lol;", strlen($command) + 1) //Writing text/command we want to send to the server or die("error: failed to write to socket\n"); sleep(2); // This is example code and here has to be that script i want to make. //while(($returnedString = socket_read($sock,50000))!= ""){ $returnedString = socket_read($sock,50000,PHP_NORMAL_READ); print($returnedString) //} print("End of script"); socket_close($sock); }catch(Exception $e){ echo $e->getMessage(); } ?> I hope i made things clear and you will help me Thanks I'm working with little php background here and trying to write mysql table data to a text file. So far what I have is... $query = "SELECT * FROM `list` "; $result = mysql_query($query) or die("Query failed : " . mysql_error()); while ($line = mysql_fetch_array($result)) { $file = "export.txt"; $fhandle = fopen($file, 'w') or die("can't open file"); $stringdata = $line["listid"]. "\n"; fwrite($fhandle, $stringdata); //write to text file fclose($fhandle); } All this does is write the very last row in my table to the text file. If I switch fwrite to the 'a' mode, it works... but I don't want it to append to existing data. Ideally I'd like to wipe any contents in the existing text file clean before adding all new data from the query. Any thoughts? Thanks for the help! so what i have going on is that i need help writing a basic script to upload original and copy with resize for thumbnail. then also need to rename both image files with content in the form. My server supports GD Library and that imagemagik or whatever it is lol. upload dirs orig: ../media/photos/ thumb: ../media/photos/thumb/ mySQL DB: name: m_photos fields: id(INT) m_cat(varchar) m_sub_cat(varchar) pic(varchar) description(varchar) p_group(varchar) I have the form written up for how it should look like: Code: [Select] <form action="upload.php" method="post" enctype="multipart/form-data"> Upload an image for processing<br /> <input type="file" name="Image"><br /> <select name="sub_group"> <option value="Photo Shoot">Photo Shoot</option> <option value="Live Performances">Live Performances</option> <option value="Randoms">Randoms</option> <option value="Fan Photos">Fan Photos</option> </select><br /> Location: <input type="text" name="p_group" /><br /> Date of Pic: <input type="text" name="date" /><br /> Description: <input type="text" name="description" /><br /> <input type="submit" value="Upload"> </form> so what needs to happen is for the file upload name. it needs to grab a count from "p_group" database to give it a starting number in a "00" pattern and then the date of pic needs to go in there next then the p_group name. so when the files gets uploaded it would look something like this after upload. "03 - Oct 21, 2011 - The Mex.jpg" NOTE: all pics must be converted to ".jpg" extension. both the orig and thumb will use that same file name cuz they just go into different dirs re-sizing for the thumbnail should be done by aspect ratio and needs to either be 300px width or 400px height. so if anyone would like to help me out please do. im not the greatest at writing in php yet Hi
I come from a desktop (vb.net) background and have used oridinary text files for my databases. I use file locking to prevent other processes from writing to the same file simultaneously.
Now I am moving over the PHP/MySQL - what precautions should I take to stop a simultaneous processes from writing to a table at the same time.?
Do I need to lock the table before writing to it?
Does MySQL deal with this automatically and just block my process until the table becomes free?
(I am talking about a single table here, not multiple dependant tables - I know that is another issue)
Thanks
Nigel
Hi all, hope some can help because this is giving me more grey hairs than I allready have.
I am trying to solve the following: I'm pulling in JSON data, decoding it to a array which I write to a database. However in the array are social security numbers that I don't want to store (privacyregulations). So I need to check if a row has a social security number and if it has one I want to replace it with 'anonymized'. I have got it to work successfully on a local Xampp test environment using the following script (extract off course): //first anonymize the social security number (ssn) if exists $data = json_decode($jsondata, true);
// then fill the tables foreach($data as $row) {
$insertstatement = mysqli_query($link,"INSERT INTO $tablename (personid, type, ssn) VALUES ('".$row["personid"]."', '".$row["type"]."', '".$row["ssn"]."') ON DUPLICATE KEY UPDATE type = VALUES(type), bsn = VALUES(ssn)");
This leads to a filled table where the ssn's are filled with 'anonymized' if they exist in the array and empty if it does not exist for that row. This is exactly what I want ;-).
Personid type ssn
However, when I run the same script on a Lamp production environment (lamp stack on an Azure server) it does not work. Then the scripts results in totally ignoring the whole row that contains a ssn??
Personid type ssn Hope someone can help to get this working on my production environment as well.
Richard
Hi again.... I'm working on a project that creates a profile page for the user (i.e. 'username.php') when they register. Because there are two ways to register, through Facebook and through the website itself, there has to be an if statement in this page that it crates as to which ID to use for that user. Because Facebook usernames are not unique, we must identify a user through their OAuth User ID which is a 10 digit number. When a user registers through the website itself, usernames are unique so their profile page can be ID'd by their username. Here's the code that creates that profile page: function createProfile($user) { $userFile = 'users/'.$result['oauth_uid'].'.php'; $fh = fopen($userFile, 'w') or die("can't open file"); $stringData = "<?php\n" . '$pageowner = "' . $result['oauth_uid'] . '";' . "\n" . 'include "profile.php";' . "\n?>"; fwrite($fh, $stringData); fclose($fh); } $user is the username passed to the function when it's called. Currently that is set to create a line of code in the new profile page ('userid'.php) that looks like this: <?php $pageowner = "100001745088506"; include "profile.php"; ?> I want to add an IF to that page that follows this structu if oauth_provider == facebook { $pageowner = "oauth_uid" } else { $pageowner = username } But I don't know how to write that he $stringData = "<?php\n" . '$pageowner = "' . $result['oauth_uid'] . '";' . "\n" . 'include "profile.php";' . "\n?>"; to make it show up in the page it creates. I want that if statement to be written IN the page that is created. I just don't know the syntax well enough yet to do that. Would somebody help me out or point me in the right direction? Thanks! I would like to create a Job Numbering system for all of my jobs. Job number format : print-001232 I would like the job numbers to be sequential. So we will have a drop down list with three categories. which will form the first part of the job number. (print- ) and then I would like the 6 digits after it to be sequential starting from 000001. What is the best way of going about doing this? I am using a simple email script called PHPmailer which works great but i would like to create a form so a user can input what the text for the email should be along with the subject from texts boxes, i also need the script to connect to a mysql database to get a list of email address to send to. Then once the user presses the send button the email is sent out to everyone in the database. Can anyone help me? <?php include_once('class.phpmailer.php'); $mail = new PHPMailer(); $body = eregi_replace("[\]",'',$body); $mail->IsSendmail(); // telling the class to use SendMail transport $mail->From = "zac@zpwebsites.com"; $mail->FromName = "First Last"; $mail->Subject = "PHPMailer Test Subject via smtp"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress("zacthespack@gmail.com", "John Doe"); $mail->AddAttachment("uploads/AleMail.pdf"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> Hi all. I work at a university library where I am the default web coding person. Although I know far more than anyone else who works here, my skills are not exactly at the guru level. At the moment I'm fighting with libcURL, trying to use a (secured) submission form to upload files from faculty to a remote server. (Of course, I had one that worked which uploaded to a safe directory on our web server, but that was deemed insufficient. ) I have managed to connect to the FTP server with cURL, and I have managed to create files on that server which have the same name as the files uploaded in the form. However, for some reason that escapes me, the files created on the FTP server are empty files. The server is using Server 2003 and IIS 6, and I am able to successfully upload to it using Filezilla, so I suspect the problem is with my code. I have searched Google for help with this, but all I can get is examples of how to upload which are the same as the one I already have, and how to delete a file using cURL, which is not what I want to do. The problem does seem to be somewhere in the file transfer process. die($_Files['syllabus']['size']); gives me the correct file size, and I tried moving the file onto the (local) webserver before transfering it via FTP, and the server one was fine--the FTPed version still showed up empty. If anybody has any idea what's going on, your help would be greatly appreciated. //the syllabus file from the form $syllabus=$_FILES['syllabus']['name']; //the syllabus as it will appear on the server (to make it a clickable link in the e-mail sent //to our processing librarian later in the script. Removing this did not fix the problem anyway.) $REMsyllabus = str_replace(' ', '-', $_FILES['syllabus']['name']); //formatted URL, with FTP information defined just before the syllabus and REMsyllabus files. $SYLremoteurl = "ftp://${ftpuser}:${ftppasswd}@${ftpserver}/${REMsyllabus}"; $ch = curl_init(); $fp = fopen($syllabus, 'r'); curl_setopt($ch, CURLOPT_URL, $SYLremoteurl); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, $_FILES['syllabus']['size']); curl_exec ($ch); $error_no = curl_errno($ch); curl_close ($ch); if ($error_no == 0) { $error = 'File uploaded succesfully.'; } //if else { $error = 'File upload error: '.$error_no; }//else } //if else { $error = 'No syllabus file selected.'; }//else This is pretty much the example code from the libcURL PHP section web page, so I'm not entirely sure why it doesn't work. Thanks in advance for any help anybody can offer! $sql = "SELECT * FROM `users` WHERE `emailAddress` = '".mysql_real_escape_string($_POST['email'])."' AND `password` = '".mysql_real_escape_string(md5($_POST['password']))."'"; I currently have it accepting just the email address but I want it to be the email address OR the username. How do I do this? Hi there, trying to create a function more out of lazyness an timesaving than anything im sure it has to do with something combining the use of INSERT and x++ in an array, but im failing at figuring out the right way of doing it to achieve the right combination of effects. in simple need to create a 600x600 grid of co-ordinates where x starts at 1, ending in 600 with y starting at 1 and ending in 600 so basically a cubed set of entrys, (360,000 rows) not even sure thats possible lol.. the table only needs to contain the colums of id, x , y , ownerid (where id is auto inc) any suggestions, as you can tell its a pain-staking long case of affairs to create with a manual VERY long sql statement, trying to figure out a better way of doing this. help please? Thanks What I want to do is create a table out of records from a table that shows an image and a radio button under the image (so I would imagine it would be in 2 rows). I want it to have 3 columns across. Here's what I have to get and output the results: $fabricsql = "SELECT * FROM Fabric f, Images i WHERE f.SKU = i.SKU"; //echo $fabricsql; $fabricResult = mysql_query($fabricsql); $i=0; while($fabricAssoc = mysql_fetch_assoc($fabricResult)){ //echo $fabricAssoc['SKU']. "+ ".$fabricAssoc['Name']; echo "<a href=\"\"><img src='../../".$fabricAssoc['ThumbPath']."' alt='".$fabricAssoc['Description']."' width='".$fabricAssoc['ThumbWidth']."' /></a><br /> <input type=\"radio\" name=\"fabricSelect\" value='".$fabricAssoc['SKU']."' id=\"RadioGroup1_".$i."\" /><br /><br />"; $i++; } Any help is much appreciated. I'm not even sure this is the best way to go about this so any suggestions are appreciated. It's about making a form for a web page. Which is better? Using table or divs? Which do you use? <form action='a.php' method='post'> <table> ............. </table> </form> <form action='a.php' method='post'> <div> ............. </div> </form> Hi guys, i cannot figure out what is wrong with this and I hope you could help figure it out? This is the code I am using - Code: [Select] $create_cart_table = "CREATE TABLE `". $string ."` (cart_id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(cart_id), item_name VARCHAR(1000) NOT NULL, item_id VARCHAR(30) NOT NULL, price VARCHAR(30) NOT NULL, date_time TIMESTAMP(100) NOT NULL CURRENT_TIMESTAMP, quantity VARCHAR(100) NOT NULL)"; $set_cart_table = mysql_query($create_cart_table); $string is defined above and there are no database connection warnings etc coming up and I am lost as to how the heck this isn't working? It was working for about an hour when I first made the script but now it is not. Please help? I have a string (Product1-Product2-Product3#2-4-1) where Product1-Product2-Product3 are products and 2-4-1 are quantities. I am struggling to make a table out of it where products and quantities are shown in rows. here is what i tried. Code: [Select] list($products, $quantities) = explode("#", $specs); //to separate Quantities from products <?php foreach(preg_split("/-/", $products) as $product_list) { ?> <tr> <td> <?php echo $product_list; ?></td><? } ?> <?php foreach(preg_split("/-/", $quantities) as $qtylist) { ?> <td></td> <td><?php echo $qtylist; ?></td> <?php } ?> </tr> <?php //} ?> </table> I know something is wrong with this and its giving me unexpected reasult Please help me create a table out of the above string. Many Thanks -Max |