PHP - Issue To Save Values In Database With Multiple Checkboxs In Crud
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 Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
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> I 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[]" /> Hi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
This is actually a page to edit the drama details. Database- 3 tables 1. drama dramaID drama_title 1 friends 2. drama_genre drama_genreID dramaID genreID 1 1 2 2 1 1 3 1 3 3. genre genreID genre 1 comedy 2 romance 3 family 4 suspense 5 war 6 horror <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'drama'; $link = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $id = $_GET['dramaID']; $link2 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql2 = "SELECT * from drama , drama_genre , genre WHERE drama.dramaID='".$id."' AND drama_genre.dramaID='".$id."' AND drama.dramaID = drama_genre.dramaID AND drama_genre.genreID = genre.genreID"; $status2 = mysqli_query($link2,$sql2) or die (mysqli_error($link2)); $link3 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql3 = "SELECT * from genre "; $status3 = mysqli_query($link3,$sql3) or die (mysqli_error($link3)); <form method='Post' action='doUpdate.php' enctype="multipart/form-data"> <?php while ($row2 = mysqli_fetch_assoc($status2)) { ?> <td height="1"></td> <td><select name="gdrop"> <option value="<?php echo $row2['genreID'];?>"><?php echo $row2['genre'];?></option> <?php while ($row3 = mysqli_fetch_assoc($status3)) { ?> <option value="<?php echo $row3['genreID'];?>"><?php echo $row3['genre'];?></option> <?php } mysqli_close($link3); ?> <input type='hidden' id='drama_genreID' name='drama_genreID' value = "<?php echo $row2['drama_genreID']; ?>"/> </select> <input type="hidden" id="dramaID" name="dramaID" value = "<?php echo $row['dramaID'];?>"/> <input type="submit" Value="Update"/> The result was there were 3 dropdown menus but only the first dropdown menu has all 6 genres from my database and also the genre that belongs to the drama. I'm also wondering how I can bring all the drama_genreIDs to my save(doupdate.php) page and update all 3 of them because it seems like only the last dropdown menu's data is saved. And also how can I display only 6 genres instead of 7 with the genre that belongs to the drama , being set as the default selection. I've played around with CakePHP, then XCrud (a decent CRUD application) but I gave up on both of them, XCrud was great for everything up until it came to managing complicated relational database tables. Anyhow, I'm using wordpress a lot now cuz it lets me stop reinventing the wheel so much and although I was able to integrate XCrud into WordPress as a plugin, I think the best way to go is just transfer my database tables to WordPress tables and display them as custom post types. My time is really limited right now though, is there a plugin/set of plugins I can use to automate the process? To show you what I mean, heres the XCrud list display of one of the tables:
thats great because it automatically sets up the CRUD thing and lets you add and edit fields to the table, and doesn't heavily box you into their system but I have a table of plants, one for products, one for pharmacology, one for categories which are all related to each other, and some of them are structured in a tree/nested hierarchy structure so long story short, I need to do advanced searches based on these relations and handle these tree structured tables and CakePHP didn't work out, and XCrud has crappy documentation and isn't popular enough to find good info.
So how would you go about transfering this system to WordPress? I'm guessing I need to make custom post types for each table but what I don't yet know is how to transfer the DB tables to WordPress format, how to handle the relationships between each table and how to handle the hierarchical tree structures.
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309239.0 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.. 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 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
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
One image is displaying but when i choose image 2 it overlaps image 1..
gallery.php 8.77KB
7 downloads
Hi all, I've just finished sorting my Inbox code for my website which all works apart from deleting more than one message at a time. if (isset($_POST['Deleteselected'])){ foreach($_POST['radio'] as $value) { $numm++; mysql_query("DELETE FROM inbox WHERE id='$value'"); } echo "<table class='table' width='30%' align='center' cellpadding='0' border='1' cellspacing='0'> <tr> <td class='header' align='center'>Success</td> </tr> <tr> <td align='center'>$numm messages deleted!</td> </tr> </table><br /> "; } $row = mysql_fetch_array($get_messages2); if($row['read'] == 0) { echo '<tr><td><input class="input" type="checkbox" name="radio[]" value="' . $row['id'] . '"></td><td width="40%" align="center"><a href="rmessage.php?messageid=' . $row['id'] . '">' . $row['title'] . '</a> <font color="red"><strong>**</font> Unread <font color="red">**</strong></font></td><td width="40%" align="center"><a href="profile.php?viewuser=' . $row['from'] . '">' . $row['from'] . '</a></td><td align="center"><a href="?delete='.$row['id'].'"><strong>Delete</strong></td></tr>'; }else{ echo '<tr><td><input class="input" type="checkbox" name="radio[]" value="' . $row['id'] . '"></td><td width="40%" align="center"><a href="rmessage.php?messageid=' . $row['id'] . '">' . $row['title'] . '</a></td><td width="40%" align="center"><a href="profile.php?viewuser=' . $row['from'] . '">' . $row['from'] . '</a></td><td align="center"><a href="?delete='.$row['id'].'"><strong>Delete</strong></td>'; } This is the form which has the button: <form action='' method='POST' name='thishere'> <table width="25%" cellpadding="0" align="center" cellspacing="0" border="1" class="table"> <tr> <td class="header" align="center" colspan="2">Control Panel</td> </tr> <tr> <td align='left' width='50%'> <input name='Deleteselected' class='button' type='submit' id='Deleteselected' value='Delete Selected'></td> </tr> When I select the check box and the press "Delete Selected" It says that the message is deleted but it accually still there and hasnt been deleted. Anyone see why its doing that? Thanks for any help provided 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> yes how?
if you don't understand what do i mean, look on the textarea input, when i type some data in list format they are going to be saved in single column but i cant retrieve them as list but a single paragraph. why? after cloasing connection of database i still got the values form database. Code: [Select] <?php session_start(); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once '../database/db_connecting.php'; $dbname="sahansevena";//set database name $con= setConnections();//make connections use implemented methode in db_connectiong.php mysql_select_db($dbname, $con); //update the time and date of the admin table $update_time="update admin set last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname'limit 3,4"; //my admin table contain 5 colums they are id, username,password, last_logged_date, last_log_time $link= mysql_query($update_time); // mysql_select_db($dbname, $link); //$con=mysql_connect('localhost', 'root','ijts'); $result="select * from admin where username='a'"; $result=mysql_query($result); mysql_close($con); //here i just check after closing data baseconnection whether i do get reselts but i do, why? echo "after the cnnection was closed"; if(!$result){ echo "cont fetch data"; }else{ $row= mysql_fetch_array($result); echo "id".$row[0]."usrname".$row[1]."passwped".$row[2]."date".$row[3]."time".$row[4]; } // echo "<html>"; //echo "<table border='1' cellspacing='1' cellpadding='2' align='center'>"; // echo "<thead>"; // echo"<tr>"; // echo "<th>"; // echo ID; // echo"</th>"; // echo" <th>";echo Username; echo"</th>"; // echo"<th>";echo Password; echo"</th>"; // echo"<th>";echo Last_logged_date; echo "</th>"; // echo "<th>";echo Last_logged_time; echo "</th>"; // echo" </tr>"; // echo" </thead>"; // echo" <tbody>"; //while($row= mysql_fetch_array($result,MYSQL_BOTH)){ // echo "<tr>"; // echo "<td>"; // echo $row[0]; // echo "</td>"; // echo "<td>"; // echo $row[1]; // echo "</td>"; // echo "<td>"; // echo $row[2]; // echo "</td>"; // echo "<td>"; // echo $row[3]; // echo "</td>"; // echo "<td>"; // echo $row[4]; // echo "</td>"; // echo "</tr>"; // } // echo" </tbody>"; // echo "</table>"; // echo "</html>"; session_destroy(); session_commit(); echo "session and database are closed but i still get values from doatabase session is destroyed".$_SESSION['admin']; ?> session is destroyed but database connection is not closed. thanks Hello,
Here is my current code:
index.php
<html> <body> <form id="hey" name="hey" method="post" onsubmit="return false"> Name:<input type="text" name="name"> <input type="submit" name="submit" value="click"> </form> <table class="table table-bordered" id="update"> <thead> <th>Name</th> </thead> <tbody> <script type="text/javascript"> $("#hey").submit(function() { $.ajax({ type: 'GET', url: 'response.php', data: { username: $('#name').val()}, success: function (data) { $("#update").prepend(data); }, error: function (xhr, ajaxOptions, thrownError) { alert(thrownError); } }); }); </script> </tbody> </table>response.php <?php $username = $_GET['username']; echo "<tr>"; echo "<td>$username</td>"; echo "</tr>"; ?>This code works fine, it prints out the rows as what the user enters. Now what I want to do is, log all these entries to a mySQL database and also, display these rows over the site. i.e., any user who is online, should be seeing this without having to refresh the page too.. Real time updates in a way. How can I achieve that? Thanks! <?php $GLOBALS['title']="Admission-HMS"; $base_url="http://localhost/hms/"; require('./../../inc/sessionManager.php'); require('./../../inc/dbPlayer.php'); require('./../../inc/fileUploader.php'); require('./../../inc/handyCam.php'); $ses = new \sessionManager\sessionManager(); $ses->start(); if($ses->isExpired()) { header( 'Location:'.$base_url.'login.php'); } else { $name=$ses->Get("loginId"); } $msg=""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST["btnSave"])) { $db = new \dbPlayer\dbPlayer(); $msg = $db->open(); echo '<script type="text/javascript"> alert("'.$msg.'");</script>'; if ($msg = "true") { $userIds = $db->getAutoId("U"); $flup = new fileUploader\fileUploader(); $perPhoto = $flup->upload("/hms/files/photos/",$_FILES['perPhoto'], $userIds[1]); // var_dump($perPhoto); $handyCam=new \handyCam\handyCam(); if (strpos($perPhoto, 'Error:') === false) { $dateNow=date("Y-m-d"); $data = array( 'userId' => $userIds[1], 'userGroupId' => "UG004", 'name' => $_POST['name'], 'studentId' => $_POST['stdId'], 'cellNo' => $_POST['cellNo'], 'gender' => $_POST['gender'], 'dob' => $handyCam->parseAppDate($_POST['dob']), 'passportNo' => $_POST['passportNo'], 'fatherName' => $_POST['fatherName'], 'fatherCellNo' => $_POST['fatherCellNo'], 'perPhoto' => $perPhoto, 'admitDate' => $dateNow, 'isActive' => 'Y' ); $result = $db->insertData("studentinfo",$data); if($result>=0) { $data = array( 'userId' => $userIds[1], 'userGroupId' => "UG004", 'name' => $_POST['name'], 'loginId' => $_POST['stdId'], 'verifyCode' => "vhms2115", 'expireDate' => "2115-01-4", 'isVerifed' => 'Y' ); $result=$db->insertData("users",$data); if($result>0) { $id =intval($userIds[0])+1; $query="UPDATE auto_id set number=".$id." where prefix='U';"; $result=$db->update($query); // $db->close(); echo '<script type="text/javascript"> alert("Admitted Successfully.");</script>'; } else { echo '<script type="text/javascript"> alert("' . $result . '");</script>'; } } elseif(strpos($result,'Duplicate') !== false) { echo '<script type="text/javascript"> alert("Student Already Exits!");</script>'; } else { echo '<script type="text/javascript"> alert("' . $result . '");</script>'; } } else { echo '<script type="text/javascript"> alert("' . $perPhoto . '");</script>'; } } else { echo '<script type="text/javascript"> alert("' . $msg . '");</script>'; } } Is there anyway of saving data to phpmyadmin, and linking it to another page with one button. I can do it separately but I can't seem to do it using one button. Does anyone has any ideas! Ok. I am trying to create a customer tracking database that will allow me to get a handle on my customer support inquiries. To do this I have created a database that will store all of a customers pertinent information and then I plan on creating another table that will be 'Notes' where each note is associated with a customerID. I have created the form fine where I can input the data into the table but I am having issues with the next part. I would like to have a list/menu that will display all of the current users in the database. Then when I click on one of those it will display that information in the form so that I can view it, edit it, or delete it. But I have been stumped for multiple days and other php forums have been absolutely worthless. I know that php can pass a variable name in the address but I have no idea how to do that or how to use it when it's in the address. I know I'm a newb. Please help. I really need to move on from this hurdle. Code: [Select] <!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> <link href="maxxTraxx.css" rel="stylesheet" type="text/css" /> </head> <body> <?php //Load Database Connectivity and Form Helpers require 'DB.php'; require 'formhelper.php'; //Connect To Database $db = MY CONNECTIVITY IS FINE, HIDING FOR SECURITY PURPOSES if (DB::isError($db)) { die("Cant connect: " .$db->getMessage()); } //Print Message and Quit on Future Database Errors $db->setErrorHandling(PEAR_ERROR_DIE); customerList(); //Main Page Logic if ($_POST['_submit_check']) { foreach($_POST as $key=>$value) { if($key == 'saveCustomer') { //If validate_form() returns errors, show them the form with errors if ($form_errors = validate_formCustomer()) { show_form($form_errrors); } else { //The submitted data is valid, so process it process_formCustomer(); } } if($key =='go') { print $_POST['customerList']; } } }else { //The form wasn't submitted, so display it blank show_form(); } //------------FUNCTIONS--------------------------------------------------------- function show_form($errors = '') { //If the form is submitted, get defaults from submitted parameters if ($_POST['_submit_check']) { $defaults = $_POST; } else { //Otherwise set your own defaults $defaults = ''; } //If errors were passed in, put them in $error_text (with HTML markup) if ($errors) { $error_text = '<tr><td>You need to correct the following errors: '; $error_text .= '</td></tr><ul><li>'; $error_text .= implode('</li><li>',$errors); $error_text .= '</li></ul></td></tr>'; } else { //No errors? Then $error_text is blank $error_text = ''; } $states = array('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'Canada', 'Puerto Rico', 'Australia'); $status = array(1=>'Fine', 2=>'Received', 3=>'In Repair', 4=>'Waiting', 5=>'Shipped'); $months = array(1=>'January', 2=>'February', 3=>'March', 4=>'April', 5=>'May', 6=>'June', 7=>'July', 8=>'August', 9=>'September', 10=>'October', 11=>'November', 12=>'December'); $days = array(); for($i = 1; $i <=31; $i++) { $days[$i] = $i; } $years = array(); for($year = date('Y') , $max_year = date('Y')+5; $year < $max_year; $year++) { $years[$year] = $year; } //Jump out of PHP mode to make displaying all the HTML tags easier but still inside the show_form function ?> <div class="customerForm"> <center><h2>Customer Form</h2></center> <form method="post" action="<?php print $_SERVER['PHP_SELF']; ?>"> <table> <?php print $error_text ?> <tr><td>Last Name</td> <td><?php input_text('customerNameLast', $defaults); ?>, </td> <td>First Name</td> <td><?php input_text('customerNameFirst', $defaults); ?></td> <td>Phone Number</td> <td><?php input_text('customerPhone', $defaults); ?></td></tr></table> <table><tr><td>Address</td> <td><?php input_text('customerAddresss', $defaults); ?></td> <td>City</td> <td><?php input_text('customerCity', $defaults); ?></td> <td>State</td> <td><?php input_select('customerState', $defaults, $states); ?></td> <td>Zip</td> <td><?php input_text('customerZip', $defaults); ?></td></tr></table> <table><tr><td>Email</td> <td><?php input_text('customerEmail', $defaults); ?></td> <td>RMA #</td> <td><?php input_text('customerRMA', $defaults); ?></td> <td>Parts Out</td> <td><?php input_text('customerPartsOut', $defaults); ?></td></tr></table> <table><tr><td>Status</td> <td><?php input_select('customerStatus', $defaults, $status); ?></td> <td>Due Date</td> <td><?php input_select('customerDueMonth', $defaults, $months); ?> <?php input_select('customerDueDay', $defualts, $days); ?> <?php input_select('customerDueYear', $defaults, $years); ?></td></tr></table> <center><?php input_submit('saveCustomer', 'Save Customer'); ?></center> <input type="hidden" name="_submit_check" value="1"/> </form> </div> <?php }//End of the show_form() function function validate_formCustomer() { $errors = array(); return $errors; } function process_formCustomer() { global $db; //Get a unique ID for Customer $customerID = $db->nextID('customerID'); $customerDueDate = $_POST['customerDueYear'].'-'.$_POST['customerDueMonth'].'-'.$_POST['customerDueDay']; $db->query('INSERT INTO Customer (customerID, customerNameLast, customerNameFirst, customerPhone, customerEmail, customerAddress, customerCity, customerState, customerZip, customerStatus, customerPartsOut, customerRMA, customerDueDate) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)', array($customerID, $_POST['customerNameLast'], $_POST['customerNameFirst'], $_POST['customerPhone'], $_POST['customerEmail'], $_POST['customerAddress'], $_POST['customerCity'], $_POST['customerState'], $_POST['customerZip'], $_POST['customerStatus'], $_POST['customerPartsOut'], $_POST['customerRMA'], $customerDueDate)); //Tell the user that we adde a customer print '<center>Added '.htmlentities($_POST['customerNameLast']) .' to the database.</center> <br /><br />'; print '<center><a href="/maxxTraxx/index.php">Back To The Admin</a></center>'; }//End of process_formCustomer function function customerList() { global $db; $qCustomers = $db->query('SELECT customerID, customerNameLast, customerNameFirst FROM Customer'); print '<div class="customerList"><form action="test.php" method="get">'; print '<select name="customerList" size="30">'; while($row = $qCustomers->fetchRow()) { $qAllCustomers[0] = $row[0]; $qAllCustomers[1] = $row[1]; $qAllCustomers[2] = $row[2]; //print $row[0]; //print 'Customer #'.$qAllCustomers[0].' is: '.$qAllCustomers[2].' '.$qAllCustomers[1].''; print '<option value="'.$qAllCustomers[0].'" selected>'.$qAllCustomers[1].', '.$qAllCustomers[2].'</option>'; } print '</select></form></div>'; echo $_POST['customerList']; input_submit('go', 'go'); //return $qAllCustomers; } ?> </body> </html> |