Jump to content

Search the Community

Showing results for tags 'form'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. Hey, Im new to PHP and am trying to make a simple form where it puts the form data into a table called "users" This is the form: <p><form method="post" action="register.php"> <table border="0" align="center"> <tr> <td>Username</td><td><input type="text" name="username" size="15" > </tr> <br /> <tr> <td>Password</td><td><input name="password" type="password" size="15"></td> </tr> <br /> <td><input type="submit" value="Sign Up"/></td><td></td> </table> This is the php code: <?php $dbhost = ''; $dbname = ''; $dbuser = ''; $dbpass = ''; mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname); $order = "INSERT INTO users (username, password) VALUES ('$username', '$password')"; $result = mysql_query($order); if($result){ echo("<br>It Worked!"); } else{ echo("<br>It Failed!"); } ?> But when i upload it to the server and try it, it says there was a entry but its blank..... When i upload it to a server and try it, it automaticly seems to post the data to the database before i even enter a username/password! when i type a username/password in and post it again it says there was another entry but its blank..... any help? - Thanks!
  2. I'm trying to $_POST a variable or two back to the same page, so that I can scroll through different years of entries in my database... I'm not having any luck with it so far, is anyone able to tell me where I've gone wrong? I've tried a few different techniques, but my trouble boils down to being unable to post to the same page, initially I tried <a href="">'s with the variables on the end, but following documentation online its become a more complicated mess with the same effect... adding in $_SERVER['PHP_SELF'], a <form> and such... <?php $up=$_POST['up']; $dn=$_POST['down']; $year = date("Y"); if(up){$year++;} if(dn){$year--;} ?> <h2 style="font-family: ErasDemi;">Log for <?php echo $year; ?></h2> <form action=<?php echo $_SERVER['PHP_SELF'] ?> method='post'> <input type='submit' name='dn' value='Last Year'/> <input type='submit' name='up' value='Next Year'/> </form> Any help would be much appreciated.
  3. Hello, I have set up a form but when I fill it in it says the captcha math question is wrong. I have checked everthing but I can't find my problem. The strange thing that I get the error but It still sends a email. http://klappenvanjepa.co.nf/ <?php $num_one = rand() % 10; $num_two = rand() & 10; $final_num = $num_one + $num_two; $_SESSION['answer'] = $final_num; echo $num_one . ' + ' . $num_two . ' = '; ?> <input type="text" name="answer" /> <br /> <input type="submit" name="send_message" value="Send!"> $user_answer = $_POST['answer']; $real_answer = $_SESSION['answer']; if(empty($naam) OR empty($email) OR empty($email)) { echo "Your forget somthing."; } elseif($user_answer != $real_answer) { echo "Can't send because the question is wrong."; Can someone please help me with this problem. Thanks
  4. I've stored entries from a large form into an array, this array I now want to pass to the next page, but when using either "$_GET[ ]" or "$_POST[ ]", I just get in my array 'a','r','r','a','y', then the rest of the array is empty... I've followed all the documentation I can find, but nothing has worked so far; can anybody help? the variable is man[x], all the other variables from the form passed over, perhaps I've not got the syntax right for an array where i declare it in the second file? $man=$_POST['man'];
  5. Noob here learning PHP with a MySQL database. I know that this isn't the best way to connect to a database and I should probably be using variables as well as stored procedures. I just want to make this functional then I will go back and learn how to make it more secure. I've put a database together with 5 fields, id, author, title, date, body. id is the primary key set as autoincrement. Currently I have a page that displays each row in the database and has an option at the bottom to add a new entry. I want to add the option to edit a current entry. I've spent the last 2 hours doing trial/error and reading forums and I don't really feel like I've made any headway. My Main page <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXX", $con); $result = mysql_query("SELECT * FROM news"); echo "<table border='1'> <tr> <th>ID</th> <th>Author</th> <th>Title</th> <th>Date</th> <th>Body</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['author'] . "</td>"; echo "<td>" . $row['title'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['body'] . "</td>"; echo "<td><a href='file133.php?id=" . $row['id'] . "'>edit</a></td>"; echo "</tr>"; } echo "</table>"; echo "<form action='file132.php' method='post'> <table> <tr><td>Author:</td><td> <input type='text' name='author'></td></tr> <tr><td>Title:</td><td> <input type='text' name='title'></td></tr> <tr><td>Body:</td><td> <input type='text' name='body' size='75'></td></tr> <tr><td></td><td><input type='submit' value='Submit'></td></tr> </table> </form>"; mysql_close($con); ?> Clicking Edit takes you to this page where you can enter in the new data <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_GET['id']) AND $_GET['id'] > 0) { mysql_select_db("XXXXX", $con); echo "<form action='file134.php' method='post'> <table> <tr><td>Author:</td><td> <input type='text' name='author'></td></tr> <tr><td>Title:</td><td> <input type='text' name='title'></td></tr> <tr><td>Body:</td><td> <input type='text' name='body' size='75'></td></tr> <tr><td></td><td><input type='submit' value='Submit'></td></tr> </table> </form>"; } mysql_close($con); ?> When you click submit it goes to this page. I know this code below is all wrong because it just displays the actual code from the 0) to the end. I just need some direction on how to make this functional. <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_GET['id']) AND $_GET['id'] > 0) { mysql_select_db("XXXXX", $con); $mysql_query = "UPDATE news SET Author = '$_POST[author]', title = '$_POST[title]', date = NOW(),body = '$_POST[body]' WHERE id= $row['id'] "; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Record updated, click <a href='file130.php'>here</a> to return to the list of records."; mysql_close($con); ?>
  6. I have the following PHP form that works perfectly and I want to add the possibility to attach a file and after 3 weeks of research I still not able to find a way to do. Please any help will be highly appreciated. Thanks HTML CODE: Code: <form name="htmlform" method="post" action="MyphpFile.php"> <table width="450px"> </tr> <tr> <td valign="top"> <label for="first_name"><b>First Name *</b></label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top""> <label for="last_name"><b>Last Name *</b></label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email"><b>Email *<font size='2'></b></label> </td> <td valign="top"> <input type="text" name="email" maxlength="80" size="30"> </td> </tr> <tr> <td valign="top"> <label for="comments"><b>Comments*</b></label> </td> <td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> </td> </tr> <tr> <td colspan="4" style="text-align:center"> <br><br> <input type="submit" value="Submit"> </td> </tr> </table> </form> And here is the code of my PHP File: PHP Code: <?php if(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "myemail@gmail.com"; $email_subject = "Reporting and issue in UnlimitedWonders"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- place your own success html below --> Thank you <?php } die(); ?>
  7. im not sure if i should post it in php or html. but here it goes. im trying to do an application with dropdown selection options where one selector depends on the last, two levels this way. the options are in a mysql datbase so by using php im retrieving the array for each selector, but how can i make the selectors change live depending on which option you choose without refreshing the page? do i need something else? like javascript or something like that? i know nothing about JS Thanks for taking your time reading this,
  8. Hello, I have a form for the purpose of people signing up for workshops. Of the elements, a few are radio buttons for workshops on different dates. I would like these dates to remain visible if: the date is before the actual workshop date the total number of people signed up is less than 25 Where I have had trouble is if only one of the above is the case. The code below works. But if I change the && to an OR or XOR, it does not work. Is it possible to combine an if statement with based on whether a certain has passed OR the max person limit has been reached? <?php $cntAll = "100";//max person limit $date = "2013-05-01"; $unix_date = strtotime ($date); if ($unix_date > time() && $cntAll < 2) { echo "form fields..."; } ?> Thanks! Peter T
  9. Hi, I'm trying to create a script that will redirect to a url from a form input. Basically I have a page: http://mydomain.com/page (no .html or php etc) and I have an input box on my site - I want someone to be able to type in Joe Blogs and I'm looking to simply redirect to: http://mydomain.com/page/Joe%20Blogs How can I do this?
  10. my code doesnt seem to work.. the radio buttons appear but nothing beside them .. what i know already: mysql_fetch_row is working - i have tested this using mysqli_num_rows() mysqli_query is working - testing in phpmyadmin and also proven above the problem seems to be with $a ..... $e .. i have tried to echo these variables outside teh form but they dont work. i have also tried to echo them directly ie. $retrieve['question']; and this doesnt work either. could someone please advise what is wrong? cheers ps. i am new at this. this is my code. <?php include 'dbyear2.php'; $qnumber = ($_REQUEST['uqn']); // obtain question number from URL $find = mysqli_query($condbyear2, "SELECT * FROM Renal WHERE UQN='$qnumber'"); while($retrieve=mysqli_fetch_row($find)); { $question = $retrieve['question']; $a = $retrieve['MCQ_A']; $b = $retrieve['MCQ_B']; $c = $retrieve['MCQ_C']; $d = $retrieve['MCQ_D']; $e = $retrieve['MCQ_E']; $answer = $retrieve['answer']; $correct = $retrieve['MCQ_correct']; } ?> <form action='check.php' method='POST'> <table> <tr><td></td><td></td></tr> <tr></tr> <tr><td><input type='radio' name='group1' value='A' /></td><td> <?php echo $a; ?></td></tr> <tr><td><input type='radio' name='group1' value='B' /></td><td> <?php echo $b; ?></td></tr> <tr><td><input type='radio' name='group1' value='C' /></td><td> <?php echo $c; ?></td></tr> <tr><td><input type='radio' name='group1' value='D' /></td><td> <?php echo $d; ?></td></tr> <tr><td><input type='radio' name='group1' value='E' /></td><td> <?php echo $e; ?></td></tr> <tr> <?php // sending the retrieved information from MYSQL via POST for use in check.php file $qnumber; $a; $b; $c; $d; $e; $answer; $correct; ?></tr> <tr><td><input type="submit" value="Submit"></td></tr> </table> </form>
  11. Hi all, I am working with a drop down to auto populate a textarea with preset fields / lines. The issue I keep having is the formatting to the text being populated has no lines/breaks to it. Below is the current java script snip it and the form as it stands. I am looking to find if there would be a better method to doing this, including creating a php form utlizing ajax to pull the information. Thoughts? Javascript: <script type="text/javascript">function updateTextBox(val) { if(val == "1") { document.forms['Form'].elements['TextBox'].value = "Line 1, Line 2, Line 3, Line 4";<--- In theory should display as entered, however this does not occur on any line break/Also /n/p/br/&nbsp do not work to adding lines/breaks. } else if(val == "2") { document.forms['Form'].elements['TextBox'].value = "Line 1 &nbsp Line 2"; } } </script> Form: <form name="Form"> <select onchange='updateTextBox(this.value)'> <option value=""></option> <option value="1">Test</option> <option value="2">Test2</option> </select> <tr> <td> <div align="left"><span id="copy"> <textarea name="TextBox" cols="29" rows="30" style="font-family: Verdana" class="size12"></textarea> <br /> </span></div> <table width="20%" border="0" align="left"> <tr><td><input name="Button" type="button" onclick="javascript:selectcopy('Form.textbox')" value="Copy Notes" /></td></tr> <tr><td><input name="RESET" type="RESET" value="Clear Notes" /></td></tr> </table> </div>
  12. Hello, I have a large form that can be built dynamically, user can add multiple fields and now I have problems with saving values to DB. I'm using codeigniter. This is my form and this is part of my controller that handle those inputs: $from = array(); foreach ($this->input->post('from') as $froms) { $from[] = $froms; } $to = array(); foreach ($this->input->post('to') as $tos) { $to[] = $tos; } $step = array(); foreach ($this->input->post('step') as $steps) { $step[] = $steps; } $odvisnost = array(); foreach ($this->input->post('odvisnost') as $dependency) { $odvisnost[] = $dependency; } And I get error: and 1st value is "productid" As you can see it tries to insert 'array' instead of values that I enter, I entered 2,3,4,5 and 6. My html form is correct with all inputs names as array[] for example: <input type="text" name="steps[]">
  13. I have a html form in which the dropdown box is an array element now I have created a javascript function that get form as parameter . 1)I need to maniulate the values of the array present in the form in the below code sendmail is the form sname is the field array function addit(sendmail) { var x=document.sendmail.sname.length; //alert(x); while( x>0 ) { var skill=document.getElementById("sname[x]").value; //alert(skill); var anOption = document.createElement("OPTION"); anOption.innerText = skill; anOption.Value = skill; document.form.snames.options.add(anOption); x--; } }
  14. Hi everyone, this is my first post, because I need to pick your brains a bit Any help is appreciated. Thx ... I'm designing an application for purposes known to just a few people . It's work related. It should take the data provided and insert into form provided below, and automatically submit it. There are no issues on any other page on that domain, I'm able to login, save cookies, read them, go to other links on the same site. The problem I'm having is occurring on the page with the form, specifically, curl executes and fetches the page, but the post data is not sent.(data is sent as array, also tried urlencoded string) It think there might be a problem with the way the form is structured(code below). Also, the site with the form is not mine, but i will provide headers and post variable that are transmitted when form is submitted in browser. So to begin. Form: <form action="newFault" method="GET" id="typeForm"> <div style="margin:5px"> Tip smetnje: <select name="type" id="type"> <option value="SVA" selected>SVA VA</option> <option value="SNBS">SNBS - NBSA</option> <option value="SULL">SULL - ULL</option> </select> </div> </form> <div> <form method="POST" action="createFault" enctype="multipart/form-data"> <input type="hidden" name="type" value="SVA"> <table class="tableLight" cellpadding="0" cellspacing="1" style="margin: 5px;"> <tr> <td colspan="2" style="text-align: right">Virtual account code:</td> <td><input name="accountCode" size="60"></td> <td></td> </tr> <tr> <th>konos</th> <th style="text-align: right">Kontakt osoba:</th> <td><input name="param.konos" size="60"></td> <td></td> </tr> <tr> <th>tel</th> <th style="text-align: right">Telefon:</th> <td><input name="param.tel" size="60"></td> <td></td> </tr> <tr> <th>tfx</th> <td style="text-align: right">Telefax:</th> <td><input name="param.tfx" size="60"></td> <td></td> </tr> <tr> <th>eml</th> <td style="text-align: right">E-mail:</td> <td><input name="param.eml" size="60"></td> <td></td> </tr> <tr> <th>vrkv</th> <th style="text-align: right">Vrsta:</th> <td><input name="param.vrkv" size="60"></td> <td></td> </tr> <tr> <th>lpb</th> <td style="text-align: right">Lokalni pozivni broj:</td> <td><input name="param.lpb" size="60"></td> <td></td> </tr> <tr> <th>idkod</th> <th style="text-align: right">nesto pristupa:</th> <td><input name="param.idkod" size="60"></td> <td></td> </tr> <tr> <th>ugbrz</th> <td style="text-align: right">brzina:</td> <td><input name="param.ugbrz" size="60"></td> <td></td> </tr> <tr> <th>iatk</th> <th style="text-align: right; ">Name:</th> <td><textarea name="param.iatk" cols="40" rows="3"></textarea></td> <td></td> </tr> <tr> <th>dkk</th> <td style="text-align: right">Datum koji odredi krajnji korisnik (ukoliko je to primjenjivo):</td> <td><input name="param.dkk" size="60"></td> <td></td> </tr> <tr> <th>opkv</th> <th style="text-align: right">Opis kvara:</th> <td><textarea name="param.opkv" cols="40"></textarea></td> <td></td> </tr> <tr> <th colspan="2" style="text-align: right">Dokumentacija u TIFF formatu:</th> <td><input type="file" name="attachment"></td> <td></td> </tr> <tr> <td colspan="2"></td> <td colspan="2"> <input type="submit" value="Pozovi"> PHP code: function saljipostom() { $postdata = 'type=SVA&accountCode=101010&param.konos=osoba&param.tel=016000840&param.tfx=&param.eml=&param.vrkv=vrsta&param.lpb=&param.idkod=02637992641&param.ugbrz=&param.iatk=imekorisnika&param.dkk=&param.opkv=opis&attachment=&submit=Pozovi'; $fields = array( 'type'=>'SVA', 'accountCode'=>'101010', 'param.konos'=>'osoba', 'param.tel'=>'016000840', 'param.tfx'=>'', 'param.eml'=>'', 'param.vrkv'=>'vrsta', 'param.lpb'=>'', 'param.idkod'=>'02637992641', 'param.ugbrz'=>'', 'param.iatk'=>'imekorisnika', 'param.dkk'=>'', 'param.opkv'=>'opis', 'attachment'=>'' ); $polje = $fields; foreach ( $fields as $key => $value) { $post_items[] = $key . '=' . urlencode($value); } $post_string = implode ('&', $post_items); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://something.something/ui/ganimed/b2b/newFault?type=SVA"); curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0"); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'curl/cookies.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'curl/cookies.txt'); $result = curl_exec ($ch); curl_close ($ch); unset($ch); $page = str_get_html($result); echo $page; } Response header from curl: HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 08:05:17 GMT Content-Type: text/html;charset=UTF-8 Content-Language: en-US Vary: Accept-Encoding Transfer-Encoding: chunked Firebug says post fields are: typeSVA accountCode param.konos param.tel param.tfx param.eml param.vrkv param.lpb param.idkod param.ugbrz param.iatk param.dkk param.opkv attachment Headers in firebug when form is submitted in browser: Response Headers: Connection Keep-Alive Content-Language en-US Content-Length 0 Content-Type text/plain Date Thu, 24 Jan 2013 12:52:46 GMT Keep-Alive timeout=15, max=100 Location https://something.something/ui/something/b2b/faults?type=SVA&guid=40898022-1b33-42ab-a9f2-696cc5f70950 Request Headers: Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.5 Connection keep-alive Cookie JSESSIONID=DD0148C1D1701FA237704C42DE093687.node1 Host something Referer https://something.something/ui/something/something/newFault?type=SVA User-Agent Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0 QUestion: The problem I'm having is occurring on the page with the form, specifically, curl executes and fetches the page, but the post data is not sent, i.e. form is not accepting it(data is sent as array, also tried urlencoded string) ANy ideas? Anything else you need just ask.
  15. I need to call a javascript or a php function from a form made in php, so that I could make change in data base on clicks. 1)I included the function on onclick event on submit but nothing happens. 2)The file name in which this code is include is view_users.php could someone hel me solve this <?php mysql_select_db("programmers") or die(mysql_error()); $data = mysql_query("SELECT * FROM user_allotment") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo "<tr>"; echo "<td>".$info['id'] . "</td>"; echo "<td>".$info['uname'] . "</td> "; echo "<td>".$info['password'] . "</td>"; $id=$info['id']; echo "<form method="post" action="view_users.php">"; echo "<td><label><input type="button" name=/"$id/" value="edit" align="middle" onclick="edit()"/></label></td>"; echo "<td><label><input type="button" name=/"$id/" value="delete" align="middle" onclick="edit()"/></label></td>"; echo "<td><label><input type="checkbox" name=/"$id/" value="privilege" align="middle" onclick="edit()"/></label></td>"; echo "</form>"; echo "</tr>"; } ?>
  16. Hey people, I am faced with a problem that I need guidance with in order to solve. I have a catering website that is connected to a mysql database that has a back end to do changes to the menu. I have created an update page that originally updated the price but I was asked for it to update all the fields with any changes being made on the page, sounds simple right? Only problem is, is that the data that is being displayed is pulled from the database and displayed as values in input boxes so that the user can make changes. Each input box has a nameid which is a unique number that is pulled from the database that is stored in a field for each entry. I want it so that the user can change any input box data and click on the one button and it update the records to each correct field based on their own unique id. Here is the code for the front end <form action="chstarterprice.php" method="post"> <br><br> <?php include("connection.php"); $result= mysql_query("SELECT title, subtext, nameid, category, price FROM starters"); while($row = mysql_fetch_array($result)) { $nameid = $row['nameid']; $title = $row['title']; $subtext = $row['subtext']; $category = $row['category']; $price = $row['price']; echo"<table>"; echo"<tr>"; echo"<td width=\"70px\">"; echo"<p class=\"form2\">"; echo "<b>Title</b>"; echo"</td>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo "<b>Subtext</b>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo "<b>Category</b>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo "<b>Price</b>"; echo"</td>"; echo"</tr>"; echo"<tr>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$title\">"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$subtext\">"; echo"</td>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$category\">"; echo"</td>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$price\">"; echo"</td>"; echo"</tr>"; echo"<tr>"; echo"</tr>"; echo"</table>"; } mysql_close($con); ?> <br> <input name="Submit" type="submit" value="Change" /></p> </form> Here is the backend script that processes the form data <? ob_start(); ?> <?php include("connection.php"); $nameid = $_POST['nameid']; $query = "update starters set title, subtext, nameid, category, price = ('$_POST[nameid]') where 'starters'.'nameid' = '$nameid' or die(mysql_error)"; if(mysql_query($query)){ header("location:change-prices.php");} else{ header("location:change-prices.php");} ?> <? ob_flush(); ?> If you guys can point me in the right direction with the code to make this work I would be greatly appreciated, I am really sure that it has something to do with the backend script as opposed to the front end. Please get back to me, thanks guys. Mitch
  17. I'm working with a client and setting up this form for them. I'm trying to have the user be able to add a new name and email record into the account table. Once they submit it should display the 10 newest records below the form. Appreciate any help. class account{ function account(){ $this->id = ' '; $this->name = ''; $this->email = ''; } function find_account($id){ $sql="select `id` from `account` where `id`='".$id."'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)){ $row['id']; //int pk auto incerment $row['name']; //varchar(50) $row['email']; //varchar(50) $row['timestamp']; //varchar(15) } } } <html> <body> <div> <form action='#'> name: <input type='text' name='account_name'> email:<input type='text' id='account_email'> <input type="button" value="submit"> </form> </div> <div style="border:solid 1px #F60;"> Last 10 entry: </div> <div style="border:solid 1px #000;"> <?php echo "id: ".$account->id;?> <?php echo "name: ".$account->name;?> <?php echo "email: ".$account->email;?> </div> </body> </html>
  18. I looking for a good tutorial that will cover arrays, from HTML forms to storing the data( serialize,unserialize, implode, explode)in mysql with php I need to create a from that will allow me to create an array from text field then submit to database and late allow me to editied and update that array So I have four basic tables one serving as main table that will hold 5 field of data plus three field set aside for arrays then I have 3 tables that will hold keys and reference for those array plus additional data objective : In my main table the fields array1 array2 and array3 are the one I need to insert the array data into. I need to be able to manipulate the data of the array completely from an HTML form or multiple forms create basic HTML forms and PHP code to process I must be able to pull a record, check to see if that is an in those field array then add some data if their is if not start a new array for that record create basic HTML forms and PHP code to process I must be able to view and delete part of the array as well create basic HTML forms and PHP code to process then pull a record that has array data in it, then create a query base on those array to pull data from other tables and create some basic calculation base on the original record and the data that you reference in the other tables ( tables array1 array2 and array3 )create basic HTML forms and PHP code to process To help paint you better picture I am attaching below some sample tables and data I know that the data is not optimize but that is on purpose ok let say that this is( id) 2 in main 2 11 12 12 15 18 ('MOPQY4IV','9QR4TH7K','NZ1O45B0','1XUUU5D4','J94RVSNY')NULL NULL this array would be reference in table array1 'MOPQY4IV','9QR4TH7K','NZ1O45B0','1XUUU5D4','J94RVSNY' So in PHP I need to create a for loop that would take the value of this array and pull the data from table array1 I don't think the foreign key would work as this is not normalize database since other (id) in main could reference the same keys in array1 so I believe it be a many to many relation (id)3 could look some like this 3 10 16 12 17 14 ('MOPQY4IV','9QR4TH7K','JAM39TXN',)NULL NULL some of the array value are the same as in (id) 2 Thank You Antonio CREATE TABLE IF NOT EXISTS `array1` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array1` -- INSERT INTO `array1` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'MOPQY4IV', 0, 1, 0, 3, 2), (2, '9QR4TH7K', 2, 2, 0, 0, 2), (3, '8NBYRZ72', 2, 1, 3, 3, 3), (4, 'NZ1O45B0', 0, 2, 2, 3, 2), (5, 'Y7XPA7Q3', 0, 0, 1, 1, 2), (6, '1XUUU5D4', 1, 3, 2, 1, 2), (7, 'JVUI1KA6', 2, 1, 3, 3, 1), (8, 'J94RVSNY', 3, 2, 3, 1, 1), (9, 'NF9YSEF4', 2, 3, 0, 1, 3), (10, 'LFY81TBA', 1, 1, 1, 3, 1), (11, 'LZH9S2DE', 0, 3, 2, 0, 1), (12, '7XK4NF8M', 3, 1, 1, 2, 0), (13, 'JAM39TXN', 0, 0, 2, 2, 1); -- -------------------------------------------------------- -- -- Table structure for table `array2` -- CREATE TABLE IF NOT EXISTS `array2` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array2` -- INSERT INTO `array2` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'BZGZX887', 1, 0, 0, 0, 3), (2, 'WW7JG2WI', 3, 1, 0, 2, 0), (3, 'U1UAK4Z7', 0, 2, 2, 3, 0), (4, 'L1ETC8VM', 1, 3, 3, 3, 3), (5, 'RYPO75Y6', 3, 3, 0, 1, 0), (6, 'O9XKS4B0', 2, 2, 2, 2, 0), (7, 'A1W8VD5M', 1, 1, 0, 3, 3), (8, '4EH4IUBF', 1, 3, 3, 2, 0), (9, '2YV7VJML', 0, 2, 0, 1, 1), (10, '1V9TPRT8', 1, 2, 3, 3, 1), (11, '6XC0QJPB', 1, 2, 2, 3, 3), (12, 'JWX4SG1M', 2, 2, 3, 1, 0), (13, '60UBRIB2', 0, 0, 2, 2, 0); -- -------------------------------------------------------- -- -- Table structure for table `array3` -- CREATE TABLE IF NOT EXISTS `array3` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array3` -- INSERT INTO `array3` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'XW2R8FZV', 0, 2, 0, 2, 1), (2, 'U0UQ4XE0', 3, 3, 3, 2, 1), (3, 'DJZ0F72P', 0, 2, 0, 2, 1), (4, '58NZG2QT', 3, 0, 3, 1, 0), (5, '8X0MTA7C', 3, 3, 1, 3, 0), (6, '566JPHPO', 3, 1, 0, 2, 2), (7, '59FE3PVA', 3, 0, 2, 3, 1), (8, 'O87PI80J', 1, 2, 0, 3, 3), (9, 'J69OP30N', 1, 2, 0, 2, 2), (10, '4VCA5FA9', 2, 1, 1, 3, 3), (11, 'N6I82WQS', 2, 0, 3, 0, 2), (12, 'ZSNV3O7K', 0, 0, 2, 2, 3), (13, 'YE6E4RB0', 2, 2, 3, 1, 0); -- -------------------------------------------------------- -- -- Table structure for table `main` -- CREATE TABLE IF NOT EXISTS `main` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, `array1` text, `array2` text, `array3` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ; -- -- Dumping data for table `main` -- INSERT INTO `main` (`id`, `data1`, `data2`, `data3`, `data4`, `data5`, `array1`, `array2`, `array3`) VALUES (1, 10, 11, 15, 14, 16, NULL, NULL, NULL), (2, 11, 12, 12, 15, 18, NULL, NULL, NULL), (3, 10, 16, 12, 17, 14, NULL, NULL, NULL), (4, 18, 10, 13, 16, 11, NULL, NULL, NULL), (5, 11, 10, 13, 9, 15, NULL, NULL, NULL), (6, 9, 18, 14, 17, 14, NULL, NULL, NULL), (7, 14, 18, 16, 13, 17, NULL, NULL, NULL), (8, 15, 16, 12, 17, 17, NULL, NULL, NULL), (9, 17, 16, 12, 14, 10, NULL, NULL, NULL), (10, 17, 14, 11, 9, 17, NULL, NULL, NULL), (11, 12, 18, 10, 13, 13, NULL, NULL, NULL), (12, 10, 12, 14, 14, 10, NULL, NULL, NULL), (13, 14, 14, 12, 17, 18, NULL, NULL, NULL), (14, 1, 1, 1, 1, 1, NULL, NULL, NULL), (15, 22, 22, 22, 22, 22, NULL, NULL, NULL), (16, 1, 1, 1, 1, 1, NULL, NULL, NULL);
  19. I'm writing code to validate a form and I'd like to be able to set the position of the cursor to the field of my choice when I detect an error. I'm getting the strong impression that I have to use Javascript to set the position of the cursor via the focus() function. But how do I pass information from my PHP code to Javascript to tell it which field I want the focus on? For example, let's say I've got a simple form contain Name, Email address, Subject and Message. I check for bad data in all of those fields and I want to put the cursor (or focus) on the first field that has an error. How does my PHP code tell Javascript that the first field in error is the Email Address or the Message or whatever? An example showing what happens in PHP and what happens in Javascript would be very handy if someone can point me to one or throw one together....
  20. Hello. Recently, I've been learning about registration forms in PHP, and I'm wandering how I could improve the one I've already written(this is only an excerpt, obviously): if(!empty($username) && !empty($password) && !empty($re_password) && !empty($firstname) && !empty($lastname)){ if($password === $re_password){ $query_run = mysql_query("SELECT username FROM users WHERE username = '$username'"); if(mysql_num_rows($query_run)==1){ echo 'User '."<strong>".$username."</strong>".' Already Exists!'; }else{ mysql_query("INSERT INTO users VALUES ('','".mysql_real_escape_string($username)."','".mysql_real_escape_string($hashed_password)."','".mysql_real_escape_string($firstname)."','".mysql_real_escape_string($lastname)."')"); header('Location: my119file.php?pass_username='.$username); } }else{ echo 'The Re-Entered Password Doesn\'t Match'; } }else{ echo 'Please Fill Out All The Fields'; } } }else{ echo 'You\'re already logged in'; } I'm mainly concerned about the fact that, if the user inputs invalid information into the fields, he will only be notified of the first error encountered; if there happen to be multiple errors with the filled-out information, the user will not know until the first error is solved. For instance, if the user omits one of the required fields, AND the "confirm password" does't match, only the "Please Fill Out All The Fields" error will be displayed, and the "Password Don't Match" error will be ignored until the first issue is resolved. I would much rather prefer if the form recognized all errors in a single run, but I'm not sure how to do that... Any ideas? Thanks.
  21. form not posting to database instead its redirecting me to another page with heading "object not found!" <?php $connect= mysql_connect("localhost", "username", "password"); if (!$connect) { die("could'nt connect to db:".mysql_error()); } mysql_select_db("myapp", $connect); $sql="INSERT INTO form(fname,lname,email,password,telephone,sex,dob) VALUES ('','$_POST[fname]', '$_POST[lname]', '$_POST[email]' '$_POST[password]', '$_POST[telephone]', '$_POST[sex]', '$_POST[dob]')"; if (!mysql_query($sql, $connect)) { die("Error:" .mysql_error()); } mysql_close($connect); function spamcheck($field) { $field = filter_var($field, FILTER_SANITIZE_EMAIL); if(filter_var ($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_POST['email'])) { $mailcheck = spamcheck($_POST['email']); } if($mailcheck == FALSE) { //echo "invalid input"; } else { $email=$_POST['email']; $fname=$_POST['fname']; $lname=$_POST['lname']; $password=$_POST['password']; $retype_password=$password; $telephone=$_POST['telephone']; $sex=$_POST['sex']; $DOB=$_POST['dob']; } function yearOptions() { for ($i = 1910; $i <= date('Y'); $i++) { $s = date('Y') == $i ? ' selected="selected"' : ''; echo '<option '.$s.' value="'.$i.'">'.$i.'</option>'."\n"; } } function monthOptions() { $months = array( 1 => "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); foreach ( $months as $monthNo => $month ) { ( $monthNo == date('n') ) ? $selected = ' selected="selected"' : $selected = ''; echo '<option value="'.$monthNo.'"'.$selected.'>'.$month.'</option>'."\n"; } } function dayOptions() { for ( $i = 1; $i <= 31; $i++ ) { ( $i == date('j') ) ? $selected = ' selected="selected"' : $selected = ''; echo '<option value="'.$i.'"'.$selected.'>'.$i.'</option>'."\n"; } } $password=$_POST["password"]; $salt=rand(100000,999999); $encrypted= (MD5(MD5($salt.$password))); if($retype_password!=$password) { echo "password mismatch"; } ?> <form action = "register.php" method=post> <fieldset> Firstname: <input type="text" size=30 name="fname"><br> Lastname: <input type="text" size=30 name="lname"><br> Email address: <input type=text size=30 name="email"><br> Password: <input type=password size=30 name="password"><br> Retype Password: <input type=password size=30 name="retype_password"><br> Telephone: <input type=tel size=30 name="telephone"><br> sex: <input type="radio" name="sex" value="male" checked="checked">Male<br/><input type="radio" name="sex" value="female">Female<br> Date of birth: <select name="dob"> <?php dayOptions();?> </select> <select name="dob"> <?php monthOptions();?> </select> <select name="dob"> <?php yearOptions();?> </select><br> <INPUT TYPE=SUBMIT VALUE="Register"> </fieldset> </form>
  22. I'm a PHP newbie (but experienced in several other languages) and I'm looking for the best way to reset a form, i.e. restore it to its initial values. I have a Reset button on the form and I know I can detect that it was pressed with if (isset($_POST['resetButton'])) { } where resetButton is the value I gave to the name attribute of the button. I just need to know how to get the various values on the form back to their original state. Typically, that would be blank for text fields and default values for radio buttons, etc. I don't know if there is a single all-purpose function that will reset everything in one go or if I have to set each field to its original value with individual statements. Either approach is fine by me. Frankly, at this stage of the game, I'd be happy to get even a not-so-good method of doing this! I have spent close to two hours googling and searching on every phrase I could think of but all I get is items about how to prevent blanks in forms; not a word on how to blank out a form field. Maybe I'm just having a Stupid Day but it shouldn't be this hard to find out how to set a field to blank! For what it's worth, I tried setting a text field to blank with this: $_POST['name'] = ''; //blank out name but nothing happened. There was no error message and the field was unchanged but I know the statement executed. I'd prefer to stay away from the klugey mess called Javascript if I can....
  23. Hi there! I currently have a form that posts the data to a MySQL database. How would I go about having it automatically add a timestamp (to the form entry) in the database as well, every time the from is submitted by a different user, this way I always know the original date/time of reception? Additionally, I also have a user-interface that displays the submitted form data, how would I go about pulling that timestamp from the database so that each entry also displays the timestamp. Thanks for your help.
  24. I am hoping someone might be able to help to resolve an issue that has arisen recently with a number of websites I administer relating to contact form submission. Host server version configuration: Apache - MySQL - 5.0.91-log Perl - 5.8.8 PHP - 5.3.13 Until about a month ago all the contact forms were working correctly, but now whenever a user attempts to submit data via any of the contact forms the form produces the following error. (The subject pulldown menu dictates the delivery destination of the form contact message): Any data entered into any of the form fields ends up being duplicated - e.g.: My SubjectMy Subject instead of My Subject If I change the PHP code to accept My SubjectMy Subject instead of My Subject the form will submit but the data in the sent message is garbage - see below: Message Subject: Mrs.Mrs. Title: Mrs.Mrs. First Name: SS Last Name: OtherOther Telephone No.: 0789012345607890123456 Mobile No.: 0789012345607890123456 Message: A message exampleA message example Email: an.other@whatdoneit.coman.other@whatdoneit.com
  25. Hey! My name is Molly and I am currently attempting to create a form for use in a science project I am conducting. This form has inputs for the usual name, age, gender, etc. The only difference is, after the subjects are done filling out the name, age, and gender inputs, they need to be taken to the next page that will give them four options. Each option will have a three letter (or two letter, if their name is three letters or less) prefix (I can create all of these, they all have to be completely different) , and the same ending. (For example, 'poln'.) The fourth option will take the first three letters of the submitted name (or two letters, if their name is three letters long or less) and tack it onto the same ending. ('poln'). Then the subject needs to be able to choose this option, and submit all the information to my sql database. Here's an example situation; Your name is Sarah. You go to the website and type in your name, age, and click on your gender. You click the next button, and you see a page with four choices; Molpoln Addpoln Sarpoln Tarpoln You select your choice and press submit, which sends the information to a data base. Now have pretty much no experience with php, this is incredibly difficult for me. I have understood how to great the normal inputs i.e. text boxes for name/age and radio buttons for gender, but the rest is almost impossible. In short, 1. How do I "fix" the name input so that the code will take the first three letters and tack it onto the ending? 2. How do I "upload" the other choices so that whenever the name is given, the other three choices must start with a different letter? 3, How do I make these options clickable? 4. How do I submit it all to my sql database? This is what I have so far for my index page <html> <body> <style> .robotext {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none} .robolink:link {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none} .robolink:hover {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: underline} .robolink:visited {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: none} </style> <script language="Javascript"> function validate(){ var allok = true; if(sproject.First_Name__1.value == ""){ alert('Invalid input for First Name'); return false; } if(isNaN(sproject.Age__2.value)){ alert('Invalid input for Age, this must be a number') return false; } document.sproject.Submit.disabled="disabled"; return true; } </script> <form name="sproject" method="Post" action="http://agreatperhaps...nf/entries.php" onsubmit="return validate();"> <form method="post" action="update.php" <table width="100%" border="0" cellpadding="5" cellspacing="0"> <tr><td>First Name</td><td><input type="edit" name="name1" value="" size="15"></td></tr> <tr><td>Age</td><td><input type="edit" name="age2" value="" size="2"></td></tr> <tr><td valign=top>Gender</td><td valign=top> <input type="radio" name="gen3" value="Female" checked>Female<br> <input type="radio" name="gen3" value="Male">Male<br> </td></tr> <tr><td colspan=2><input type="submit" name="Submit" value="submit"></td></tr> </body> </html> And here is my update.php page <html> <body> <?php $name1 = $_POST[ ' name1 ' ]; $age2 = $_POST [ 'age2 ']; $gen3 = $_POST [ 'gen3 ']; mysql_connect ("provider", "databasename", "databasepassword") or die ('Error: ' . mysql_error ()) mysql_select_db ("databsename"); $query= "INTERT INTO TestTable (name1, age2, gen3) VALUES ('NULL', '".$name1."', '".$age2."', '".gen3."') mysql_query ($query) or die ('Error updating database'); echo "Database Updated With: " .$name1." ".$age2." ?> </body> </html> Thank you so much!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.