PHP - Question About After A Script Is Executed
so a user fills out a form, data gets sent to send.php then if successful redirects back to index.php, how on that index.php can i get it to say, sent successfully?
Similar TutorialsHi all I have this problem on a server using php5, unix based, safe_mode is On globally, i have turned it off locally through php.ini. Ok, this is testing example script i used: $cmd = ( "php -v" ); $out = shell_exec( $cmd ); print $out; On my own server this returns php version. On this mentioned server i'm using (commercial) this causes complete server breakdown, when logged in with SSH, i can't even issue "ls" command after that, nor find and kill the process. What could be so wrong with it? I don't think calling php-cli would make any difference. I have a games website called GPStudios.com. In a previous topic (that remains unresolved) I needed help fixing a view counter on a specific page that was sometimes executing a mysql query twice. I've since noticed that it is happening on other pages, maybe all of them. At the top of the php "playgame.php", is the statement: $updatesql = "update games set timesplayed = timesplayed+1, last_played = now() where gameid = $gameid"; mysql_query($updatesql); However, when I reload the page or check on phpMyAdmin, it has sometimes incremented by 2 (possibly 3). I have confirmed that no where else is calling the same query. I created a new table called "FUCK" and editted the code stated above to: $updatesql = "update FUCK set timesplayed = timesplayed+1, last_played = now() where gameid = $gameid"; mysql_query($updatesql); Upon loading the page, it did exactly the same thing. So I confirmed that the PHP must be being run twice. I have tried it on other pages on my website such as I had no luck on my other topic of the same problem, but hopefully someone might be able to tell me why or how this might be happening. Just remember - it is an absolute certainty that the query is NOT being run elsewhere. Thanks. Hello, I create tracking code file named "get_t.php". I call it using javascript: <script language='javascript' type='text/javascript'> var r=document.referrer; var counter = new Object(); counter.src = 'http://MyWebSite.com/get_t.php?aid=55&lid=F29&r='+r; </script><script src=http://MyWebSite.com/get_t.php?aid=55&lid=F29> </script> In this file all I do is to print "Hello World". Now, everything works fine most of the time. but sometimes the file does not executed for some reason, and empty page is displayed without showing message "Hello World". Please advice. Thanks, I have a function with a query and then a while loop and then an if file_exists with an image path. I am getting the image path displayed as text. Would this be because I am running the query through json encoding? Hi, we are trying to make a marketing wheel. This means we got a database with lots of persons in it each with a individual email adres. The simel example of how the basic database looks is seen in the picture below. This table is called "Clicks" As you might notice the field "Aan" is either a 0 or a 1. This is how it works, when someone fills in a form on the website asking for more information the form with all the personal information of this person is send to a random email adres found in this table. When this happens the field "Aan" changes from 0 to 1 this way we can make sure that the same person does not get a email again until everyone else has been used 1 time. So in other words until that the field "Aan" is value 1 for every person in the table. As you might have guessed this is sadly enough not working ... this is our code : Code: [Select] include_once('connection.php'); $data = array(); $i = 0; $result1 = mysql_query("SELECT * FROM `Clicks` WHERE Aan = 0"); while ($list1 = mysql_fetch_array($result1,MYSQL_ASSOC)) { if (empty($list1) ){ mysql_query("UPDATE `Clicks` SET `Aan`= 0 WHERE `Aan` = 1"); } $result = mysql_query("SELECT * FROM `Clicks` WHERE Aan = 0 ORDER BY RAND() LIMIT 1"); while ($list = mysql_fetch_array($result,MYSQL_ASSOC)) { foreach ($list as $key => $value) { // Met htmlentities() voorkom je dat html wordt uitgevoert. $value = htmlentities($value); $data[$i][$keyl] = $value; } $i++; } } mysql_free_result($result); $data = array_reverse($data); // Zet de nieuwste berichten bovenaan // in plaats van onderaan. $cnt = count($data); for($i = 0; $i < $cnt; ++$i) { $bericht = $data[$i]; echo(nl2br($bericht['bericht'])); // Met nl2br() worden alle enters in het // bericht omgezet naar <br/>. echo('</td></tr></table>'); $naarwie= $bericht['Email']; }mysql_query("UPDATE `Clicks` SET `Aan`= 1 WHERE `Email` = $naarwie"); mysql_close($Verbinding); // Sluit de verbinding. // We hebben hem nu niet meer nodig. So this code in short explained would be. It checks if all the "Aan" fields are on 0 if the list is empty so it means they are all on 1 he will reset all the fields of every user to 0. and then he will take a random person out and send the email to that person. And after the mail is send will change that person his value on "Aan" to value 1. Now if the list is not empty, that means there are still persons with value 0 in the list. Then he will take a random user out of all the persons who have "Aan" with value 0 send the mail to that user and change his "Aan" value to 1. This process will be repeated every time someone asks for information until all values of all users are on 1. And then again he will change them to 0 for everyone. I hope its clear what we are looking for. And I hope someone can help us out. We are clueless... When I try to upload a file larger than the server's max limit, the following code is not executed. How am I supposed to inform the user that their file is too large? NOTE: I've stripped the code down for this post. Code: [Select] <?php if(isset($_POST['submit'])) { echo "test.."; } ?> <html> <head> <title>Upload Test</title> </head> <body> <form action='' enctype='multipart/form-data' method='POST'> <input type='file' name='file_upload' /> <input type='submit' name='submit' value='upload' /> </form> </body> </html> Hello all
I'm new to this forum. I've been struggling on this problem for a few days now.
I’m writing a script to automatically push code to a git server. exec(‘git config user.name "’ . $userName . ‘"’); exec(‘git config user.email "’ . $userEmail . ‘"’); exec('git checkout -b ’ . $branch); exec(‘git add --all’); exec(‘git commit -m "’ . $message . ‘"’); exec('git push origin ’ . $branch);
When running the last command, the script stops and asks for a user name, then a password. I tried other forums, searching the net. I'm frustrated...
Thanks in advance. Say a script has ignore_user_abort(true); set. If the user aborts the connection and print is called, the buffer doesn't get written anywhere. So shouldn't print() return false in this case? To clarify, I know it doesn't, but shouldn't it? If not, why not? Hi All, I have a form that enables the user to know events that occur in a specific city. Most of the time they get the results in a few seconds, despite the fact that many rows in various tables might be searched for detailed infos about the events in that city. However, this form partly relies on a table against which a MySQL event regularly does some operations. If the user uses the form while the event is being executed, they have to wait up to 30 seconds before getting the results, and sometimes only part of the html page is generated. Is there a way to avoid this lengthy waiting time ? I am wondering whether or not the best would be putting the site on maintenance while the event is being executed, with a "please come back in a few minutes" message. Thanks in advance for your help. Hey, So I have a couple of files, and I'm trying to create a login script. There is a MySQL query that accesses a database with a list of usernames and passwords. I have a feeling something is wrong with my SQL query, because it's not working correctly. Code: [Select] <?php $connect = mysql_connect("localhost", "root", "root"); if(!$connect){//If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } mysql_select_db("colin_db", $connect); //Get given username and password from username field and password field $givenUsername = $_POST["usernameField"]; $givenPassword = $_POST["passwordField"]; $myQuery = "SELECT * FROM ADMINS WHERE USERNAME = $givenUsername AND PASSWORD = $givenPassword"; $queryResult = mysql_query($myQuery); $numRows = mysql_num_rows($queryResult); if($numRows == 1){ //If the details are correct... //Reload the page and login echo "<script type = 'text/javascript'> window.location.reload() </script>"; echo "Details correct"; } elseif($numRows == 0){ //Else if the details are not found //Display error accordingly echo "Details not correct!"; //This is what happens every time } mysql_close($connect); ?> The database is configured correctly, but I'm not sure how to correctly create a SQL query to determine if the given username and password are correct. In case you'd like to see it, the segment from the index.php file is below. Code: [Select] <form action = "login.php" method = "POST"> Admin Login: <br> Username: <input type = "text" name = "usernameField"/><br> <!-- Password field--> Password: <input type = "password" name = "passwordField"/><br> <!-- Username field --> <input type = "submit" value = "Login" name = "submitButton"/> <!-- Login button --> </form> Any ideas? Thanks, Jake Hi, My name is Karel van der Veen. I am trying to creat a script for a quiz on my website but I am stuck. I was hoping you might have an idea for the solution. The idea is a page with a picture and multiple choice questions about that picture. For example a picture of a bike. Question 1: what colour is the bike? --> choices are green, red, blue. Question 2: what shape are the wheels? --> round, square. I have made a script that compares the answers given by the student, with the correct answers I put in the database corresponding with the bike on the picture. If the student has it right, than after clicking on "next", the "correct answer" page will load. If he made a mistake a "wrong answer" page will load. So far the script works. But what I would like to happen is if the student gives a wrong answer, that after clicking on the `next` button, he will go back to the front page where the picture and the questions are with a sign or mark around the question he answered wrong, so he knows what question he had wrong and has to answer again. Below is the script I have so far. Do you know what I have to change or to add to the script? regards Karel Code: [Select] script of the question page: <?php $array_vorm = Array("rond","vierkant"); $array_kleur= array("rood","blauw","groen"); $array_grootte = array("4x4","8x8"); ?> <form method="post" action="results.php"><br /> <div id="vorm"> <div id="vorm1"><img src="images/vorm.gif" alt="vorm" width="75" height="75" class="vorms" /></div> <div id="vorm2"> <table> <tr><td> <label class="vormhead">VORM</label><br> <select name="form_vorm[]" class="randmenu" size="4" multiple > <option><?php echo implode("</option><option>",$array_vorm); ?></option> </select> </td></tr> </table> </div> </div> <div id="kleur"> <div id="kleur1"><img src="images/kleur.gif" alt="vorm" width="75" height="75" class="kleur" /></div> <div id="kleur2"> <table> <tr><td> <label class="kleurhead">KLEUR</label><br> <select name="form_kleur[]" class="randmenu" size="4" multiple > <option><?php echo implode("</option><option>",$array_kleur); ?></option> </select> </td></tr> </table> </div> </div> <div id="grootte"> <div id=" grootte 1"><img src="images/ grootte .gif" alt="vorm" width="75" height="75" class=" grootte " /></div> <div id=" grootte2"> <table> <tr><td> <label class=" grootte head">GROOTTE</label><br> <select name="form_ grootte []" class="randmenu" size="4" multiple > <option><?php echo implode("</option><option>",$array_ grootte ); ?></option> </select> </td></tr> </table> </div> </div> <input type="submit" class="zoekbalk" value="zoeken" /> And this is the script of the result page: <?php error_reporting ( E_ALL | E_STRICT ); ini_set ( 'display_errors', 1 ); ?> <?php include 'connect.php'; ?> <?php $geenbeschrijving = "De beschrijving is onjuist. $geenselectie = "Je hebt geen selectie gemaakt, maak eerst een selectie en klik dan op zoeken. <br/><br/> $antwoord = "Antwoord: "; $diagnose = "Beschrijving: "; $diagnose2 = "Diagnose: "; $vormeggo = "Vorm: "; $kleureggo = "Kleur: "; $grootteeggo = "Grootte: "; $array_vorm = array("rond","vierkant"); $array_kleur= array("rood","blauw","groen"); $array_grootte = array("4x4","8x8"); if($_SERVER['REQUEST_METHOD'] == 'POST' ) { $query = "select * from foto1 where "; $query_init = $query; $first_option = true; if (isset($_POST["form_vorm"])){ if ($first_option == false){ $query .= " AND "; } else{ $first_option = false; } $query .= "("; for ($i=0; $i<=count($_POST["form_vorm"])-1; $i++){ if ($i == 0){ $query .= "(vorm LIKE '%".$_POST["form_vorm"][$i]."%') "; }else{ $query .= " OR (vorm LIKE '%".$_POST["form_vorm"][$i]."%') "; } } $query .= ")"; } if (isset($_POST["form_ kleur "])){ if ($first_option == false){ $query .= " AND "; } else{ $first_option = false; } $query .= "("; for ($i=0; $i<=count($_POST["form_ kleur "])-1; $i++){ if ($i == 0){ $query .= "( kleur LIKE '%".$_POST["form_ kleur "][$i]."%') "; }else{ $query .= " AND (kleur LIKE '%".$_POST["form_ kleur "][$i]."%') "; } } $query .= ")"; } if (isset($_POST["form_ grootte "])){ if ($first_option == false){ $query .= " AND "; } else{ $first_option = false; } $query .= "("; for ($i=0; $i<=count($_POST["form_ grootte "])-1; $i++){ if ($i == 0){ $query .= "( grootte LIKE '%".$_POST["form_ grootte "][$i]."%') "; }else{ $query .= " AND (grootte LIKE '%".$_POST["form_ grootte "][$i]."%') "; } } $query .= ")"; } if ($query == $query_init){ echo "<div class=\"geenbeschrijving\">" . $geenselectie . "</div>"; }else{ //echo $query."<br><br>"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)<>0) { while ( $row = mysql_fetch_assoc ( $result ) ) { echo "<div class=\"beschrijving\">" . $antwoord . "</div>"; echo "<div class=\"keuze\">" . $vormeggo . $row["VORM"]. "</div>"; echo "<div class=\"keuze2\">" . $kleureggo . $row["KLEUR"]. "</div>"; echo "<div class=\"keuze2\">" . $grootteeggo . $row["GROOTTE"]. "</div>"; </div>"; $beschrijvingquery = "select BESCHRIJVING from beschrijving where Catalog_ID=".$row["ID"]; if ($beschrijvingresult = mysql_query($beschrijvingquery)) { if (mysql_num_rows($beschrijvingresult)<>0) { while ( $beschrijvingrow = mysql_fetch_assoc ( $beschrijvingresult ) ) { echo "<div class=\"beschrijving\">" . $diagnose . "</div>"; echo "<div class=\"beschrijving2\">" . $beschrijvingrow["BESCHRIJVING"]."</div></br>"; } } else { echo "geen beschrijving<br />"; } } $diagnosequery = "select DIAGNOSE from diagnose where Catalog_ID=".$row["ID"]; if ($diagnoseresult = mysql_query($diagnosequery)) { if (mysql_num_rows($diagnoseresult)<>0) { while ( $diagnoserow = mysql_fetch_assoc ( $diagnoseresult ) ) { echo "<div class=\"beschrijving\">" . $diagnose2 . "</div>"; echo "<div class=\"beschrijving2\">".$diagnoserow["DIAGNOSE"]."<br /><br />"; } } else { echo "geen beschrijving<br />"; } } $fotoquery = "select FOTOthumb, FOTObig from foto where Catalog_ID=".$row["ID"]; if ($fotoresult = mysql_query($fotoquery)) { if (mysql_num_rows($fotoresult)<>0) { while ( $fotorow = mysql_fetch_assoc ( $fotoresult ) ) { echo "<div class=\"beschrijving4\">" .'<a title="' . $fotorow['FOTObig'] . '" href="images/big/' . $fotorow['FOTObig'] . '" rel="lightbox"><img src="images/thumb/' . $fotorow['FOTOthumb'] . '"></a></br></br><hr><hr> '; } } else { echo "<img src='geenfoto.jpg' alt='geen foto' /><br />"; } } } } else { echo "<div class=\"geenhuidaandoeningen\">" . $geenhuidaandoeningen . "</div>"; } } } } ?> Hello, I am slightly nervous about posting this because I am almost completely new to php, I have a few introductory books on the subject which I am working through at the moment as well as some reference books but I am still getting through the basics of it all. I recently downloaded a login script, which allows a user to login and also allows the protection of some pages if users are not logged in. This script was a free one from easykiss123. it comes with other .php files and I have given them all a look over and I get the general idea of what's going on for the most part, and I THINK as I keep reading my books I will understand everything even more. However, what I really want to do right now is make it so a website would know which user is logged on, and then use this information elsewhere. For example if a particular user logged on and submitted something, I would like obviously the submission to be recorded but also the id of the user that submitted it, at the moment with this code, I do not think that is possible, however I could be wrong. I am looking for any pointers or a nudge in the right direction or link to a tutorial of how I would go about this, anything that may help. I think I would be storing the user ID in a global variable that can be used throughout the site, but again I am not sure. Thanks in advance for any help, I have included both the login script and the script used for protecting pages, as its already freely available online I see no issue with posting snippits of it here since the source has been referenced. Code: [Select] <?php # Script 16.8 - login.php // This is the login page for the site. require_once ('includes/config.inc.php'); $page_title = 'Login'; include ('includes/header.html'); if (isset($_POST['submitted'])) { require_once (MYSQL); // Validate the email address: if (!empty($_POST['email'])) { $e = mysqli_real_escape_string ($dbc, $_POST['email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the password: if (!empty($_POST['pass'])) { $p = mysqli_real_escape_string ($dbc, $_POST['pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } if ($e && $p) { // If everything's OK. // Query the database: $q = "SELECT user_id, first_name, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // A match was made. // Register the values & redirect: $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'index.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // No match was made. echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>'; } } else { // If everything wasn't OK. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } // End of SUBMIT conditional. ?> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" /></p> <p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <?php // Include the HTML footer. include ('includes/footer.html'); ?> Code: [Select] <?php require_once ('includes/config.inc.php'); $page_title = 'YOUR PAGE TITLE GOES HERE'; // Start output buffering: ob_start(); // Initialize a session: session_start(); // Check for a $page_title value: if (!isset($page_title)) { $page_title = 'User Registration'; } // If no first_name session variable exists, redirect the user: if (!isset($_SESSION['first_name'])) { $url = BASE_URL . 'index.php'; // Define the URL. ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } ?> Code: [Select] <?php // Flush the buffered output. ob_end_flush(); ?> I am needing help designing password recover script. This script must include a password recovery script. I am needing for the person to reset there password, need to first answer a form named: Your Email. If the email is found, it goes to another form that asks for the secret answer. Then it goes to a form that asks the answer of there secret question that they entered when they first signed up. If the answer is correct it updates the database table value of the password with a random string generated with: abcdefghijklmnopqrstuvwxyz023456789 And it also, sends that password to the email provided. What I am wanting to know, is how would the code with the if statements would be structured like and the column types and names. Or if anyone has ever created something like this, and would be glad to post a snippet of there code would be great. I have a install.php file that I created. It asks for the MySQL user, pass, hostname and database they want to use. When the script is run, the tables are created and the MySQL info is inserted into a connection table. Now the tricky part. On each page that needs to connect to the MySQL database, I have an include, which contains the following: Code: [Select] define ('DB_USER', ' '); define ('DB_PASS', ' '); define ('DB_HOST', ' '); define ('DB_NAME', ' '); $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASS) OR die ('Cannot connect to MySQL server.'); mysql_select_db (DB_NAME) OR die ('Cannot connect to database.'); How do I tell the database connection script what the variables are from the connections table? Yeah, I know I can manually put them in there, but the point of the script was to make it so the user does not have to go into the code. I have been trying to insert data into my database thru php script with no luck. I think its has to do with not being able access my database. My question is when I use MySQL command client and enter the password and get mysql> does that mean I can use that password to access my databases as long as I point to the correct database with the mysqli_connect function. I dont think I fully understand how this works. I have everything stored on my local computer and I use "localhost" in mysqli_connect function. Hi, I am very new to PHP (and web developing generally, as well). I have been passing through two different ways of verifying user input in a PHP webpage: 1- By calling a different script file, where the verification logic code is listed and then recall the referer $_SERVER['HTTP_REFERER'] page and pass the result using $_SESSION. (I understood this is basically done to avoid repeating the action in the code with every refreshment of the browser window). 2- By enclosing the verification logic code withing the same PHP page, so the page is a big mix of HTML & PHP. (I understood this is basically done, in order to keep the user input without using $_SESSION and it should save one trip of data transfer.) For me, I see both are working; still I want to learn the best coding practices. So your advice is appreciated, and please feel free to correct my, if I missed something about both methods. Hello, I'm trying to take the value from an HTML form and insert it into a database on a button click. It inserts a null value into the database. The script is called submitColumnDetails.php. This is where I create the text field that I want to take the information from. This is in a separate file. Code: [Select] echo <<<END <form action = "submitColumnDetails.php" method = "POST"> <input type = "text" name = "columnField"/> </form> END; This is the submitColumnDetails.php file Code: [Select] <?php //Submit Column Data //-----------------------------------------------------// //Connect to localhost server $connector = mysql_connect("localhost", "root", "root"); if(!$connector){ //If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } //-----------------------------------------------------// mysql_select_db("colin_db", $connector); $newValue = $_POST["columnField"]; //Data from column field. THIS IS WHAT RETURNS NULL $newColumnQuery = "INSERT INTO `colin_db`.`allColumnFields` (`DATA`) VALUES ('$newValue')"; mysql_query($newColumnQuery); //Query to add form to main table $newColumnIntoMainTableQuery = "ALTER TABLE colin_table ADD ('$newValue' varchar(50))"; mysql_query($newColumnIntoMainTableQuery); //Query to add column to main table mysql_close($connector); //Close database connection echo "<script type = 'text/javascript'> window.location = 'index.php'</script>"; //Go back to original page ?> Even when I print out the $newValue, it does not print anything. What am I doing incorrectly? I wrote this basic script yesterday to process and generate a Google Site Map. And it works! BUT I want to advance this script to accommodate for something else and I don't know the correct path to take from here, but I will tell you what I've found out so far.. Current Situation: 1 - Currently my below script generates urls in the site map like: http://abcdefg.com/index.php?dispatch=products.view&product_id=29826 2 - I have .htaccess configured to rewrite the urls to the products name data like: http://abcdefg.com/pennies/wheat-pennies/lincoln-wheat-penny-cent.html (just an example) and these urls are ONLY active if clicking on the site links themselves - meaning if I enter: http://abcdefg.com/index.php?dispatch=products.view&product_id=29826 directly into the url, the url does not resolve to this natural friendly url name. What Id like to achieve (which I don't know what direction I should be looking!): - I'd like my xml output urls (as current) to be written in the natural format (as in #2 above). FYI here is a current example output item in my sitemap: Code: [Select] <url> <loc>http://abcdefg.com/index.php?dispatch=products.view&product_id=29803</loc> <changefreq>weekly</changefreq> <lastmod>2010-09-24T08:00:00+04:00</lastmod> </url> Can anyone give me some guidance on what method might work for this? Do you think it's more a mod_rewrite issue? Or can this be handled easier with straight up modifications to my below? I'm just a bit confused on what direction I should be looking.. Thanks for any input. <?php header("Content-Type: text/xml;charset=iso-8859-1"); echo '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; //include('config.local.php'); $cxn = mysqli_connect($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']); $query = "SELECT cscart_product_descriptions.product_id, cscart_products.product_id, cscart_products.timestamp FROM cscart_product_descriptions JOIN cscart_products ON cscart_product_descriptions.product_id = cscart_products.product_id WHERE cscart_products.status='A' LIMIT 10000"; $result = mysqli_query($cxn, $query); $row = mysqli_fetch_array($result); while ($row = mysqli_fetch_array($result)) { $formatedTime = $row['timestamp']; echo '<url> <loc>http://abcdefg.com/index.php?dispatch=products.view&product_id=' . $row['product_id'] . '</loc> <changefreq>weekly</changefreq> <lastmod>'. date('c',$formatedTime) .'</lastmod> </url>'; } //while ($row = mysqli_fetch_array($result)) echo '</urlset>'; ?> Hi everyone! I've been working on a php script to replace links that contain a query with direct links to the files they would redirect to. Hi i have this upload script which works fine it uploads image to a specified folder and sends the the details to the database. but now i am trying to instead make a modify script which is Update set so i tried to change insert to update but didnt work can someone help me out please this my insert image script which works fine but want to change to modify instead Code: [Select] <?php mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("upload") or die(mysql_error()) ; // my file the name of the input area on the form type is the extension of the file //echo $_FILES["myfile"]["type"]; //myfile is the name of the input area on the form $name = $_FILES["image"] ["name"]; // name of the file $type = $_FILES["image"]["type"]; //type of the file $size = $_FILES["image"]["size"]; //the size of the file $temp = $_FILES["image"]["tmp_name"];//temporary file location when click upload it temporary stores on the computer and gives it a temporary name $error =array(); // this an empty array where you can then call on all of the error messages $allowed_exts = array('jpg', 'jpeg', 'png', 'gif'); // array with the following extension name values $image_type = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif'); // array with the following image type values $location = 'images/'; //location of the file or directory where the file will be stored $appendic_name = "news".$name;//this append the word [news] before the name so the image would be news[nameofimage].gif // substr counts the number of carachters and then you the specify how how many you letters you want to cut off from the beginning of the word example drivers.jpg it would cut off dri, and would display vers.jpg //echo $extension = substr($name, 3); //using both substr and strpos, strpos it will delete anything before the dot in this case it finds the dot on the $name file deletes and + 1 says read after the last letter you delete because you want to display the letters after the dot. if remove the +1 it will display .gif which what we want is just gif $extension = strtolower(substr($name, strpos ($name, '.') +1));//strlower turn the extension non capital in case extension is capital example JPG will strtolower will make jpg // another way of doing is with explode // $image_ext strtolower(end(explode('.',$name))); will explode from where you want in this case from the dot adn end will display from the end after the explode $myfile = $_POST["myfile"]; if (isset($image)) // if you choose a file name do the if bellow { // if extension is not equal to any of the variables in the array $allowed_exts error appears if(in_array($extension, $allowed_exts) === false ) { $error[] = 'Extension not allowed! gif, jpg, jpeg, png only<br />'; // if no errror read next if line } // if file type is not equal to any of the variables in array $image_type error appears if(in_array($type, $image_type) === false) { $error[] = 'Type of file not allowed! only images allowed<br />'; } // if file bigger than the number bellow error message if($size > 2097152) { $error[] = 'File size must be under 2MB!'; } // check if folder exist in the server if(!file_exists ($location)) { $error[] = 'No directory ' . $location. ' on the server Please create a folder ' .$location; } } // if no error found do the move upload function if (empty($error)){ if (move_uploaded_file($temp, $location .$appendic_name)) { // insert data into database first are the field name teh values are the variables you want to insert into those fields appendic is the new name of the image mysql_query("INSERT INTO image (myfile ,image) VALUES ('$myfile', '$appendic_name')") ; exit(); } } else { foreach ($error as $error) { echo $error; } } //echo $type; ?> |