PHP - Re-executing Mysql Query After Submission - Two Forms One Page
Hi, I know this has to be possible but I have been unable to get this to work properly.
I have a page with two forms. The first form is a list of sources associated with a subject, with checkboxes, so that it is possible to remove these associations, like so: Code: [Select] $qs = "SELECT s.source_id, s.source_name from source s, source_subject ss, subject sb where s.source_id = ss.source_id and sb.subject_id = ss.subject_id and sb.subject_id = $subject_id order by source_name"; $rs = mysqli_query($dbc, $qs) or die ('Error querying database'); while($row = mysqli_fetch_array($rs)) { echo '<input type="checkbox" value="' . $row['source_id'] . '" name="markdelete[]">' . $row['source_name'] . '<br />' ; } The second form is a list of sources that are not associated with this subject, with checkboxes enabling the addition of more sources to this subject, like so: Code: [Select] $r = "SELECT source_id, source_name FROM source WHERE source_id NOT IN (select s.source_id from source s, source_subject ss where s.source_id = ss.source_id and ss.subject_id = '$subject_id')"; $r1 = mysqli_query($dbc, $r) or die ('Update Error: '.mysqli_error($dbc)); while ($row = mysqli_fetch_array($r1)) { echo '<input type="checkbox" id="source_id" name="source_id[]" ' ; echo 'value="'. $row['source_id'] .'"'; echo '> ' . $row['source_name'] . '<br />'; } The first form works fine... when the "remove" submit button is clicked, it successfully removes any selected sources and then shows the remaining sources still associated, and then automatically populates this source in the below list (form 2) as one that is not selected. On the second form, when adding a new source to the subject, it successfully enters the data into the database, and removes this source from the list of unselected sources, but it does not seem to re-populate in the first form. The data is correct on the tables, but the page needs to reload the first query... how do I get it to do this? I'd like to be able to make this page editable, and re-editable (in case someone makes a mistake) without having to go back and reload the entire page. Note, both forms call the page itself; not sure if this is part of it. Using this: Code: [Select] <form method="POST" action="<?php echo $_SERVER['PHP_SELF'].'?subject_id='.$subject_id ; ?>"> Does anyone have any ideas? Similar Tutorialshey guys im sure this is possible im wondering how a user can execute a mysql query by a click of a button but without the page reloading...thanks guys What is the best way to display the next record on a web page, from a list of records, without executing the query over and over again each time you display the next record? For example, imagine my user has a list of messages displayed on a web page, and the user filters that list to display all messages with the title "Test", and let's say that returns 12 records. He then clicks on record 1 to read that message. Once he is done reading it, he then wants to read msg 2, and then msg 3 etc. He could hit the Back button in his browser and click on the next record from the list, but it would be more useful to just click on a link that says "Next" which displays the next message in the filtered list of messages (without having to go back to the list). A lot of web sites do this sort of thing, but what is the best way to do it? Do you have to run the original query again each time a new message is loaded, so you know which message is next, or can you somehow store the query to save the server from having to run the same query over and over again? If a user is viewing a list of pictures for example, they could be flicking through the pictures quite quickly, and I would not like to have the server running the same query over and over again every few seconds when it doesn't need to. Advice? (Thanks.) I have the following query where $userid is about 100,000 userids separated by commas. Code: [Select] <? $getpostid=mysql_query("SELECT DISTINCT post.username,post.threadid,thread.threadid,thread.forumid from post,thread WHERE post.username='$username' AND post.threadid=thread.threadid AND post.userid IN ($userid) AND thread.forumid IN ($forumids)") or die (mysql_error()); ?>can i just print all the usernames from above result separated by ';' without looping it multiple times? Could someone help me out how to do above in an efficient manner? Hi, In some cases I need to execute a default query , so I am storing the SELECT statement in a variable like this and executing it: Code: [Select] $default_query="SELECT * from user where userid='$userid'"; $user_query=mysql_query($default_query); The above code returns an empty results. But if I execute it without the variable it works fine. Code: [Select] $user_query=mysql_query("SELECT * from user where userid='$userid'"); Am I syntatically wrong somewhere? Im trying to execute an update sql query, but its not working. IDK if I got the right query tho what i want to do is, when the form is submitted, subtract 15 from the value 'creditleft'. So say the value is 20 , i want to subtract 15 and get 5. Here is the sql query im using; $query2="update userdata set creditleft = - 15 where username = '".$_SESSION['login_name']."'"; mysql_query($query2, $link); I dont get any errors, just no output I am facing problem to execute query by assigning NULL value to a variable and then executing query.In MySQL DB four fields Mobile,landline, pincode,dob are set as integer and date(for dob) respectively.The default is set as NULL and NULL option is selected as yes.All these fields are not mandatory.The problem is that when I edit the form my keeping the value as empty in DB these are saved as 0, 0 , 0 & 0000-00-00 inspite of Null. I have tried everything but still the defect persist. Please help me to come out of the problem The code, I have used: <?php //require_once 'includes/config.php'; $dbusername = $_POST['email']; $dbfirstname = $_POST['first_name']; $dblastname = $_POST['last_name']; //$dbmobile_number = $_POST['mobile']; if (isset($_POST['mobile'])) { $dbmobile_number = $_POST['mobile']; } else { $dbmobile_number = "NULL"; } $dblandline_number = $_POST['landline']; $dbdob = $_POST['dob']; if(isset($_POST['is_email'])) { $dbSubscribe_Email_Alert = '1'; } else { $dbSubscribe_Email_Alert = '0'; } if(isset($_POST['is_sms'])) { $dbSubscribe_SMS = 0; } else { $dbSubscribe_SMS = 0; } $dbAddress_firstname = $_POST['shipping_first_name']; $dbAddress_lastname = $_POST['shipping_last_name']; $dbAddress = $_POST['shipping_address']; $dbcity = $_POST['shipping_city']; $dbpincode = $_POST['shipping_pincode']; $dbstate = $_POST['shipping_state']; $dbcountry = $_POST['shipping_country']; echo "Welcome".$dbusername; //if($_POST['btnSave']) //if ($_POST['btnSave']) //{ //echo "Inside query loop"; $connect = mysql_connect("localhost","root","") or die("Couldn't connect!"); mysql_select_db("salebees") or die ("Couldn't find DB"); //$query = mysql_query("SELECT * FROM users WHERE username='$username'"); $query = mysql_query("update users set firstname = '$dbfirstname', lastname = '$dblastname', mobile_number = '$dbmobile_number', landline_number = '$dblandline_number', dob = '$dbdob', Subscribe_Email_Alert = '$dbSubscribe_Email_Alert', Subscribe_SMS = '$dbSubscribe_SMS', Address_firstname = '$dbAddress_firstname', Address_lastname = '$dbAddress_lastname', Address = '$dbAddress', city = '$dbcity', pincode = '$dbpincode', state = '$dbstate', country = '$dbcountry' where username = '$dbusername' "); header("location:my_account.php"); //} //else //{ //die(); //} ?> 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. Hello all, I have been working with PHP for almost a year now, so somewhat still new to it all. OK, this may be an Apache issue, but this involves a php script I wrote that tries to execute on pages that do NOT call it (via the include command). So, here is a little info on how I have set things up. I use WAMP Server to test php and MySQL code for myself (for fun and for practice) and for clients and their web sites. I run WAMP Server off of my laptop, so I can code on the go and because it is on my laptop, I decided to create a PHP & MySQL user authentication setup to keep out unwanted visitors, but allow trusted friends and fellow developers to view my work on client web sites. Let's say the authentication script is called "auth.php" and for all of the pages I want private, I include that script at the top of those pages, if the visitor is not logged in, redirect them to the login page, otherwise, let them view the page (provided their permission level is adequate). Now, for the client web sites that I am working on, I do not call auth.php anywhere on those pages. Now, the problem I notice is that when I visited a client's web site that I am working on (on my WAMP Server), I reviewed my Apache error log and it gave me a PHP error stating the following: Code: [Select] Maximum execution time of 60 seconds exceeded in E:\\wamp\\www\\assets\\auth.php on line 3, referer: http://192.168.1.4/Web_Projects/NCCCLP/home.php Of course I am able to view the client web site pages without having to login, however, the auth.php script tries to run nonetheless. So my question is, does anyone know why this is happening and if and how I can stop it? This is not a serious (urgent) issue, but it does clog up my error logs and so forth and I prefer to have as few errors as possible. Plus, I would just like to know why and how it is running without being called. Any and all help is greatly appreciated and if I need to provide anymore details or be more specific, please let me know. Also, if an issue like this has already been solved and I missed that thread, please let me know and have my apologies. Thanks in advance. Looking to INSERT a row in a data table and keeping the User on the current page. Will it work like what I have below, or do I need to send it to its own page then return the User back to where he started? What I have below isn't inserting a row. No errors showing. function bookmark_add () { if (isset($_POST['submit'])) { include("/home2/csi/public_html/resources/con.php"); $query = "INSERT INTO a_player_bookmark (bookmark) VALUES ('1')"; $results = mysqli_query($con,$query); echo mysqli_error($con); } $output = '<form name="bookmark_add" method="post" action="" class="bookmark-plus">'; $output .= '<span><input type="submit" name="Bookmark"></span>'; $output .= '</form>'; return $output; }
I'm in the process of making a network for investors and entrepreneurs. When they access their profile page, select edit and go to editprofile.php a problem arises with the data base submission. I have the data they have previously inputted being echoed back out to the user. This lets the user see what they have inputted so that they can make changes to their profile. Unfortunately, with my radio buttons, if no changes are made and the user hits submit, the radio buttons return a value of 'unchecked'. I need them to maintain the value previously submitted to the database if the radio button isn't 'checked'. I'm not sure exactly how to do this. You can test it out yourself by going to http://network.jasonbiondo.com Code is below: Code: [Select] ?php session_start(); require ('connect.php'); include ('header.php'); $savechanges = $_POST['savechanges']; $firstname = strip_tags($_POST['firstname']); $lastname = strip_tags($_POST['lastname']); $username = strtolower(strip_tags($_POST['username'])); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); $entrepreneur = 'unchecked'; $investor = 'unchecked'; $date = date("Y-m-d"); $companyname = strip_tags($_POST['companyname']); $companywebsite = strip_tags($_POST['companywebsite']); $founder = strip_tags($_POST['founder']); $phone = strip_tags($_POST['phone']); $address = strip_tags($_POST['address']); $city = strip_tags($_POST['city']); $state = strip_tags($_POST['state']); $zipcode = strip_tags($_POST['zipcode']); $country = strip_tags($_POST['country']); $development = strip_tags($_POST['development']); $capitalamount = strip_tags($_POST['capitalamount']); $companydo = strip_tags($_POST['companydo']); $founderbuilt = strip_tags($_POST['founderbuilt']); $whatsnew = strip_tags($_POST['whatsnew']); $understand = strip_tags($_POST['understand']); $competition = strip_tags($_POST['competition']); $money = strip_tags($_POST['money']); $demo = strip_tags($_POST['demo']); $incorporation = strip_tags($_POST['incorporation']); $companynameinv = strip_tags($_POST['companynameinv']); $phoneinv = strip_tags($_POST['phoneinv']); $addressinv = strip_tags($_POST['addressinv']); $cityinv = strip_tags($_POST['cityinv']); $stateinv = strip_tags($_POST['stateinv']); $zipcodeinv = strip_tags($_POST['zipcodeinv']); $countryinv = strip_tags($_POST['countryinv']); $angel = strip_tags($_POST['angel']); $vc = strip_tags($_POST['vc']); $capital = strip_tags($_POST['capital']); if ($savechanges) { $queryreg = mysql_query("UPDATE users SET `firstname` = '$firstname', `lastname` = '$lastname', `email` = '$email', `entrepreneur` = '$entrepreneur', `investor` = '$investor', `companyname` = '$companyname', `companywebsite` = '$companywebsite', `founder` = '$founder', `phone` = '$phone', `address` = '$address', `city` = '$city', `state` = '$state', `zipcode` = '$zipcode', `country` = '$country', `development` = '$development', `capitalamount` = '$capitalamount', `companydo` ='$companydo', `founderbuilt` = '$founderbuilt', `whatsnew` = '$whatsnew', `understand` = '$understand', `competition` = '$competition', `money` = '$money', `demo` = '$demo', `incorporation` = '$incorporation', `companynameinv` = '$companynameinv', `phoneinv` = '$phoneinv', `addressinv` = '$addressinv', `cityinv` = '$cityinv', `stateinv` = '$stateinv', `zipcodeinv` = '$zipcodeinv', `countryinv` = '$countryinv', `angel` = '$angel', `vc` = '$vc', `capital` = '$capital' WHERE username= '" . $_SESSION['username'] . "' "); $selected_radio_selector = $_POST['selector']; $selected_radio_invtype = $_POST['invtype']; if ($selected_radio_selector == 'entrepreneur') { $entrepreneur = 'checked'; } else if ($selected_radio_selector == 'investor') { $investor = 'checked'; if ($selected_radio_invtype == 'angel') { $angel = 'checked'; $vc = 'unchecked'; } else if ($selected_radio_invtype == 'vc') { $vc = 'checked'; $angel = 'unchecked'; } else { die("Please select what type of investor you are!"); } } } $q = mysql_query("SELECT `firstname`, `lastname`, `firstname`, `lastname`, `email`, `entrepreneur`, `investor`, `companyname`, `companywebsite`, `founder`, `phone`, `address`, `city`, `state`, `zipcode`, `country`, `development`, `capitalamount`, `companydo`, `founderbuilt`, `whatsnew`, `understand`, `competition`, `money`, `demo`, `incorporation`, `companynameinv`, `phoneinv`, `addressinv`, `cityinv`, `stateinv`, `zipcodeinv`, `countryinv`, `angel`, `vc`, `capital` FROM `users` WHERE username= '" . $_SESSION['username'] . "'"); $r = mysql_fetch_assoc($q); ?> <script type="text/javascript" src="../assets/js/editprofile.js"></script> <form action='editprofile.php' method="POST" id="form"> <fieldset> <p id="required"> * Required Fields</p> <p class="fieldSpacing"> <label for="firstname" class="leftcolalign">First Name *</label> <input id="firstname" class="rightcolalign" name="firstname" value='<?php echo $r['firstname']; ?>'/> </p> <p class="fieldSpacing"> <label for="lastname" class="leftcolalign">Last Name *</label> <input id="lastname" class="rightcolalign" name="lastname" value='<?php echo $r['lastname'];?>'/> </p> <p class="fieldSpacing"> <label for="username" class="leftcolalign">User Name *</label> <?php echo $_SESSION['username']; ?> </p> <p class="fieldSpacing"> <label for="email" class="leftcolalign">Email *</label> <input id="email" class="rightcolalign" name="email" value='<?php echo $r['email']; ?>''/> </p> <p class="fieldSpacing"> <label for="selector" class="leftcolalign">What am I? *</label> <input id="entButton" class="radioalign" type="radio" name="selector" value="entrepreneur"<?php echo $r['entrepreneur']; ?>/> <label for="entrepreneur" id="entrepreneur">Entrepreneur</label> <input id="invButton" class="radioalign" type="radio" name="selector" value="investor"<?php echo $r['investor']; ?>/> <label for="investor" id="investor">Investor</label> </p> </fieldset> <fieldset id="entForm"> <p class="fieldSpacing"> <label for="companyname" class="leftcolalign">Company Name: *</label> <input id="companyname" class="rightcolalign" name="companyname" value='<?php echo $r['companyname']; ?>'/> </p> <p class="fieldSpacing"> <label for="companywebsite" class="leftcolalign">Company Website:</label> <input id="companywebsite" class="rightcolalign" name="companywebsite" value='<?php echo $r['companywebsite']; ?>'/> </p> <p class="fieldSpacing"> <label for="founder" class="leftcolalign">Founder(s): *</label> <input id="founder" class="rightcolalign" name="founder" value='<?php echo $r['founder']; ?>'/> </p> <p class="fieldSpacing"> <label for="phone" class="leftcolalign">Phone Number(s): *</label> <input id="phone" class="rightcolalign" name="phone" value='<?php echo $r['phone']; ?>'/> </p> <p class="fieldSpacing"> <label for="address" class="leftcolalign">Address: *</label> <input id="address" class="rightcolalign" name="address" value='<?php echo $r['address']; ?>'/> </p> <p class="fieldSpacing"> <label for="city" class="leftcolalign">City: *</label> <input id="city" class="rightcolalign" name="city" value='<?php echo $r['city']; ?>'/> </p> <p class="fieldSpacing"> <label for="state" class="leftcolalign">State:</label> <input id="state" class="rightcolalign" name="state" value='<?php echo $r['state']; ?>'/> </p> <p class="fieldSpacing"> <label for="zipcode" class="leftcolalign">Zip Code:</label> <input id="zipcode" class="rightcolalign" name="zipcode" value='<?php echo $r['zipcode']; ?>'/> </p> Hi all, I am wondering if nayone can spot why more form is not processing, basically the page just loads afresh once details have been entered and submit button clicked The page is called client.php <?php session_start(); if (isset($_POST['submit'])) { include('config.php'); $username = $_POST['username']; $password = md5($_POST['password']); $query = mysql_query("SELECT email,password FROM customers WHERE email='$username' AND password = '$password'"); $count=mysql_num_rows($query); if($count==1) { $query1= mysql_query("SELECT id FROM customers WHERE email='$username'"); echo mysql_error() ; while($row = mysql_fetch_assoc($query1)) { $id = $row['id']; $_SESSION['id'] = $id; $_SESSION['logged'] = "SET"; header("Location: client.php?id=$id"); } } else { echo "<script>alert('Incorrect Login Details')</script>"; } } ?> <link href="styles/style.css" rel="stylesheet" type="text/css" /> <link href="styles/form_clean.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="scripts/pageload.js"></script> <script type="text/javascript"> function swapImages(that) { that.src = (that.src.indexOf('buttonselected')>-1) ? ("images/"+that.id+"button.gif") : ("images/"+that.id+"buttonselected.gif"); } </script> <link href="styles/form_clean.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div id="links"> <a href="index.php"><img src="images/homebutton.gif" alt="Home Button" class="buttons" id="home" onmouseover="swapImages(this)" onmouseout="swapImages(this)" /></a> <a href="javascript:ajaxpage('packages.php', 'content');"><img src="images/packagebutton.gif" alt="Packages Button" class="buttons" id="package" onmouseover="swapImages(this)" onmouseout="swapImages(this)" /></a> <a href="javascript:ajaxpage('purchase.php', 'content');"><img src="images/purchasebutton.gif" alt="Purchase Button" class="buttons" id="purchase" onmouseover="swapImages(this)" onmouseout="swapImages(this)" /></a> <a href="javascript:ajaxpage('contact.php', 'content');"><img src="images/contactabutton.gif" alt="Contact Button" class="buttons" id="contacta" onmouseover="swapImages(this)" onmouseout="swapImages(this)" /></a> <a href="client.php"><img src="images/clientbutton.gif" alt="Client Button" class="buttons" id="client" onmouseover="swapImages(this)" onmouseout="swapImages(this)" /></a> </div> <div id="logobox"><img src="images/logo.png" alt="JollyHosting.com - Simplified Reseller Hosting"/> </div> <div id="content"> <img src="images/gaptop.png" alt="seperator" /> <?php if(!isset($_SESSION['logged'])) { ?> <h2> Please Login</h2> <div id="login"> <form class="clean" action="client.php" method="post"> <ol> <li> <fieldset> <legend>Login</legend> <ol> <li> <label for="username">Email Address</label> <input type="text" id="username" name="username" value="" /> </li> <li> <label for="password">Password</label> <input type="password" id="password" name="password" value="" /> </li> </ol> </fieldset> </li> </ol> <p style="text-align:right;"> <input type="submit" value="OK" /> </p> </form> </div> <?php } else { echo "loggin in"; } ?> </div> <?php include('footer.php');?> </div> </body> </html> Many thanks After I input a number and press submit, it'll do some calculating and write the number to a file. Once its done I want it to go to another page but it doesn't seem to work. Ive tried header with no luck .
Heres my code: $number = $_POST['number-entered']; foreach ( range(1, $number) as $i ) { $triangle_numbers[] = $i * ( $i + 1 ) / 2; } //make a file $contents = fopen('gs://a1-task22020.appspot.com/triangular_' .$number. ".txt", "w"); fwrite($contents,implode(',', $triangle_numbers)); //open the file $contents = fopen('gs://a1-task22020.appspot.com/' . $content, 'w'); //re-open the document if you put something in it fwrite($contents, $number); fclose($contents); } header("Location: https://a1-task22020.ts.r.appspot.com/result.php"); } ?>
Hello all, As the title says: For sake of example, let's say I have a form with a couple text boxes and a submit button. When you hit submit, the data from the text boxes is translated into a database record. Howver, refershing the page will this record again and again -- which I do not want. How can I prevent this? Keeping in mind the business logic of my applicatoin allows the same record to be entered twice -- however, it should only happen if the user intentionally visits the form agian, and enters the same data. It should not happen on a page refresh. I assume this is a common problem...? Any thoughts? Thanks! Here is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 If you also have any feedback on my code, please do tell me. I wish to improve my coding base. Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference. Code: Code: [Select] mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); Full code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <h2>Create</h2> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $name = mysql_real_escape_string($_POST['name']); $server_type = mysql_real_escape_string($_POST['type']); $description = mysql_real_escape_string($_POST['description']); if(!$username || !$password || !$server_type || !$description || !$name) { echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1"); if(mysql_num_rows($check1) < 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); echo "Server has been succesfully created!"; } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> I need help I am retrieving rows from MySQL table now what I want is that as rows retrieved with each row and edit button will insert but i don't know how to insert here is my code <?php require('connect.php'); session_start(); $query="SELECT * FROM project WHERE projectstatus='Open'"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0;$j=1; while ($i < $num) { $projectid=mysql_result($result,$i,"projectid"); $fkey=mysql_result($result,$i,"fkey"); $paying=mysql_result($result,$i,"paying"); $completionmonth=mysql_result($result,$i,"completionmonth"); $completiondate=mysql_result($result,$i,"completiondate"); $personspecify=mysql_result($result,$i,"personspecify"); $projecttitle=mysql_result($result,$i,"projecttitle"); $categories=mysql_result($result,$i,"categories"); $tools=mysql_result($result,$i,"tools"); $shortdescription=mysql_result($result,$i,"shortdescription"); $date=mysql_result($result,$i,"date"); $time=mysql_result($result,$i,"time"); $i++; echo "<br>".$j."<br>"; echo "<br>".$projectid."<br>"; echo "<br>".$fkey."<br>"; echo "<br>".$paying."<br>"; echo "<br>".$completionmonth.' month '.$completiondate.' days '."<br>"; echo "<br>".$personspecify."<br>"; echo "<br>".$projecttitle."<br>"; echo "<br>".$categories."<br>"; echo "<br>".$tools."<br>"; echo "<br>".$shortdescription."<br>"; echo "<br>".$date."<br>"; echo "<br>".$time."<br>"; echo "<br>"."<br>"."<br>"; // I want to insert edit button here but dont know how echo "------------------------------------------------------------------------"."<br>"; $j++; } ?> </body> </html> Edited by requinix, 11 June 2014 - 01:09 PM. please use [code] tags when posting code Hi, I am trying to write an input form for a table that the fields contains codes of records from other tables. Is there a way that after each field I can retrieve (validate) the value of the fields that contain a code from a table and display them on the screen when the use move to the next field? The table is a customers order and I want to validate and display the customer name after they key in the customer code and the same for the product's code. Thank! James I'm restarting this under a new subject b/c I learned some things after I initially posted and the subject heading is no longer accurate. What would cause this behavior - when I populate session vars from a MYSQL query, they stick, if I populate them from an MSSQL query, they drop. It doesn't matter if I get to the next page using a header redirect or a form submit. I have two session vars I'm loading from a MYSQL query and they remain, the two loaded from MSSQL disappear. I have confirmed that all four session vars are loading ok initially and I can echo them out to the page, but when the application moves to next page via redirect or form submit, the two vars loaded from MSSQL are empty. Any ideas? Hey again guys! I'm back already today. XD Okay, so... I'm building a script, right. I have a form that is a simple text field. I do NOT want to use javascript. I want to be able to use PHP to be able to do this. Here is the form exactly as it is now: Code: [Select] <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="text" name="price"> How would I only allow a number, and up to 5 digits long, like, for example, a zip code. I know I can always limit the char space, but they might be able to "inject" it? On another note for forms, what would I have to do to get rid of people being able to run a script through a form; is it the strip_tags(); function? Thanks for your help in advance guys! I have two webpages, login_success.php and formentered.php login_success.php is a page where i am entering new information and enteredvalues.php is supposed to be a script to enter the information into mysql. So far I got the login_success page to redirect to enteredvalues.php when submit is clicked but the information in the fields isn't transferring to mysql and neither is the page redirecting back to login_success. Here are both my codes Login_success.php <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <html><title>ChronoServe - Saving Time</title> <link href="style.css" rel="stylesheet" type="text/css"> <body> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="container"> <tr> <td><form name="form2" method="post" action="entervalues.php"> <table width="335px" height="50%" border="1" align="center" cellpadding="0" cellspacing="0" class="centered"> <tr> <td><table width="100%" border="0" align="center" cellpadding="3" cellspacing="10"> <tr> <td colspan="2"><div align="center" class="font2">Activation Information</div></td> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td width="40%" class="font3">First Name :</td> <td width="60%"> <div align="center"> <input name="firstname" type="text" class="font3" id="firstname" /> </div></td> </tr> <tr> <td class="font3">Last Name :</td> <td> <div align="center"> <input name="lastname" type="text" class="font3" id="lastname" /> </div></td> </tr> <tr> <td height="28" class="font3">Phone Number :</td> <td> <div align="center"> <input name="pnumber" type="text" class="font3" id="pnumber" /> </div></td> </tr> <tr> <td class="font3">Personnel Activated :</td> <td> <div align="center"> <input name="numbactivated" type="text" class="font3" id="numbactivated" /> </div></td> </tr> <tr> <td height="37" colspan="2"></td> </tr> <tr> <td colspan="2"><div align="center"> <input name="insert" type="submit" class="font3" value="Submit" /> </div></td> </tr> </table></td> </tr> </form> </table> </td> </tr> </table> </body> </html> Here is enteredvalues.php <?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $pnumber=$_POST['pnumber']; $numberactivated=$_POST['numberactivated']; // To protect MySQL injection (more detail about MySQL injection) $firstname = stripslashes($firstname); $lastname = stripslashes($firstname); $firstname = mysql_real_escape_string($firstname); $lastname = mysql_real_escape_string($lastname); $pnumber = stripslashes($pnumber); $numberactivated = stripslashes($numberactivated); $pnumber = mysql_real_escape_string($pnumber); $numberactivated = mysql_real_escape_string($numberactivated); $sql="INSERT INTO $tbl_name (firstname, lastname, pnumber, numberactivated,) VALUES ('$firstname','$lastname','$pnumber','$numberactivated')")or die(mysql_error()); $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; header("location:login_success.php"); exit(); } ?> |