PHP - Simple Question About Html Form's, Php And Mysql Inserts
Hi,
I m doing some work for my self an because of that i been reading a lot arround about PHP, and theres something that i would like to ask a bit of enlightenment. So my question is as the title says about html form's using php to insert data into mysql, i been reading tutorials arround the interwebs and even made afew successful tests, but pretty much all tutorials use 2 files to accomplish this the html file with the form and an insert.php where the actual code is stored so this made me think is this how usually it's done? in over all you will have 1 file for the form, 1 for the insert, 1 for the edit php code and 1 for delete. How do you guys usually do it? PS: one of the tests i did was making 1 single file with all these using an switch. My interest in making this question is solo to learn how other people do it to see if i m in the right way. Thanks in advance. Similar Tutorialshi, i made my own page, but when i do an insert using mysql, jquery and php, the arabic text does not show properly it is a comments page. here is the DB structure Code: [Select] CREATE TABLE IF NOT EXISTS `app_comments` ( `comment_id` int(20) NOT NULL auto_increment, `comment` text NOT NULL, `user_id` int(20) NOT NULL, `comment_date` date NOT NULL, `app_id` int(20) NOT NULL, PRIMARY KEY (`comment_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ; here is the jquery piece that transfers to php code. Code: [Select] function submit_comment(){ $(".post_comments_button").click(function() { var post_comments = $('.post_comments').val(); var app_id = $('#app_id').val(); //alert (app_id); if(confirm('Add Comment?')) { var string = "task=add_comment&app_id=" + app_id + "&comment="+post_comments; $.ajax({ url : "appajax.php", type : "POST", data : string, success : function(data) { alert(data); window.location.reload(true); } }); } /**/ }); }and here is the acutal insert code in php $new_appquery = 'INSERT INTO app_comments (comment, user_id, app_id,comment_date) VALUES ("' . $comment . '",' . $user_id . ', ' . $app_id . ',NOW());'; and the actual problem is, the arabic text shows like this in my application: Quote بالتوفيق للريال how can i solve this issue? Well, basically I am making my log in script. This is my first website with php and MySQL... actually, its my first website I have done that isn't for a school project. Anywho, the problem I am having is I can't seem to verify the password of the account I am trying to log into. Here is the code snippet I am having trouble with: $usr = $_REQUEST['Username']; $pass = $_REQUEST['Password']; $pass = md5($pass); if(mysql_query('SELECT Password FROM Accounts WHERE Username = "' .$usr . '"') == $pass) { session_start(); $_SESSION['loggedin'] = yes; $_SESSION['User'] = $usr; $_POST['info'] = ("You have successfully logged in " . $usr . "."); } else { $_POST['info'] = "Username and password do not match.";} The problem is that it doesn't seem to matter if the username and password are correct, it always prints "Username and password do not match.". So, here is the table layout of 'Accounts': Did I type the mysql query wrong? Hi all. Im trying to insert from one form 3 items of data into to different tables. I will post the code as most of my notes are in there but first....... What is happening is the form is filled in then the first part of the form where it updates my clubs table with category ID's works fine. Nothing in the if ($result) { } seems to run. I have create some fake groups so the drop down is populated with groups already created and I have tried to select one of these groups so it can be entered into the clubs table and nothing. No errors just no answers. Does anybody no what I am doing wrong? first Ill post the form and the querys that make fields in the form... Querys //gets $validation = $_GET['new_club']; //Querys $qGetClub = "SELECT * FROM clubs WHERE validationID = '$validation'"; $rGetClub = mysql_query($qGetClub); $Club = mysql_fetch_array($rGetClub); //Query for category by name $qGetCat = "SELECT * FROM club_category WHERE catID = ".$Club['cat'].""; $rGetCat = mysql_query($qGetCat); $CatName = mysql_fetch_array($rGetCat); //query for related sub categorys. $qGetSub = "SELECT * FROM sub_categorys WHERE catID =".$Club['cat'].""; $rSubCat = mysql_query($qGetSub); // query for groups created $Groupq = mysql_query("SELECT * FROM groups WHERE memberID = '".$User['memberID']."'"); then we have the form <form action="" method="post" id="insert_clubfrm"> <tr valign="baseline"> <td colspan="2" valign="top"><br/><p>Your Chosen category was <strong><?php echo $CatName['categorys'];?></strong> Please select a sub category.</p><br></td> </tr> <tr valign="baseline"> <td width="132" valign="top" >Club Sub Category:</td> <td width="256" valign="top" ><select name='subcat'> <option value="None">Please Select One</option> <?php while ($New_SubCat = mysql_fetch_assoc($rSubCat)) { ?> <option value="<?php echo $New_SubCat['subID']; ?>"><?php echo $New_SubCat['sub_categorys']; ?></option>"<?php } ?> </select> </td> </tr> <tr valign="baseline"> <td colspan="2" valign="top" ><br/><p>If your sub category does not exist in the list please select "none" above and enter your new sub categroy below.</p><br></td> </tr> <tr valign="baseline"> <td valign="top" class="left_padding">New Sub Category</td> <td valign="top" class="left_padding"><input type="text" name="newSubCat" id="new_cat" value="" /></td> </tr> <tr valign="baseline"> <td colspan="2" valign="top" class="left_padding"><br/> If you had/have more than one site and you had to give your group of companies a name what would that name be? <br/></td> </tr> <tr valign="baseline"> <td valign="top" class="left_padding">Group Name:</td> <td valign="top" class="left_padding"><label for="other_groups"></label> <select name="other_groups" id="other_groups"> <option>None</option> <?php while ($group = mysql_fetch_assoc($Groupq)) { ?> <option value="<?php echo $group['groupID']; ?>"><?php echo $group['group']; ?></option>"<?php } ?> </select></td> </tr> <tr valign="baseline"> <td valign="top" class="left_padding">Group Name:</td> <td valign="top" class="left_padding"><label for="new_groups"></label> <input type="text" name="new_group" value=""> </td> </tr> <tr valign="baseline"> <td valign="top" nowrap="nowrap"> </td> <td valign="top"><div align="left"> <input type="submit" id="insert_clubbtn1" name="insert_clubbtn1" value="Insert record" /> </div></td> </tr> </table> </form> now the code to make the form work... if(isset($_POST['insert_clubbtn1'])){ //Process data for validation $subcat = trim($_POST['subcat']); $NewSubCat = trim($_POST['NewSubCat']); $otherg = trim($_POST['other_groups']); $newg = trim($_POST['new_groups']); //Prepare data for db insertion $newg = mysql_real_escape_string($newg); $subcat = mysql_real_escape_string($subcat); //find the new category //insert $result = mysql_query("UPDATE clubs SET `sub_category` = '$subcat' WHERE validationID ='$validation'") or die(mysql_error()); if ($result) { //if an item other than none from the list is selected then update the club with an ID relating to the group it belongs to if ($otherg !=='None') { $groupsq = mysql_query("UPDATE `clubs` SET groupID ='$otherg' WHERE validationID ='$validation')") or die (mysql_error()); } // If none is selected then $newg must have a value so create a new group in the groups table and then on the next page I will add the group in the club table if ($otherg == 'None') { $groupsq = mysql_query("INSERT INTO `groups` (memberID, group, clubID) VALUES ('".$User['memberID']."', '$newg', ''".$Club['clubID']."')"); } } if ($NewSubCat !="") { mail("email","New Sub Category Request","Dear Owner, \n\nThe club in the name of $name with a validation code of $validationID would like a new sub category called $new_cat\n\n \nTeam Me\n\n\n\n"); } $url = "/create/create_clubp3.php?new_club=$validation"; header("Location: $url"); Is it possible - and reasonable - to have one Form which allows Users to create a new record (i.e. do an INSERT) and which also allows Users to modify an existing record (i.e. do an UPDATE)? When a User registers at my website, not only do they create a record in the "member" table, but one of the required fields is "First Name". What that means is that when I allow Users to edit details in their Profile - most of which were not included in registration to streamline the process - I don't have to worry about doing an INSERT, because I already created a "member" record and on the "Edit Details" page the first field is "First Name" so that is a hook so to speak where they can enter more info about themselves like... Code: [Select] - Location - Date of Birth - Interests - Bio and so on... So here is my problem which I just discovered... Also in my User Profile, I allow Users to answer several open-ended questions like... Code: [Select] 1.) Why did you decide to start your own business? 2.) What advice would you share with others on what NOT to do? The problem is that these questions exist in the "bio_question" table and the answers that I am trying to get from Users will be stored in the "bio_answer" table but no record currently exists?! So do I need both an "INSERT Answers Form" *and* an "UPDATE Answers Form", or can I combine things into one form?! Hope that all makes sense?! Debbie Hi there, I've just started learning php and mysql today. I'm putting things together in dreamweaver and everything is running smoothly (ish). I've got a form written in php that sends data to a database. All fine. I need to send the time of submission to the database. I've put in a hidden field, what code should I use to set the field value to a mysql field of type DATETIME? Cheers. Hi Guys
I'm just getting back into coding after taking a break from it. I want to have a text field that can take up to 1000 characters. What is the best field type for the MySQL field for this? I can't remember if there are any particular special types.
Thanks
I have a quick question to ask, as i cant see it in their docs. Maybe you can help me. I am using http://simplehtmldom.sourceforge.net/ Right, i have written a Simple HTML Dom script to collect data from this page, as an example: http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.html Script executed by running a cron job on this file (which generates the XML): http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.php The data is collected, and written to this file in XML file: http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.xml Thats is fine, and the script essentially scrapes the entire page, with no conditional IF's for any sections. A sample of my code for one segment is below: http://pastebin.com/JLb8f92N What i would like to do now, and i am hoping you could help out is... Scrap this same page, but produce seperate XML files, based on the date. So if you view that page, i want to scrape the data in the table Saturday 4th February 2012 and produce XML for for that day only. The i want to scrape the data in the section for Sunday 5th February 2012, and another for Tuesday 7th February 2012. I think its self explanatory. The table date sections are separated by this HTML element: bg color = " #CCCCCC " But bare in mind that the table rows on each date section will change when the site is updated, and there may be additional or less football game records. Anyway, i would appreciate any help you can show me, on how to place in any conditionals in the code, and only scrape the date sections needed. Separate script files would be fine if it was needed. Many thanks for your time, Darren. Hi all,
Its been a long time since last help request from real professional from here but I'm again in trouble with a much more spectacular plan I'm working on. For those who are interested in the plan then here it is: My Idea was to make a new build starting from scratch and make it as dynamical as possible. So my goal is not to make almost anything fixed in the code. I have made a decision to make a one supper large table for multiple different entries so no more joining and no more views for me.! In this help request I'm having trouble with Posting values to a page processing page lets call it record_changer.php The sole purpose of this file is to get form posts and decide what to do. Either update, delete, or insert. record_changer.php <?php include '../../config/config.inc.php'; if(is_ajax()){ # Checks if action value exists if(isset($_POST["action"]) && !empty($_POST["action"])){ $action = $_POST["action"]; # Switch case for value of action switch($action){ case "insert": datatable_insert_function(); break; case "update": datatable_update_function(); break; case "delete": datatable_delete_function(); break; } } } # Function to check if the request is an AJAX request function is_ajax(){ return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; } function datatable_insert_function(){ } function datatable_update_function(){ } function datatable_delete_function(){ } ?>The problem. The problem is that the $insert places two entries to the DB. I cant seem to understand why.? # Test _POST values $_POST['UserID'] = '2'; $_POST['WorkID'] = '22'; $_POST['Status'] = '1'; $_POST['Code'] = '1'; $_POST['Title'] = '1'; $columns = array(); foreach(array_keys($_POST) as $name){ # Exclude Action and ID if($name == 'Action' || $name == 'ID' || $name == 'submit' ){ continue; } $columns[] = $name; } print_r($columns); echo "<br>"; $data = array_fill_keys($columns, 'NULL'); print_r($data); foreach($data as $key => $value){ $data[$key] = empty($_POST[$key]) ? 'NULL' : "'".mysql_real_escape_string($_POST[$key])."'"; } echo "<br>"; print_r($data); $insert = mysql_query('INSERT INTO datatable (ID, '.implode(', ',$columns).')VALUES (null, '.implode(',',$data).')') or die(mysql_error());No errors no nothing. Just two entries of correct data. PS. Sorry for a lot of prints in the code it is work and idea in the progress. The posts at the moment are fixed in the code so it is easier to refresh and debug. Please help if you spot the problem. Im really out of ideas. Some fresh eyes might make a difference. And Please for those who want to say it is a bad idea and why and why and so on.. Move a long.!!! Im not interested in whinging i have a great use for this and just having trouble with the two entries. Thanks. Edited by ztimer, 14 January 2015 - 03:27 PM. Alright so I am trying to code a very simple form that adds a user to my SQL database with certain information filled in and certain information kept hidden with default values in a form. My index.php file is as follows (not all of the code but just the form part): <?PHP $submitMessage = $_GET['value']; if ($submitMessage == success) { echo '<div class="congratulations"><font color="#84d20c"><strong>Congratulations:</strong></font> The user has been added.</div>'; }else if($submitMessage == NULL){ }else if($submitMessage == fail){ echo '<div class="error"><font color="#d3430c"><strong>Error:</strong></font> An error occurred please check the error details below:</div>'; echo 'ERROR DETAILS:'; echo mysql_error(); } ?> <h1><i>Add User</i></h1> <p>This page is where you would manually add a user to the donations databases (for example you or a member of the community with elevated status that does not need to pay).</p> <br/> <form enctype="multipart/form-data" action="scripts/admin_save_sm_db.php" method="post"> <input name="authtype" value="steam"/><br /><br /> <h3><i>STEAM ID:</i></h3> <input name="identity" value="STEAM_0:X:XXXXXXXX"/><br /> <div class="form_help">Steam ID of the player you wish to add. Must be in the format STEAM_0:X:XXXXXXXX</div><br /> <input name="flags" value="o"/><br /><br /> <input name="name" value="Donator"/><br /><br /> <input name="immunity" value="0"/><br /><br /> <h3><i>Your Email Address</i></h3> <input name="user_email"/><br /> <div class="form_help">Your Email Address for security purposes.</div><br /> <input name="Submit" type="submit" value="Submit" class="form_submit" /> </form> My admin_save_sm_db.php file is as follows: <?php session_start(); if(!isset($_SESSION["username"])) { header('Location: login.php'); exit; } @require("../sm_admin_db.php"); $authtype = $_POST['authtype']; $identity = $_POST['identity']; $flags = $_POST['flags']; $name = $_POST['name']; $immunity = $_POST['immunity']; $user_email = $_POST['user_email']; $link = @mysql_connect(_HOST,_USER,_PASS); @mysql_select_db(_DB); $sql = @mysql_db_query(_DB,"INSERT INTO "._TBL." (`authtype`, `identity`, `flags`, `name`, `immunity`, `user_email`) VALUES (NULL, '$authtype', '$identity', '$flags', '$name', '$immunity', '$user_email')"); $okay = @mysql_affected_rows(); if($okay > 0) { header( "Location: ../index.php?value=success" ); } else { header( "Location: ../index.php?value=fail" ); } @mysql_close($link); ?> And finally my sm_admin_db.php file is as follows: <?PHP //host loaction define("_HOST", "localhost", TRUE); //database username define("_USER", "thatsact_admin", TRUE); //database username`s password define("_PASS", "*********", TRUE); //database name define("_DB", "thatsact_sadadmins", TRUE); //database table name change this to install multiple version on same database define("_TBL", "sm_admins", TRUE); //This is the email that you will recieve emails when someone signs up. define("_EMAIL", "admin@tag-clan.com", TRUE); ?> All of this together does not work and gives the echo error code, however the mysql_error() string does not return anything. Nothing is inserted into the database. Can I get some help on where I went wrong and please keep in mind I am VERY new to php and didn't write most of this script so just tell me what to edit and exactly how to do it please. Thanks in advance. Alright, I am struggling to get back into the world of programming. I have background in C++ and Javascript, but this was 7 years ago. I am now trying to develop a plugin for a wordpress website I manage and am having a simple problem. It seems like it is at least. Here is what I need to accomplish. I am designing a plugin that generates a random string of text on a wordpress page. It uses a shortcode to return a form onto the page where it is placed. The form has 3 elements, a textbox, a dropdown list, and a submit button. I can do all of this so far. Here is where I am a bit lost. When the submit button is pressed, I need it to run a function passing the value selected in the dropdown list. I would like this to be contained on the same page. So I am not sure what I need to put in the action="", and my guess is I would use the post method. The function that generates the text returns a paragraph. So it would function like this... $paraText = genParagraph($txtType); //txtType would be the drop down value Currently, I do this and return the value (after slightly more processing). My guess is I have to use the $_POST[] function to somehow return the data into the text box on the page. I am not exactly sure how to achieve this. Thank you for your help! There are two pieces to this- The HTML Form and the resulting php. I can't seem to make the leap, from the code to having the form produce the php page so others can view it until the form is again submitted overwriting the php, thus generating new content. The environment I am working in is limited to IIs 5.1 and php 5.2.17 without mySQL or other DB I'm new to php, this isn't homework,or commercialization, it's for children. I am thinking perhaps fwrite / fread but can't get my head around it. Code snipets below. Any help, please use portions of this code in hopes I can understand it Thanks Code snipet from Output.php Code: [Select] <?php $t1image = $_POST["t1image"]; $t1title = $_POST["t1title"]; $t1info = $_POST["t1info"]; $t2image = $_POST["t2image"]; $t2title = $_POST["t2title"]; $t2info = $_POST["t2info"]; ?> ... <tbody> <tr><!--Headers--> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Animal</td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Image thumb<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Date<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Information<br> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Monkey </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t1image.'.gif'; ?>"><!--single image presented selected from radio buttons--> </td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?><!--time stamp generated when submitted form populates all fields at once--> </td> <td style="vertical-align: top; text-align: center;"><a href="#monkey" rel="facebox"><?php echo $t1title ?></a><!--Link name provided by "Title 1", that links to hidden Div generated page with content from "Info1" field--> <div id="Monkey" style="display:none"> <?php echo $t1info; ?> </div> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Cat<br> </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t2image.'.gif'?>"></td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?></td> <td style="vertical-align: top; text-align: center;"><a href="#Cat" rel="facebox"><?php echo $t2title ?></a> <div id="Cat" style="display:none"> <?php echo $t2info; ?> </div> </td> </tr> <tr> This replicates several times down the page around 15-20 times ( t1### - t20###) Code Snipet from HTML Form Code: [Select] <form action="animals.php" method="post"> <div style="text-align: left;"><big style="font-family: Garamond; font-weight: bold; color: rgb(51, 51, 255);"><big><big><span>Monkey</span></big></big></big><br> <table style="text-align: left; width: 110px;" border="0" cellpadding="2" cellspacing="0"> <tbody><tr> <td style="vertical-align: top;">Image thumb<br> <input type="radio" name="t1image" value="No opinion" checked><img src="eh.gif" alt="Eh"> <input type="radio" name="t1image" value="Ok"><img src="ok.gif" alt="ok"> <input type="radio" name="t1image" value="Like"><img src="like.gif" alt="Like"> <input type="radio" name="t1image" value="Dont"><img src="dont.gif" alt="Don't Like"> <input type="radio" name="t1image" value="Hate"><img src="hate.gif" alt="Hate"> <input type="radio" name="t1image" value="Other"><img src="other.gif" alt="Other"> <br> Why Title:<input type="text" name="t1title" size="45" value="..."/></td> <td style="vertical-align: top;"> Explain:<br> <textarea name="t1info" cols=45 rows=3 value="..."></textarea> </td></tr></table> <br> <!--Next--> How do I get the Form data to save to the php page for others to view? Hi, I am learning PHP now, so pardon my silly question which I am not able to resolve from a week. I have created a simple web form where in I display the values entered by a user. <form action ="reply.php" id="myForm" method="post" > Name: <input type="text" name="name" size="25" maxlength="50" /> <br> </br> Description: <textarea name="editor1"> </textarea> <input type="submit" value="Submit" /> </form> and reply.php contains: <?php echo "In reply page"; foreach($_POST as $field => $value) { echo "$field = $value"; } ?> When I click on the submit button, I just get a blank page without any values from the form. Can anyone please let me know what am I missing? Set up: I am using Netbeans with PHP bundle added on to it. When i run only a simple php proj it displays that page in localhost/nameofproj, but when I run a php file along with a jsp file, it runs in localhost:8080/nameofproj. Is this the reason(localhost:8080 instead of just localhost ) for showing a blank page, not even a simple echo stmt, when i click on submit? I even re installed netbeans, still no luck. Thanks in advance. (php is a weakness)
Here is the HTML portion for the form:
<form action="send_form_email.php" id="contacts-form" method="post"> Trying to figure out how to approach this. I have a form that uses php to pull from a mysql database. I can get the text submission form to work but I am having trouble with a drop down menu that pulls directly from the DB and submitting what is selected as the basis of the result query. I am including the two sets of code. one for my search.php and the other for my search_result.php. search.php Code: [Select] <?php require_once('Connections/search_db.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_search_db, $search_db); // Search engine functionality if ($_GET['title'] || $_GET['country2']) { $ti = $_GET['title']; $count = $_GET['country2']; $query_rsLinks = "SELECT * FROM tbl_links WHERE (tbl_links.linkemail LIKE '%$ti%' OR tbl_links.linktitle LIKE '%$ti%' OR tbl_links.linkurl LIKE '%$ti%') AND tbl_links.linkcat LIKE '$count' ORDER BY tbl_links.linkdate DESC"; } else { $query_rsCountries = "SELECT search_db.tb_name FROM search_db"; } $rsCountries = mysql_query($query_rsCountries, $search_db) or die(mysql_error()); $row_rsCountries = mysql_fetch_assoc($rsCountries); $totalRows_rsCountries = mysql_num_rows($rsCountries); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body><form action="search_result.php" method="get" name="fmsearch"> <table width="200" border="1"> <tr> <td>search</td> <td><label for="title"></label> <input name="title" type="text" id="title" /></td> <td><input name="Search" type="button" id="Submit" value="Submit" /> </td> </tr> </table> </form> <br> <!-- action="search_result.php" --> <form id="forminsert" name="fmsearch" action="search_result.php" method="get"> <table border="0" id="tblinsert"> <caption> search for country </caption> <tr> <th><label for="title">search for:</label></td> <th> <input type="text" name="title" id="title" <?php if (isset($_GET['title'])) { echo 'value="' .$GET['title']. '"'; } ?> /> </td> <td><input type="submit" id="button" value="Submit" /></td> </tr> </table> <form id="forminsert" name="fmsearch" action="search_result.php" method="get"> <table border="0" id="tblinsert2"> <caption> search for country </caption> <tr> <td><select name="country2" id="country2"> <option value="">All Countries</option>> <?php do { ?> <option value="<?php echo $row_rsCountries['tb_name']?>"> <?php echo $row_rsCountries['tb_name']?></option> <?php } while ($row_rsCountries = mysql_fetch_assoc($rsCountries)); $rows = mysql_num_rows($rsCountries); if($rows > 0) { mysql_data_seek($rsCountries, 0); $row_rsCountries = mysql_fetch_assoc($rsCountries); } ?> </select></td> <td><input type="submit" id="button" value="Submit" /></td> </tr> </table> </form> </body> </html> <?php mysql_free_result($rsCountries); ?> search_result.php Code: [Select] <?php require_once('Connections/search_db.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_rs83 = "-1"; if (isset($_GET['country2'])) { $colname_rs83 = $_GET['country2']; } mysql_select_db($database_search_db, $search_db); $query_rs83 = sprintf("SELECT * FROM search_db WHERE tb_name LIKE %s", GetSQLValueString("%" . $colname_rs83 . "%", "text"),GetSQLValueString("%" . $colname_rs83 . "%", "text")); $rs83 = mysql_query($query_rs83, $search_db) or die(mysql_error()); $row_rs83 = mysql_fetch_assoc($rs83); $colname_rs83 = "-1"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo $row_rs83['']; ?> <?php do { ?> <table width="300" border="1"> <tr> <td rowspan="2"><img src="<?php echo $row_rs83['tb_Img']; ?>" alt="image" /></td> <td><?php echo $row_rs83['tb_name']; ?></td> </tr> <tr> <td><?php echo $row_rs83['tb_desc']; ?></td> </tr> </table> <?php } while ($row_rs83 = mysql_fetch_assoc($rs83)); ?> <a href="http://barium.worldteam.org/phptesting/search.php">Back to Search</a> </body> </html> <?php mysql_free_result($rs83); ?> Hi All I am trying to upload a csv file to a database using php html form however, the results shows none of the data passsing through to the database and it produces 1000's of empty fields here is the form Code: [Select] form action="lib/import.php" method="post" enctype="multipart/form-data"> Type file name to import: <input type="file" name="filename" size="20"><br /> <input type="submit" name="submit" value="submit"></form> and here is the passing info Code: [Select] $file = $_FILES['filename']; $sqlstatement="LOAD DATA INFILE '$file' into TABLE shop FIELDS TERMINATED BY ',' (id, merchant_name, product_name, description, category_name, Affiliate_deep_link, Affiliate_image_url, price)" ; mysql_query($sqlstatement); echo "it is done!"; can anyone help please? Hello, freaks. I need a little help with the best way to go about this. I have a field in mysql that contains a comma separated string of values. What I need to do is get those values out of the db and list them into editable text fields so the user can update the values in a html form. So far this is my code, I left out all the in betweens - validation, results, etc - for this post...but its there . SELECT servs FROM services WHERE id = $a_id $services = $row['servs']; $srvs = explode(',', $services); Then for the form: <?php foreach ($srvs as $service) { ?> <input type="text" name="servs[]" value="<?php echo $service ?>" /> <?php } ?> This gives me a text field for each value of servs, great! But the problem is, the user can enter up to 15 servs. Some currently have less than that saved in the db. I want to give them the ability to 1. edit any of the current servs value and 2. add more values if they have less than 15. My question is, how do I echo out 15 editable text fields for servs[] no matter the number of values they currently have? And when I go to implode the values, will blank text fields screw everything up? I can't find anything in the forums that relate to this. I believe it probably will involve $i, but I am not too familiar with counting in php yet, so I could really use some help. Thanks! Oh - and I am not stuck on using text fields, but I couldn't figure how to make this work using a select list or checkboxes. Any suggestions either way would help. Hi, I have this script which I would like to use to build an html form from a MySQL table. The <input text................ writes successfully to file but none of the other form types are written to file when using the elseif command Also, I would like this script to carry out the file write foreach row in the table It seems complicated and i am not sure if I am going about it in the right way, but here goes Code: [Select] //// Create Forms from MySQL $result = mysql_query("SELECT * FROM forms"); while($row = mysql_fetch_assoc($result)){ $field_label = $row['field_label']; $column_name = $row['column_name']; $field_type = $row['field_type']; if ($row['field_type'] = 'Text') { $stringData = "$field_label<input type=text name=$column_name>\n"; fwrite($fh, $stringData); } elseif ($row['field_type'] = 'Text Area') { $stringData = "$field_label<input type=textarea name=$column_name></textarea>\n"; fwrite($fh, $stringData); } elseif ($row['field_type'] = 'Select Menu') { $stringData = "$field_label<select name=$column_name></select>\n"; fwrite($fh, $stringData); } elseif ($row['field_type'] = 'Checkbox') { $stringData = "$field_label<input type=checkbox name=$column_name></textarea>\n"; fwrite($fh, $stringData); } fclose($fh); As always, any help is much appreciated 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'm trying to do something that I thought was very simple about 2 weeks ago :-( I want to put a form on my site and link it to a database so when a user types a surname into the form they can search the db and the page will only display the surnames that match the search criteria. I got the db set up using phpmyadmin in about 2 minutes flat, but keep getting error messages when I write the php. I'm currently working with the below script, which keeps giving me the error 'unexpected T_string' on line 176 I've searched every forum and help site I can find, and the mysql and php manuals are just mind-boggling. I'm sure I'm making some really amateur mistake, but I'd really appreciate help with this! thanks all! <html> <head> <title>SEARCH RECORDS</title> </head> <body> <FORM NAME ="Search" METHOD ="POST" ACTION = "test3"> <INPUT TYPE = "TEXT" VALUE ="surname" NAME = "surname"> <INPUT TYPE = "Submit" Name = "Search" VALUE = "Search"> </FORM> </body> </html> <? $user_name = "*****"; $password = "*****"; $database = "*****"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SELECT * FROM *****" WHERE surname=$_POST['surname']; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { print $db_field['Grave'] . "<BR>"; print $db_field['Surname'] . "<BR>"; print $db_field['Forenames'] . "<BR>"; print $db_field['Death_Date'] . "<BR>"; print $db_field['Birth_Year'] . "<BR>"; } mysql_close($db_handle); } else { print "Database NOT Found "; mysql_close($db_handle); } ?> My problem could be odd if say it but i will spill it out, only don't say I am mad completely jut a bit ! 1.when comment is first in whole news if i press edit appear html form but if i am trying to submit any information it returns to comments and don't update ! 2.if there were more than one comment in news if i press edit appear html forms 1.not working | 2.working and do updates | 3.were appear but is gone but not sure does bug will return also not working ! Sample how it looks ! This is indeed odd hope somebody has knowledge in such issues or at least a cure for such severe bug website http://hostings.flush.ws/ user guest password guest11 | to test bug go to the news comments and spam as much needed ! Link to edit code Code: [Select] echo "<a href='/?section=nwcomment&id=".$id."&comment=edit&id_edit=".$row_news_comment['hosting_comment_id']."'>Edit Comment</a>"; Update code as far i know it is correct at least i do hope sow (also this code is inside while cycle ) Code: [Select] if ($_GET['comment'] == 'edit') { $comment_id_edit = (INT)$_GET['id_edit']; $comment_text = $row_news_comment['hosting_comment_text']; $edit_comment_text = $_POST['hosting_comment_text']; if(isset($_POST['hosting_comment_text'])) { mysql_query("UPDATE hosting_comment SET hosting_comment_text = '".$edit_comment_text."' WHERE hosting_comment_id = '".$comment_id_edit."' ") or die (mysql_error()); } if (isset($_POST['Submit'])) { echo "<meta http-equiv='REFRESH' content='0;url=/?section=nwcomment&id=".$id."'>"; } echo ("<form action='/?section=nwcomment&id=".$id."&comment=edit&id_edit=".$comment_id_edit."'' id='edit_comment' name='edit_comment' method='post'> <p> <textarea name='hosting_comment_text' cols='50' rows='10' id='textarea' value='$edit_comment_text' ></textarea> <p> <input type='submit' name='Submit' id='button' value='{$lang['BODY_NEWS_COMMENT_SUBMIT']}' /> <input type='reset' name='Reset' id='button' value='{$lang['BODY_NEWS_COMMENT_RESET']}' /> </p> </form>"); } if is needed more complete code just ask i will publish it (i hope to fix bug as soon possible grand opening of registration will be on the Aprils Fools Day) |