PHP - Get Values From Dynamically Added Textboxes And Save To Database
hello, i'm actually doing a javascript here to create dynamic textboxes when a button is clicked. now my problem is, how to get all the values from these textboxes and save these values altogether in a column on the table..
i know few php coding methods like $_POST in handling values from txtboxes and saving it to database but it doesn't include working with javascript and dynamic textboxes.. and i'm actually doubtful if this is possible..so any help from you guys i would deeply appreciate. heres my code: Code: [Select] <html> <head> <script type="text/JavaScript"> function AddTextBox() { document.getElementById('container').innerHTML+='<input type="text" name="block"><br>'; } </script> </head> <body> <input type="text" name="block"> <div id="container"></div> <br> <button onclick="AddTextBox();">Add another textbox</button> </body> </html> Similar TutorialsI have a table made up of time slots, when the user clicks maybe one or two and presses submit, i would like the date selected and the time slots chosen to be saved in to my sql.
I am working on the query but a little stuck in regards to the query, i have done the following:
<?php $username = "root"; $password = ""; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password) or die ("no connection to database"); if(isset($_POST['Submit'])){ $start = mysql_real_escape_string($_POST['start']); $end = mysql_real_escape_string($_POST['end']); $booked = mysql_real_escape_string($_POST['booked']); $selected = mysql_select_db("booking", $dbhandle); ?>i have set the table as follows <input data-val='08:30 - 08:45' class='fields' type='checkbox' name="booked[]" />
Hello I need a great help for my problem, I tried to insert multiple checkboxs for "$_POST active" in my CRUD and the values must be saved in the database but will be saved as "Array" everytime. foreach($_POST['active'] as $act){//query? } Here the PHP code <?php require_once "../lakota/config.php"; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact'])) { if(isset($_POST["submit"])){ $activearr=$_POST["active"]; $newvalues= implode(",", $activearr); include_once "../lakota/checkboxClass.php"; $checkBoxClass=new checkboxClass(); echo $checkBoxClass->addtoDatabase($newvalues); } $sql = "INSERT INTO lakotabgs (faction, stations, active, pending, influence, id_fact) VALUES (?,?,?,?,?,?)"; if ($stmt = $link->prepare($sql)) { $stmt->bind_param("ssssss", $_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact']); if ($stmt->execute()) { header("location: ../lakota/index.php"); exit(); } else { echo "Error! Try again later."; } $stmt->close(); } } $link->close(); } ?> HTML code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Add new info</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> </head> <body> <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post"> <label><b>Active States</b></label> <input name="active[]" class="form-control" id="example1" type="checkbox" value="None" /> <label for="example1">None</label> <input name="active[]" class="form-control" id="example2" type="checkbox" value="Everybody" /> <label for="example2">Everybody</label> <input name="active[]" class="form-control" id="example3" type="checkbox" value="Unknown" /> <label for="example3">Unknown</label> <input type="submit" id="submit" name="submit" class="btn btn-primary" value="Add new info"> <a href="../lakota/index.php" class="btn btn-default">Back</a> </form> </body> </html> Edited November 14, 2020 by AccuCORE How do I find the nearest div of dynamically added html?
Hi, I have set up 2 php pages page 1 - add_entry2.php In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1 Now the problem starts here on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it. One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. here is the code(I have removed the java script functionalities to reduce length of the post) add_entry2.php Code: [Select] <html> <head> <title>Page Title</title> </head> <body leftmargin="0" topmargin="0"> <!--- forms are good when you wanna actually do stuff ---> <form action="add_entry3.php" name="eval_edit" method="post" format="html"> <table align="center" width = "75%"> <tr> <td align = "center"> Invoice </td> </tr> <tr> <td align = "center"> <!--- very imporant to give the table an id ---> <!--- otherwise it won't know where to edit ---> <table border="1" id="mySampleTable"> <tr> <th>Item No</th> <th>Item Name</th> <th>Item code</th> <th>Description</th> <th>Unit Cost</th> <th>Quantity</th> <th>Price</th> <th>Cancel ?</th> </tr> <tr> <td>1</td> <td><input type="text" name="itemname[]" size="40" maxsize="100"/></td> <td><input type="text" name="itemcode[]" size="20" maxsize="100" /></td> <td><input type="text" name="description[]" size="20" maxsize="100" /></td> <td><input type="text" name="unitcost[]" size="10" maxsize="100" /></td> <td><input type="text" name="quantity[]" size="4" maxsize="100" /></td> <td><input type="text" name="price[]" size="10" maxsize="100" /></td> <td><input type="CHECKBOX" name="cancel[]"/></td> </tr> </table> <table id="totaltbl"> <tr> <th>Total</th> <th>Vat%</th> </tr> <tr> <td><input type="text" name="total" size="20" maxsize="100" /></td> <td><input type="text" name="total" size="3" maxsize="3" /></td> </tr> </table> <!--- our buttons call our javascript functions when clicked ---> <p> <input type="button" value="Add Row" onclick="addRow();" /> <input type="button" value="Calculate Total Amount" onclick="Totalcal();" /> <input type="hidden" name="count" value=""/> <!--<input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />--> <input type="submit" name="submit" value="View Bill" /> <input type="hidden" name="submitted" value="true" /> </p> </td> </tr> </table> </form> </body> </html> ****************************************************8888 This is add_entry3.php Code: [Select] <?php $num=count($_POST['itemcode']); $itemname= $_POST['itemname']; $itemcode = $_POST['itemcode']; $unitcost = $_POST['unitcost']; $description = $_POST['description']; $unitcost = $_POST['unitcost']; $quantity = $_POST['quantity']; $price = $_POST['price']; $problem = FALSE; ?> <h1 align ="center"><b><u>Invoice Details</b></u></h1> <table align="center" width = "75%"> <tr> <td align = "center"> <table border="1" id="mySampleTableheader"> <tr> <td width="75"><b>Item No</b></td> <td width="275"><b>Item Name</b></td> <td width="155"><b>Item code</b></td> <td width="155"><b>Description</b></td> <td width="95"><b>Unit Cost</b></td> <td width="60"><b>Quantity</b></td> <td width="95"><b>Price</b></td> </tr> </table> <?php $i=0; while ($i < $num) { ?> <!--- forms are good when you wanna actually do stuff ---> <form action="save_entry.php" name="eval_edit" method="post" format="html"> <table border="1" id="mySampleTable"> <tr> <td width="75"><?php echo $i+1; ?></td> <td><input type="text" name="itemname[]" value = "" size="40" maxsize="100" readonly/></td> <td><input type="text" name="itemcode[]" value ="<?php echo $itemcode[$i]; ?>" size="20" maxsize="100" readonly/></td> <td><input type="text" name="description[]" value ="<?php echo $description[$i]; ?>" size="20" maxsize="100" readonly/></td> <td><input type="text" name="unitcost[]" value ="<?php echo $unitcost[$i]; ?>" size="10" maxsize="100" readonly/></td> <td><input type="text" name="quantity[]" value = "<?php echo $quantity[$i]; ?>" size="4" maxsize="100" readonly/></td> <td><input type="text" name="price[]" value = "<?php echo $price[$i]; ?>" size="10" maxsize="100" readonly/></td> </tr> </table> <?php $i++;} ?> <!--- our buttons call our javascript functions when clicked ---> </td> </tr> </table> <p> <table id="totaltbl"> <tr> <th>Total</th> </tr> <tr> <td><input type="text" name="total" size="20" maxsize="100" /></td> </tr> </table> <input type="button" value="Add Row" onclick="addRow();" /> <input type="button" value="Row count" onclick="countRow();" /> <input type="hidden" name="count" value=""/> <!--<input type="hidden" name="count" value=""/> <input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />--> <input type="button" value="Back" onClick="history.go(-1);return true;"> <input type="submit" name="submit" value="Finalise" /> <input type="hidden" name="submitted" value="true" /> </p> </form> </body> </html> Hi there, I am working on a PHP form and running a loop to generate textboxes at runtime. This code output the textboxes: foreach ($MyTest as $tst) { echo "<input name='testName' type='text' size='12' maxlength='5' />"; } I am able to display (or output) 4 or sometimes 6 textboxes depending on the variable $MyTest. Now after I enter the values in these texboxes. Lets say, it outputs 3 textboxes, I woud like to display the values like: In Textbox 1 you entered: In Textbox 2 you entered: In Textbox 3 you entered: How can I get (or fetch) values from the textboxes generated through the loop. Please reply. All comments and feedbacks are always welcomed! Thank you Hey guy <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Examination", $con); $sql="INSERT INTO Test (Tes_Name, Tes_Description) VALUES ('$_POST[Tes_Name]','$_POST[Tes_Description]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> This is my code and I can enter Tes_Name on to mysql but nothing is shown for Tes_Description. The form is Code: [Select] <html> <body> <h3>Test</h3> <table border="0"> <form method="POST" action="try2.php"> <tr><td>Tes_Name</td><td>:</td><td><input type="text" name="Tes_Name" size="20"></td></tr> <tr><td>Tes_Description</td><td>:</td><td><input type="Tes_Description" name="password" size="20"></td></tr> <tr><td> </td><td> </td><td><input type="submit" value="Submit"></td></tr> </form> </table> </body> </html> I have a membership site that a user creates a username and password at registration. The user logs in and all that works. The usersname is located in the database under users. Each page is protected and you must login to access it. Here is the code for that
checkLogin('2'); $getuser = getUserRecords($_SESSION['user_id']);If the user login is correct they have access to the page. This all works fine as I said. On this page is a form that gets filled out. All the data except the username is added to the database for the contents of this form. I need to have the username added to the database to track who the data belongs to. Here is the code I have for this, can some tell me where I messed up. The line under the the code <body> pulls the username and the echo command prints the username on the page. I repeated this code under the if ($_SERVER['REQUEST_METHOD'] == "POST") code and it also prints the username. <?php // this is processed when the form is submitted // back on to this page (POST METHOD) if ($_SERVER['REQUEST_METHOD'] == "POST") { $usernow = $getuser[0]['username']; $userid = $usernow; echo "$userid"; # escape data and set variables $userid = addslashes($_POST["userid"]); $date = addslashes($_POST["date"]); $temperature = addslashes($_POST["temperature"]); $ph = addslashes($_POST["ph"]); $ammonia = addslashes($_POST["ammonia"]); $nitrite = addslashes($_POST["nitrite"]); $nitrate = addslashes($_POST["nitrate"]); $phosphate = addslashes($_POST["phosphate"]); $gh = addslashes($_POST["gh"]); $kh = addslashes($_POST["kh"]); $iron = addslashes($_POST["iron"]); $potassium = addslashes($_POST["potassium"]); $notes = addslashes($_POST["notes"]); // # setup SQL statement $sql = " INSERT INTO water_parameters "; $sql .= " (id, userid, date, temperature, ph, ammonia, nitrite, nitrate, phosphate, gh, kh, iron, potassium, notes) VALUES "; $sql .= " ('', '$userid', '$date', '$temperature', '$ph', '$ammonia', '$nitrite', '$nitrate', '$phosphate', '$gh', '$kh', '$iron', '$potassium', '$notes') "; // #execute SQL statement $result = mysql_query($sql); // # check for error if (mysql_error()) { print "Database ERROR: " . mysql_error(); } print "<h3><font color=red>New Water Parameters Were Added</font></h3>"; } ?> I have a code that works but it wont add the data to my database. It says the data has been added but the actual data is not actually added. I have checked through this code to see any errors but I cant find any. Can someone help me Code: [Select] $sqll= takeanexam($_SESSION['username1'], $_SESSION['ssubject'], $_SESSION['smodule']); // mysql_data_seek(sqll, 0); while($info = mysql_fetch_array( $sqll )) { $questionId = $info['Que_ID']; $choice = array(); for ($i =1; $i < 5; $i++) { if (empty($_POST['choice'][$questionId][$i])) { $choice[$i] = 0; } else { $choice[$i] = 1; } } $username= $_SESSION['username1']; mysql_query("INSERT INTO answer (Ans_Answer1, Ans_Answer2, Ans_Answer3, Ans_Answer4, Que_ID, Use_ID) VALUES ({$choice[1]}, {$choice[2]}, {$choice[3]}, {$choice[4]}, $questionId, $username)"); } Ok, first off, I tested my own coded reg system and when I make an error test, the error shows but the user info gets added to the database. How can I stop letting the code add the user to the database when an error occurs. <?php include "lang.php"; ?> <!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>PokePals - Registering</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js" /> <link rel="stylesheet" type="text/css" href="style.css" /></head> <body> <?php include "navbar.php"; ?> <?php // Important stuff goes here include "sql_local.php"; include "ban.php"; // Now for the registration page echo "<div class='panel'>"; if (isset($_POST["submit"])) { // Define the variables here $user = mysql_real_escape_string ($_POST["user"]); $pass1 = mysql_real_escape_string ($_POST["pass"]); $pass2 = mysql_real_escape_string ($_POST["passconf"]); $email = mysql_real_escape_string ($_POST["email"]); $email2 = mysql_real_escape_string ($_POST["email2"]); $dpfc = mysql_real_escape_string ($_POST["dpfc"]); $platinumfc = mysql_real_escape_string ($_POST["platinumfc"]); $hgssfc = mysql_real_escape_string ($_POST["hgssfc"]); $otherfc = mysql_real_escape_string ($_POST["otherfc"]); $favoritepkmn = mysql_real_escape_string ($_POST["favoritepkmn"]); $aboutme = mysql_real_escape_string ($_POST["aboutme"]); $hobbies = mysql_real_escape_string ($_POST["hobbies"]); $favorites = mysql_real_escape_string ($_POST["favorites"]); $gender = mysql_real_escape_string ($_POST["gender"]); // Now check for some errors // Did he/she fill out the form completely? Lets find out function errors() { if (!$_POST["user"] | !$_POST["pass"] | !$_POST["email"] ) { echo "<div class='error'>Please fill in the required fields</div>"; } // Passwords match if ($_POST['pass'] != $_POST['passconf']) { echo "<div class='error'>Password does not match with the other one</div>"; } // Email match if ($_POST['email'] != $_POST['email2']) { echo "<div class='error'>Email does not match with the other one</div>"; } } // Is the user banned? foreach($banned_ips as $ip_ban) { if($user_ip == $ip_ban) { die ("<div class='error'>Your IP address is banned from registering. Contact the site administrator for more info</div>"); } } // If there are no errors, start adding the information to the database if (!errors()) { // Secure the passwords $securepass = md5($pass1); // Submit to the database $insertuser = "INSERT INTO users (user, password, email, dpfc, platinumfc, hgssfc, otherfc, favoritepkmn, aboutme, hobbies, favorites, gender, regip) values ('$user', '$securepass', '$email', '$dpfc', '$platinumfc', '$hgssfc', '$otherfc', '$favoritepkmn', '$aboutme', '$hobbies', '$favorites', '$gender', '$user_ip')"; $add = mysql_query($insertuser, $con) or die ('Error: ' . mysql_error() . ' Please contact an admin'); if ($add) { echo ("<h3>Registration Success</h3><p>You may now login using your username and password. Start hatching some eggs now!</p>"); } } } ?> <div class='registerform'><form action='register.php' method='post'> <label>Username *</label> <input type='text' name='user' class='form1' value='<?php echo @$_POST['user']; ?>' /> <fieldset><legend>Password</legend> <label>Enter your password *</label> <input type='password' name='pass' class='form1' value='<?php echo @$_POST['pass']; ?>' /> <label>Password again *</label> <input type='password' name='passconf' class='form1' value='<?php echo @$_POST['passconf']; ?>' /> </fieldset> <fieldset><legend>Email</legend> <label>Enter your email *</label> <input type="text" name="email" class="form1" value="<?php echo @$_POST['email']; ?>" /> <label>Enter email again *</label> <input type="text" name="email2" class="form1" value="<?php echo @$_POST['email2']; ?>" /> </fieldset> <input type="submit" name="submit" class="submitbutton" value="Register!" /> </form> Well, folks, thanks to all the help, I've narrowed my problem down to needing a way to allow a variable value to traverse into subsequent calls of a function. I have a simple integer - "companyID", and it's set in "actionfile.php" which is called by two forms. The first time it's called by Form A, it's set. I'd LIKE to put it into $_SESSION, but apparently $_SESSION is zeroed out before I can use it in the second call to "actionfile.php" by Form B. A new form/function call is a new session? I've tried setting it to global and static, to no avail. Anything more elegant than writing the value to SQL for later retrieval? Thanks! Mark Hi all I have a form with a few textareas and a bunch of input fields. The input fields are dynamically created from querying a country table. $query = $DB->query("SELECT country_code, country_id, IF(country_code = '".$country_code."', '', '') AS sel FROM countries WHERE site = 'test' ORDER BY country_name ASC"); foreach ($query->result as $row) { $options .= '<label>' . 'Phrase for ' . $this->settings['countries'][$row['country_code']] . '</label>' . '<br />'; $options .= '<input style="width: 100%; height: 5%;" id="country_data" type="text" name="' . $row['country_id'] . '" />' . '<br /><br />'; $options .= '<input type="hidden" name="country_id" id="country_id" value="' . $row['country_id'] . '" />'; } This is fine and outputs all the input fields I need. The problem comes when I need to get the value of each field input field and pass it into a query. The 'value' field of the inputs are numbers, such as 68, 70, 124, 108 etc so I can't get them in a for loop etc What's the easiest way to get all of these input field values? Can I use $_POST? Let's say I have a script that updates the database every 5 minutes. Or fwrites to a text file at an interval. How do I say create a dynamic textbook or label that displays this information and automatically UPDATES on the page without the user clicking on REFRESH? my name is fairooj and ama new to php and jquery. i have a proplam. i want your help.
<script type="text/javascript"> var count = 0; $(function(){ $('p#add_field').click(function(){ count += 1; $('#container').append( '<strong>Link #' + count + '</strong><br />' + '<input id="field_' + count + '" name="fields[]' + '" type="text" />' + '<input id="code_' + count + '" name="code[]' + '" type="text" /><br />' ); }); }); </script> One image is displaying but when i choose image 2 it overlaps image 1..
gallery.php 8.77KB
7 downloads
Hi.. I just want to know how can I save to another table all data that I display using while loop. Now I encountered only one row was save. Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sr_date = $_GET['sr_date']; $sr_number = $_GET['sr_number']; $Items = $_GET['Items']; $SubItems = $_GET['SubItems']; $ItemCode = $_GET['ItemCode']; $DemandedQty = $_GET['DemandedQty']; $UoM = $_GET['UoM']; $Class = $_GET['Class']; $Description = $_GET['Description']; $BINLocation = $_GET['BINLocation']; $RequestedBy = $_GET['RequestedBy']; $ApprovedBy = $_GET['ApprovedBy']; $ReceivedBy = $_GET['ReceivedBy']; $IssuedBy = $_GET['IssuedBy']; $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; } else { $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items1 = document.getElementById("Items1").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items1="+Items1+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition.php"; } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" > <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li> <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td> </tr>"; $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_array($res_sub)){ $Items1 = $row_sub['Items']; $SubItems = $row_sub['SubItems']; $ItemCode = $row_sub['ItemCode']; $UoM = $row_sub['UoM']; $Class = $row_sub['Class']; $Description = $row_sub['Description']; $BINLocation = $row_sub['BINLocation']; echo "<tr> <td style='border: none;'> <input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td> <!--<td style='border: none;'> <input type='hidden' value='$cast[$i]['id']' id='Items1' name='Items1[]'></td> --> <td style='border: none;'> <input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> </tr>"; } $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items1', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description', '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items1', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty', UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy', ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'"; $result = mysql_query($sql, $con); } ?> </table> </div> <div id='RequestedBy'> <label>Requested By:</label> <select name="Requested_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ApprovedBy'> <label>Approved By:</label> <select name="Approved_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ReceivedBy'> <label>Received By:</label> <select name="Received_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id='IssuedBy'> <label>Issued By:</label> <select name="Issued BY"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onclick="save_sr()"> </div> </body> </html> I attach the sample form and output. Sorry if I repost my previous thread. I hope somebody can help me. Thank you I need to add date of birth field to registration form and then save it to databse. I cannot figure out what might be best way of storing the date in the table. I could convert it to unix epoch time, or I could do YYYYMMDD.
Thoughts? What would be the easiest method of saving the DOB?
I am not asking on how to do it, just the format. Thanks
Hi, I'm trying to save data from an array to database but something is wrong. This is from i send data, as you see im using arrays [] because the user have the posibility to clone the row <div class="box-body"> <div class="form-group"> <label class="col-sm-2">Student</label> <div class="col-sm-10"> <table id="table" border="1" bordercolor="#00acc1"> <thead> <tr> <th><p>Name</p></th> <th><p>Mode</p></th> <th><p>Sport</p></th> <th> </th> </tr> </thead> <tbody> <tr> <td><select style="width:325px" name="Name[]" class="form-control"> <option value="">Select</option> <?php $search = "SELECT * FROM prof"; $data = $connect->prepare($search); $data->execute(); while($re=$data -> fetch(PDO::FETCH_ASSOC)){ echo "<option value = '".$re['id']."'>"; echo $re['n_prof'].' '.$re['ap_prof'];} ?> </select> </td> <td> <select class="form-control" name="mode[]" style="width:150px" /> <option value="">Select</option> <option value="Administrator">Administrator</option> <option value="Scholar">Scholar</option> <option value="External student">External student</option> <option value="Thesis">Thesis</option> <option value="Voluntary">Voluntary</option> </select> </td> <td> <select class="form-control" name="Sport[]" style="width:150px" /> <option value="">Select</option> <option value="Football">Football</option> <option value="Baseball">Baseball</option> <option value="Swimming">Swimming</option> <option value="Horse riding">Horse riding</option> <option value="basketball">basketball</option> </select> </td> <td class="Delete">Delete</td> </tr> </tbody> </table> <input type="button" id="add" value="+ add student" class="btn btn-primary"/> </div> </div> </div> my db.table is like this id | name | mode | sport | idstudent_fk And Im using an algorithm to read the array and every time can save every row, but im usind PDO and im having problems try{ here i insert data in a table here i got the last id from that table then ... if($_POST['name']!="" and $_POST['mode']!="" and $_POST['sport']!=""){ if(is_array($_POST['name'])){ while(list($key, $name) = each($_POST['name']) and list($val,$mode) = each($_POST['mode']) and list($id, $sport) = each($_POST['sport'])){ $sql = "INSERT INTO sports(id_studentfk, mode_stu, sport, id_projfk) values(:value, :mode, :sport, :lastid)"; $statement = $connect ->prepare($sql); $statement -> bindParam(':name', $name, PDO::PARAM_INT); $statement -> bindParam(':mode', $mode, PDO::PARAM_STR); $statement -> bindParam(':sport', $sport, PDO::PARAM_STR); $statement -> bindParam(':lastid', $lastid, PDO::PARAM_INT); $pdoExec = $statement -> execute(); } }//end if array }//end if post } catch (PDOException $e) { print 'ERROR: '. $e->getMessage(); print '<br/>Data Not Inserted'; } the idea is creating a loop to read the array and every time can insert data. Im using PDO this time is not working, im geeting this error
ERROR: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined I hope someone can help me to solve this
hey i am using a MySql database and i need to create a dynamic HTML table with one of its columns as checkboxes.so i have to create multiple checkboxes.but these checkbox values are to be stored in a mysql table and then later retrieved when form reloads.and depending on previous state when form was submitted, the newly created checkboxes have to be checked in the same manner.so how do i store multiple checkbox values in my table and also how do i retrieve them? please help. My current project requires me to save the number of views an image (banner ad) has appeared on users website. The problem here is that the image will be appearing on several users website and i want to be able to save the number of times it has appeared on my database. I know how to do this if the image was on the same server as the database, but not when the image and database are on completely different servers. This is somewhat like analytic where it tracks the visitors to a page. Does anyone how i can accomplish this? i figured i would need to create a JavaScript code to provide to the user so they can place it on the site but how do i get that code to connect to my database? Hello folks I am new to php and I have been trying to put together a database that a user can search and choose from the results. I have managed to make this script by copying code from google searches and trial and error. The script so far has been tested and works. The hard part is the code for choosing from the results, I have tried some things but I have been far from the mark, the thing is I can't get my head around the problem, if the first field is a number which is unique to each row, how can I pick that up in a php argument. I have tried making the first field an href link to send that number to a different table which would collect the results of the users choices, but I'm just not sure what to put in the code. Could someone throw me a lifeline here I've searched for hours on google to find any code that looks like it would work with no luck. // Get the search variable from URL $var = @$_GET['a'] ; $trimmed1 = trim($var); //trim whitespace from the stored variable $var = @$_GET['b'] ; $trimmed2 = trim($var); $var = @$_GET['c'] ; $trimmed3 = trim($var); $var = @$_GET['d'] ; $trimmed4 = trim($var); $var = @$_GET['e'] ; $trimmed5 = trim($var); $var = @$_GET['f'] ; $trimmed6 = trim($var); //connect to your database mysql_connect("localhost","root",""); //(host, username, password) //specify database mysql_select_db("a2149809_MV") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "SELECT * FROM `table` WHERE `field1` LIKE \"%$trimmed1%\" AND `field2` LIKE \"%$trimmed2%\" AND `field3` LIKE \"%$trimmed3%\" AND `field4` LIKE \"%$trimmed4%\" AND `field5` LIKE \"%$trimmed5%\" AND `field6` LIKE \"%$trimmed6%\" order by `field1`"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); <table width="100%" border=2 cellspacing=2 cellpadding=2> <tr><form name="form" action="" method="get"> <td colspan="6"><input type="submit" name="Submit" value="Search" /> </td> </tr> <tr> <td><input type="text" name="a" value="" size="4" /></td> <td><input type="text" name="b" value="" size="40" /></td> <td><input type="text" name="c" value="" size="3" /></td> <td><input type="text" name="d" value="" size="10" /></td> <td><input type="text" name="e" value="" size="10" /></td> <td><input type="text" name="f" value="" size="10" /></td> </form></tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"Field1"); $f2=mysql_result($result,$i,"Field2"); $f3=mysql_result($result,$i,"Field3"); $f4=mysql_result($result,$i,"Field4"); $f5=mysql_result($result,$i,"Field5"); $f6=mysql_result($result,$i,"Field6"); ?> <tr> <td><?php echo $f1; ?></td> <td><?php echo $f2; ?></td> <td><?php echo $f3; ?></td> <td><?php echo $f4; ?></td> <td><?php echo $f5; ?></td> <td><?php echo $f6; ?></td> </tr> <?php $i++; } ?> </table> |