PHP - On Checkbox Select, Update Textarea-info In The Right Database-field.
Or something like that... I am not sure how to put this..
Anyway, I'll just get started with explaining my problem. I have an admin-page in which you can delete the comments given on blogs, using checkboxes and clicking on a button with the value 'verwijderenSubmit'. The deletion part works just fine, nothing wrong. However, I also want to be able to EDIT the comments with an other button called 'bewerkenSubmit', using the same checkboxes that I use for deletion. Selecting the right CID (CommentID) is no problem, because that works the same as the deletion-part, but selecting the right textarea to update into the database is the problem... I uploaded a file here with the whole code: http://dhost.info/ddfs/myproblem.html I escaped the textarea within with square brackets, because otherwise the whole textarea would screw up.. I also added <!-- RELEVANT CODE --> to select the parts that I need to change. Well, I hope you understand my problem and can help. Similar TutorialsHi i have this simple update form and scrip but somehow it doesnt seem to be update the field on the database can someone help out please. The html form is the second form bellow where the action send to status_update.php HTML FORM Code: [Select] <?php include("../header.html"); ?> <?php include("header_news.html"); extract($_REQUEST,EXTR_SKIP); ?><?php /* print("sfilm_refnum = $sfilm_refnum<BR>"); print("sfilm_addr01 = $sfilm_addr01<BR>"); print("sfilm_postcode = $sfilm_postcode<BR>"); print("Film Client = $fclient<BR>"); */ ?> <form id="search" action="list.php" method="post" name="search"> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td align="right" width="140"></td> <td width="320"><span class="hofblack10"> </span> </td> <td align="center" width="100"><input type="hidden" name="lstart" value="<?php print("$lstart"); ?>" /><input type="hidden" name="lend" value="<?php print("$lend"); ?>" /><input type="hidden" name="lamount" value="<?php print("$lamount"); ?>" /></td> <td align="center" width="100"></td> <td align="right"></td> </tr> </table> </form> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#4050c4"> <tr> <td width="60" class="hofwhite10">action</td> <td width="140"><span class="hofwhite14">DATE</span></td> <td width="80"><span class="hofwhite14">ID</span></td> <td><span class="hofwhite14">News Titile</span></td> <td width="100"><span class="hofwhite14">Status</span></td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table><table width="780" border="0" cellspacing="0" cellpadding="4"><tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> <tr height="0"> <td width="60" height="0"></td> <td width="80" height="0"></td> <td height="0"></td> <td align="right" width="120" height="0"></td> </tr> </table> <?php //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select DATABASE."); $query2="SELECT * FROM news WHERE !(news_status='deleted')"; $result2 = mysql_query($query2) or die("Couldn't execute QUERY - Select NEWS Qty"); $fqty = mysql_num_rows($result2); //SELECT or FIND the same USERNAME $query3="SELECT * FROM news WHERE !(news_status='deleted') ORDER BY news_id DESC"; $result3 = mysql_query($query3) or die("Couldn't execute QUERY - Select NEWS"); while ($row = mysql_fetch_array($result3)) { $news_id = $row['news_id']; $news_title = $row['news_title']; $news_story = $row['news_story']; $news_image = $row['news_image']; $news_image_caption = $row['news_image_caption']; $news_image_link = $row['news_image_link']; $news_date_day = $row['news_date_day']; $news_date_month = $row['news_date_month']; $news_date_year = $row['news_date_year']; $news_status = $row['news_status']; $news_website = $row['news_website']; $news_date_created = $row['news_date_created']; $news_date_modified = $row['news_date_modified']; ?> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td width="60"><span class="hofblack10"> <?php if($news_status=="deleted"){ print("<a class='hifblack10'>deleted</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>edit</a>"); } ?> </span></td> <td width="140"><span class="titlegrey12"> <?php if(!$news_date_day) { echo "00"; } else{ echo $news_date_day; } echo "/"; if(!$news_date_month) { echo "00"; }else{ echo $news_date_month; } echo "/"; if(!$news_date_year) { echo "0000"; }else{ echo $news_date_year; } ?> </span></td> <td width="80"><span class="titlegrey12"><?php print("$news_id"); ?></span> </td> <td><?php if($news_status=="deleted") { print("<class='hofblack10'>$news_title</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>$news_title</a>"); } ?></td> <td width="100"> <form id="list_update" action="status_update.php" method="post" name="list_update"> <select name="newnstatus" size="1"> <option <?php if($row['news_status'] == "") { print("selected"); } ?> selected="selected" value="">Status...</option> <option <?php if($row['news_status'] == "on") { print("selected"); } ?> value="on">On</option> <option <?php if($row['news_status'] == "off") { print("selected"); } ?> value="off">Off</option> <option <?php if($row['news_status'] == "deleted") { print("selected"); } ?> value="deleted">Delete</option> </select> <input type="hidden" name="nstatus" value="<?php echo $row[news_status]; ?>" /> <input type="hidden" name="id" value="<?php echo $row[news_id]; ?>" /> <input type="submit" name="update" value="update" /> </form> </td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table> <?php } mysql_close($connection);//}?> <table width="780" border="0" cellspacing="0" cellpadding="4"> <tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> </table><?php // include("list_navigation.html"); ?> <?php include("../footer.html"); ?> </div></body></html> The action script php Code: [Select] <?php /* echo "fstatus: ".$fstatus."<BR>"; echo "id: ".$id."<BR>"; echo "fclient: ".$fclient."<BR>"; echo "newfstatus: ".$newfstatus."<BR>";*/ //set the date of agreement $timestamp = date('l jS \of F Y h:i:s A'); //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select FILMS DATABASE."); // All appears well, so enter into database $query= "UPDATE news SET news_status = '$newnstatus' WHERE news_id='$id'"; $result = mysql_query($query) or die("could not execute query - Update FILMS Record to DB"); //setup an email to the Admin @ hof, w/o attachment $emailto="xx@xxx.co.uk"; $emailfrom="no-reply@xxxx.co.uk"; $emailsubject="xx Record Updated"; $emailmessage="Hello Registrar\n\n"; $emailmessage.="News ID: ".$id."\n"; $emailmessage.="Updated on: ".$timestamp."\n\n"; $emailmessage.="Status was: ".$nstatus."\n"; $emailmessage.="Status now: ".$newfnstatus."\n"; $emailmessage.="Thank you,\n\n"; $emailmessage.="Web Site ROBOT\n"; $emailmessage.="(Administrator)\n"; $emailmessage.="xxx.co.uk | xxx.biz\n"; $emailmessage.="----------------------------------------------\n"; $emailmessage.="e. http://www.xxx.co.uk/contact.php\n"; $emailmessage.="w. http://www.xxx.co.uk\n"; $emailheader="From: xxx.co.uk<$emailfrom>"; $emailheader .= 'Cc: xxx@xxx.co.uk'."\r\n"; $emailheader .= 'Bcc: xxx@xxxxx.co.uk'."\r\n"; $ok=mail($emailto,$emailsubject,$emailmessage,$emailheader); mysql_close($connection); if ($ok) { header("Location: list.php"); /* Redirect browser */ exit; } else { $errmsg="There was a problem, please try later or telephone us direct."; $errsta="1"; include("edit_error.html"); //echo "<p>Mail could not be sent. Sorry!</p>"; exit; } ?> Thanks in advance Howdy, I'm trying to display text from a table in a database. It's a list of quotes, so I just need to pull out the quote and the author name. However, the quote and name are not fields in the same record; they are separate records. Example data: Code: [Select] quoteid name value 1 content You guys are great! Thanks for being awesome. 1 author John Jackson 2 content Gosh you're amazing! Always been so darn helpful! 2 author Peter Davis So, I just need to rip out the data from 'content' and 'author', and then group them together based on the quoteid. This is my code thus far: $testimonial_resource = mysql_query("SELECT name, value FROM quotes GROUP BY quoteid ORDER BY author ASC") or die(mysql_error()); while ($testimonial = mysql_fetch_assoc($testimonial_resource)) { echo '<p>'.$testimonial['value']'.<br /><strong>'.$testimonial['value'].'</strong></p>'; } Any help would be greatly appreciated for this novice. Cheers. Hi, I need to make it so the items on my page are only displayed if the value in their database column is set to 1 (and 0 for no display). And I should be able to change those values with a checkbox toggle on my admin panel. Ideally I wouldn't have to click submit either. Table: <table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%"> <thead> <tr> <th>ID</th> <th>Item name</th> <th>Item group</th> <th>Actions</th> <th>Display</th> </tr> </thead> <tbody> <?php if($result -> num_rows > 0){ while($row = $result-> fetch_assoc()){ echo "<tr>"; echo "<td>" . $row["id"] ."</td>"; echo "<td>" . $row["item_name"]. "</td>"; echo "<td>" . $row["group_name"] ."</td>"; ?> <?php require_once "deleteitem.php"; ?> <td> <a href="edititem.php?edit=<?php echo $row['id']; ?>" name="edit"><i class="material-icons">edit</i></a> <a href="?delete=<?php echo $row['id']; ?>" name="delete"><i class="material-icons">delete</i></a> </td> <td> <form action="displayitem.php" method="POST"> <div class="togglebutton"> <label> <input type="checkbox" name="display"> <span class="toggle"></span> </label> </div> </form> </td> <?php echo "</tr>"; } } ?> </tbody> </table> https://i.imgur.com/Qyz6s8v.png In displayitem.php <?php if(isset($_POST['display'])){ echo '<p>'.$_POST['display'].'</p>'; // queries etc here } ?> I'm not getting the value here unless I add a submit button. Guessing jQuery / AJAX is the way to go but can't seem to find any good tutorials on it, are there any other suitable approaches to this?
Which languages do I need to make this happen? And I am unsure of how to incorporate PHP within a javascript query and what jQuery functions I will need. what Im basically trying to do is just like a phpmyadmin function... you select rows you want to update with a checkbox and then it takes you to a page where the rows that are clicked are shown in forms so that you can view and edit info in them... and then have 1 submit button to update them all at once. Hi guys, Im developing a stock system and so far new stock and can be added with the quantity, however im trying to update the stock by using a select box and selecting the type of stock and inputting a new qty. the form and everything is set up and i can select files from the database, however i dont know how to update files from a select box The code i got so far is 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>stock manager</title> </head> <body> <?php $stockqty =&$_POST['stock_qty1']; ?> <center> <table> <td> <table> <td> <form action='stockview.php' method='POST'> Please Enter a Stock Name and Stock Value <table> <tr> <td> Stock Name: </td> <td> <input name="stock_name" type="text" /><BR /> </td> </tr> <tr> <td> Stock Qty: </td> <td> <input name="stock_qty" type="text" /> </td> </tr> </table> <input name="submit" type="submit" value="Add New Stock Items" /> </form> </td> </table> </td> <td> <table> <td> <form action='stockmanager.php' method='POST' enctype="multipart/form-data"> Please Select from the list the item you wish to update <table> <tr> <td> Stock Name: </td> <td> <?php $connect = mysql_connect("localhost","root", "") or die ("Couldn't Connect!"); mysql_select_db("stock", $connect) or die("Couldn't find db"); // select database $query=("SELECT id, stockname FROM stocks"); $result = mysql_query ($query); echo "<select name=stock value=''>Edit Stock QTY</option>"; while($nt=mysql_fetch_array($result)) { //Array or records stored in $nt echo "<option value=$nt[id]>$nt[stockname]</option>"; /* Option values are added by looping through the array */ } $queryreg = mysql_query("SELECT * FROM stocks WHERE stockqty='$stockqty'"); $numrows = mysql_num_rows($queryreg); $update = mysql_query("UPDATE stocks SET stockqty='$stockqty' WHERE stockname = '$stockname'"); echo("Its updated"); ?> </td> </tr> <tr> <td> Stock Qty: </td> <td> <input name="stock_qty1" type="text" /> </td> </tr> </table> <input name="submit" type="submit" value="Update stock items" /> </form> </td> </table> </td> </table> </center> </body> </html> Any help would be greatly appreciated. Thanks Lance This has been bugging me for quite a while and I've tried so many different things and just run into all kinds of problems... What I'm doing or trying at least is pulling data from a table displaying it into a multiple select box allowing the user the oppertunity to remove one or more options. As the code stands now I'm getting no value at all in the post variable, by taking the [] brackets out of the inputs name i was able to get the first selected option but the php code was then unable to remove that value from the database. I hope I'm explaining this well enough but the code follows I'd really appreciate some help or direction on this one. The FORM Code: [Select] <FORM action='' method='post'> <select size='8' multiple name='remove_player[]'> <?php foreach ($members as $key => $mem) { if ($mem != "") { $mem = str_replace("-", " ", $mem); $mem = ucwords($mem); echo ("<option value='" . $mem . "'>" . $mem . "</option>"); } } ?> </select> and then the handler code: Code: [Select] $to_remove = $_POST['remove_player']; $as_team = str_replace(" ", "-", $teamname); $as_team = strtolower($as_team); $for_remove = "SELECT * FROM teams WHERE name = '$as_team'"; $for_query = (mysql_query($for_remove)); foreach ($to_remove as $y => $z) { $z = str_replace(" ", "-", $z); $z = strtolower($z); } while($arr_remove = mysql_fetch_array($for_query)) { foreach ($arr_remove as $a => $b) { foreach ($to_remove as $c => $d) { if ($b == $d) { unset($arr_remove[$a]); } } } foreach ($arr_remove as $e => $f) { $add_replace = (mysql_result($for_query, 0, 'members')); $replace = ($add_replace . "\r\n" . $f . "\r\n"); $replace_mem = "UPDATE teams SET members = '$replace'"; $replace_q = (mysql_query($replace_mem)); } } echo "Member List successfully updated.<br>"; foreach ($to_remove as $h => $g) { echo ($g . " removed from the team.<br>"); } Also any time i try to print any part of the array/s I get no values but the database is being updated with 2 line breaks and a "3" at the end of the table which has me a bit confused as well. Thanks! Code: [Select] $new_array2=array_diff($my_array,$itemIds); $updatedb = mysql_query("UPDATE content_type_ads SET field_expire_value = '666' WHERE $new_array2 = field_item_id_value"); "$new_array2" has only 12 digit numbers for each item in the array, and I want to match them to the "field_item_id_value" field in the table, updating the "field_expire_value" field for the record where they match. I know I am close because the UPDATE code works before I add the WHERE statement (it of course adds '666' to EVERY field, but for a noobie it's a start!). Hey guys, how do I send checkbox variables to my e-mail address once a user has checked it on the html form. Here is my html form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Form</title> <script type="text/javascript"> //email form validation function everif(str) { var at="@" var punct="." var lat=str.indexOf(at) var lstr=str.length var lpunct=str.indexOf(punct) if (str.indexOf(at)==-1){ alert("Valid email must be entered") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Valid email must be entered") return false } if (str.indexOf(punct)==-1 || str.indexOf(punct)==0 || str.indexOf(punct)==lstr){ alert("Valid email must be entered") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Valid email must be entered") return false } if (str.substring(lat-1,lat)==punct || str.substring(lat+1,lat+2)==punct){ alert("Valid email must be entered") return false } if (str.indexOf(punct,(lat+2))==-1){ alert("Valid email must be entered") return false } if (str.indexOf(" ")!=-1){ alert("Valid email must be entered") return false } return true } function evalid(){ var emailID=document.contact_form.mail if (everif(emailID.value)==false){ emailID.focus() return false } //empty field validation var naam=document.contact_form.naam if ((naam.value==null)||(naam.value=="")){ alert("Fields marqued with * must be entered") naam.focus() return false } var telefoon=document.contact_form.telefoon if ((telefoon.value==null)||(telefoon.value=="")){ alert("Fields marqued with * must be entered") telefoon.focus() return false } var branche=document.contact_form.branche if ((branche.value==null)||(branche.value=="")){ alert("Fields marqued with * must be entered") branche.focus() return false } return true } </script> </head> <body> <form name="contact_form" method="post" id="contactform" action="doeactie.php" onSubmit="return evalid()"> <table border="0"> <tr> <td><label for="bedrijfsnaam">Company name</label></td> <td colspan="2"><input name="bedrijfsnaam" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="naam">Name *</label></td> <td colspan="2"><input name="naam" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="mail">E-mail *</label></td> <td colspan="2"><input type="text" name="mail" class="text" size="30" /></td> </tr><tr> <td><label for="adres">Address</label></td> <td colspan="2"><input name="adres" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="plaatsnaam">City</label></td> <td colspan="2"><input name="plaatsnaam" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="postcode">Zip</label></td> <td colspan="2"><input type="text" name="postcode" class="text" size="10" /></td> </tr><tr> <td><label for="branche">Niche *</label></td> <td colspan="2"><input name="branche" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="telefoon">Phone *</label></td> <td colspan="2"><input name="telefoon" class="text" type="text" size="30" /></td> </tr><tr> <td><label for="bericht">Question or Comment</label></td> <td colspan="2"><textarea name="message" class="text" onkeyup="return limitarelungime(this, 255)" cols="35" rows="5"></textarea></td> </tr> </table> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td></td> <td height="25"></td> </tr> <tr> <td></td> <td height="30" valign="top"><font face="arial" size="2"><b>I would also like to receive information about :</b></font></td> </tr> <tr> <td><input type="checkbox" name="emailmarketing" id="emailmarketing" value="emailmarketing" /></td> <td height="25"><font face="arial" size="2">E-mail Campaign</font></td> </tr> <tr> <td><input type="checkbox" name="zoekmachopt" id="zoekmachopt" value="zoekmachopt" /></td> <td height="25"><font face="arial" size="2">SEO</font></td> </tr> <tr> <td><input type="checkbox" name="socialmedia" id="id" value="socialmedia" /></td> <td height="25"><font face="arial" size="2">Social Media</font></td> </tr> <tr> <td><input type="checkbox" name="videomarketing" id="videomarketing" value="videomarketing" /></td> <td height="25"><font face="arial" size="2">Video Marketing</font></td> </tr> <tr> <td><input type="checkbox" name="webshop" id="webshop" value="webshop" /></td> <td height="25"><font face="arial" size="2">Webshop</font></td> </tr> <tr> <td><input type="checkbox" name="cms" id="cms" value="cms" /></td> <td height="25"><font face="arial" size="2">Content Management System</font></td> </tr> <tr> <td><input type="checkbox" name="grafisch" id="grafisch" value="grafisch" /></td> <td height="25"><font face="arial" size="2">Graphic Design</font></td> </tr> <tr> <td></td> <td align="left"><br /><input type="submit" name="Submit" value="Send"></td> <td align="right"></td> </tr> </table> </form> </body> </html> and this is the PHP script that processes this. Everything works except for the checkbox part. <?php session_start(); if(isset($_POST['Submit'])) { $youremail = 'blabla@gmail.com'; $fromsubject = 'Request from form'; $bedrijfsnaam = $_POST['bedrijfsnaam']; $naam = $_POST['naam']; $mail = $_POST['mail']; $adres = $_POST['adres']; $plaatsnaam = $_POST['plaatsnaam']; $postcode = $_POST['postcode']; $branche = $_POST['branche']; $telefoon = $_POST['telefoon']; $message = $_POST['message']; $to = $youremail; $mailsubject = 'Bericht ontvangen van'.$fromsubject.' Actie Pagina'; $body = $fromsubject.' Bedrijfsnaam: '.$bedrijfsnaam.' Naam Contact Persoon: '.$naam.' E-mail: '.$mail.' Adres: '.$adres.' Plaatsnaam: '.$plaatsnaam.' Postcode: '.$postcode.' Branche: '.$branche.' Telefoonnummer: '.$telefoon.' vraag of Wens: '.$message.' |---------End Message----------|'; echo "thank you for your request we will contact you asap."; mail($to, $subject, $body); } else { echo "Error Please <a href='form.html'>try again</a>"; } ?> Any help would be great! Thanks guys I have a standard form that displays users current data from a mysql database once logged in(code obtained from the internet). Users can then edit their data then submit it to page called editform.php that does the update. All works well except that the page does not display the updated info. Users have to first logout and login again to see the updated info. even refreshing the page does not show the new info. Please tell me where the problem is as i am new to php.
my form page test.php
<?PHP require_once("./include/membersite_config.php"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } ?> <form action="editform.php?id_user=<?= $fgmembersite->UserId() ?>" method="POST"> <input type="hidden" name="id_user" value="<?= $fgmembersite->UserId() ?>"><br> Name:<br> <input type="text" name="name" size="40" value="<?= $fgmembersite->UserFullName() ?>"><br><br> Email:<br> <input type="text" name="email" size="40" value="<?= $fgmembersite->UserEmail() ?> "><br><br> Address:<br> <input type="text" name="address" size="40" value="<?= $fgmembersite->UserAddress() ?> "><br><br> <button>Submit</button>my editform.php <?php $con = mysqli_connect("localhost","root","user","pass"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"UPDATE fgusers3 SET name = '".$_POST['name']."', email= '".$_POST['email']."', address= '".$_POST['address']."' WHERE id_user='".$_POST['id_user']."'"); header("Location: test.php"); ?> I used to have a straight forward piece of code that updated multiple rows of info using a foreach loop. However, ever since I've introduced a textarea box into the mix, it's been throwing up syntax errors. Here's my textarea box: Code: [Select] <textarea id=\"detail[]\" name=\"detail[]\" rows=\"7\" cols=\"35\" wrap=\"hard\">$data[detail]</textarea> And here's my UPDATE query: Code: [Select] foreach($_POST['mid'] as $key=>$val) { mysql_query("UPDATE val_mworks SET mworks_percent = ".$_POST['percent'][$key].", mworks_detail = ".$_POST['detail'][$key].", mworks_qty = ".$_POST['qty'][$key]." WHERE mworks_id = $val ") or die(mysql_error()); } Can anyone see anything obvious that I'm doing wrong? Hi all, I wonder if anyone can give me some idea; I have a form with a drop down menu [BT,Virgin, None, Other] - When user select either [BT, Virgin,None] the textarea field will be disable. But when user select option [Other] the textarea will be available. How can I do this? .. .. <tr align="left" valign="top" <?php if ($_POST['action'] == "register") { if ($errornum[16] == "1") { echo 'class="error"'; } } ?>> <td>Who is your previous Internet Service Provider?</td> <td align="left"> <select name="oldprovider"> <option value="<?php echo $prev_supplier;?>" <?php if ($_POST['action'] == "register") { if ($_POST['oldprovider'] == "") { echo "selected"; } } ?>> Select Provider..... </option><?php $prev_supplier="BT";?> <option value="<?php echo $prev_supplier;?>" <?php if ($_POST['action'] == "register"){ if ($_POST['oldprovider'] == "$prev_supplier") { echo "selected"; } } ?>> <?php echo $prev_supplier;?> </option><?php $prev_supplier="Virgin";?> <option value="<?php echo $prev_supplier;?>" <?php if ($_POST['action'] == "register") { if ($_POST['oldprovider'] == "$prev_supplier") { echo "selected"; } } ?>><?php echo $prev_supplier;?> </option><?php $prev_supplier="None";?> <option value="<?php echo $prev_supplier;?>" <?php if ($_POST['action'] == "register") { if ($_POST['oldprovider'] == "$prev_supplier") { echo "selected"; } } ?>><?php echo $prev_supplier;?> </option><?php $prev_supplier="Other";?> <option value="<?php echo $prev_supplier;?>" <?php if ($_POST['action'] == "register") { if ($_POST['oldprovider'] == "$prev_supplier") { echo "selected"; } } ?>><?php echo $prev_supplier;?> </option> </select> <br /><br /> <textarea name="oldprovider_text" cols="30" rows="2"> <?php if ($_POST['action'] == "register") { echo $_POST['oldprovider_text']; } ?> </textarea></td> </tr> Thanks in advance. Hello, this is my first post here.
I am trying to output the rows of a certain query in sequence after a POST has been requested.
I have been successful in getting the output in a pure php file but when I try to implement this in a web page with html/css, I can't echo the array in arbitrary locations after the post has processed.
This is the code which outputs successfully in a pure php file, but I need it to work in a <textarea> field as the results of a search
$rows2 = array(); $rows3 = array(); while($stmt->fetch()){ $rows2[] = $stratoparse; $rows3[] = $date; } $search = array(); for($i=0;$i<=$num_rows;$i++){ echo $rows3[$i].' '.$rows2[$i].'<br>'.'<br>'; } }To further iterate what I am asking. When errors are stored, you write something like $errors['username']="A username is required.";Then in any location of a webpage I can call this or show it, provided by this <?php isset($errors['username']) ? $errors['username']:" ");?>That is the same thing I am trying to do with this array which can be an arbitrary count of rows... I have not been successful in getting this to work... I have been told of string concatenation... I don't know what to do Thank you for any help hello all, i have a quick question. i have a select all from toolout with toolid = $tid. the problem is, if there isnt an entry yet in toolout, it is giving me the info from the row above. is there any way that i can do a (if it doesnt exist, set $status to 1, rather than using the previous rows code) my code is below. Code: [Select] if(isset($_POST['search'])) { $tool=$_POST['tool']; echo "<table border='1' style='border-collapse: collapse' bordercolorlight='#000000' bordercolordark='#000000' width='98%' align='center'>"; echo "<tr><td width='100%' colspan='5' align='center'><b>Tool List - $tool</b></td></tr>"; echo "<tr> <th align='center'>Tool</th> <th>Location</th> <th>Status</th> </tr>"; $result = mysql_query("SELECT * FROM tools WHERE toolgroup LIKE '%$tool%' ORDER BY tool"); while($row = mysql_fetch_array($result)) { $id=$row['id']; $tool=$row['tool']; $barcode=$row['barcode']; $location=$row['location']; $result2 = mysql_query("SELECT * FROM toolout WHERE toolid = '$id' ORDER BY id ASC"); while($row2 = mysql_fetch_array($result2)) { $status=$row2['status']; $who=$row2['who']; $datechanged=$row2['datechanged']; $datechanged1 = date( 'M j, Y', strtotime($datechanged) ); if("$status" == "1") { $statusout="<font color='#0000FF' size='4'>IN</font><br /><a href='toolout.php?tool=" . $id . "' target='action'>SIGN OUT</a>"; } if("$status" == "2") { $statusout="<font color='#FF0000' size='4'>OUT</font><br />$who - $datechanged1"; } if("$status" == "3") { $statusout="<font color='#00FF00' size='4'>PENDING OUT</font><br />$who - $datechanged1"; } if("$status" == "4") { $statusout="<font color='#00FF00' size='4'>PENDING IN</font><br />$who - $datechanged1"; } } echo "<tr>"; echo "<td align='center'>" . $tool . "</td>"; echo "<td align='center'>" . $location . "</td>"; echo "<td align='center'>"; if (isset($status)) { echo "$statusout"; } else { echo "<font color='#0000FF' size='4'>IN</font><br /><a href='toolout.php?tool=" . $id . "' target='action'>SIGN OUT</a>"; } echo "</td>"; echo "</tr>"; } echo "</table>"; } Thank you so much. Hi - how's it going? I've been working on something with no luck and I'm wondering if you have any ideas. I have two tables; Members and Events. When a member logs in they are redirected to a page where I want them to be able to see a list of events that they have created based on a user ID that is common in both tables. So if the member has a memberID of 123 I want them to see any events that have the userID of 123. I used two different column names just for clarity. I've tried a number of variations on the following code: <?php session_start(); header("Cache-control: private"); // Connect to Database include ('includes/db.php'); //Has login info // If not logged in if (!$_SESSION['pkMemberID']) { echo ("<div class='box'><h2>Sorry, you are not logged in!</h2>"); exit(); } // Convert Session variable 'pkMemberID' to simple variable. $memberID = $_SESSION['memberID']; $pkMemberID = $_SESSION['pkMemberID']; $name = $_SESSION['name']; //Query Events $sql = "SELECT * FROM events WHERE userID = $memberID"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); echo ("<div>Events:<br />"); // Event exists if (!($num_rows == 0)) { $myrow = mysql_fetch_array($result); do { printf ('<span>– <a href="event_edit.php?pkEventID=%s">%s</a></span><br />', $myrow['pkEventID'], $myrow['eventName']); } while ($myrow = mysql_fetch_array($result)); } echo ("</div>"); //End Events //end page ?> Sometimes I get errors, sometimes just nothing. Any advice would be appreciated. hi im trying to display the form entities in the textarea field so they can be sent to the user in an email, but its not working properly it prints out the variable $idName instead of its value?? any help would be greatly appricated ive been stuck on this bit of ages <?php function display_output_page() { $idName = trim($_REQUEST['username']); $firstName = trim($_REQUEST['firstname']); $Surname = trim($_REQUEST['surname']); $Address = trim($_REQUEST['address']); $Email = trim($_REQUEST['email']); $Phone = trim($_REQUEST['phone']); $Fitness = isset($_REQUEST['fitness']) ? $_REQUEST['fitness'] : ''; $goGym = isset($_REQUEST['gogym']) ? $_REQUEST['gogym'] : ''; $whyGym = isset($_REQUEST['whyGym']) ? $_REQUEST['whyGym']: array(); ?> <html> <head><title>Form Results</title></head> <body> <h1>Form Results</h1> <form action='mailto:$Email?subject=user comments' method='post'enctype='text/plain'> <textarea name='Topic' rows=15 cols=90> idName: ". $idName\n; Firstname: ". $_POST["firstname"]\n; Surname: ". $_POST["surname"]\n; Address: ". $_POST["address"]\n; Email: ". $_POST["email"]\n; Phone no.: ". $_POST["phone"]\n; Your fitness level: ". $_POST["fitness"]\n; How often do you go to the gym: ". $_POST["goGym"]\n; Why do you go to the Gym: ". $_POST["whyGym"]; </textarea></br> <input type='submit' value='Send Thru Email'> </form> </body> </html> <?php } ?> Hi, All: I'm trying to figure out what way it's the best way to pull info belonging to a specific user based on whether he's a logged-in "member", and want to make sure he's not able to access any other member's details... would the best way be to try to match the user's "username" stored in a $_SESSION when fetching his info, something like this: Code: [Select] <?php // Assume the login combo is this: $username = $_POST['username']; $password = $_POST['password']; // Assume he has already logged in: $_SESSION['username'] = $username; //EXAMPLE 1: SELECTING user info simply from actual DB username/password match: if ($_SESSION['username']) { $userRecords = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"); $userInfo = mysql_fetch_array($userRecords); echo $userInfo['id'] . $userInfo['username'] . $userInfo['first-name'] . $userInfo['last-name'] . $userInfo['date-register']; } // EXAMPLE 2: or SELECTING user info based on $_SESSION['username'] value: if ($_SESSION['username']) { $userRecords = mysql_query("SELECT * FROM users WHERE username = . $_SESSION['username'] . AND password = '$password'"); $userInfo = mysql_fetch_array($userRecords); echo $userInfo['id'] . $userInfo['username'] . $userInfo['first-name'] . $userInfo['last-name'] . $userInfo['date-register']; } ?> So, my question is, are this actually working differently? is one better than the other as far as security, preventing other users from hacking either on purpose or accidenally into other user's details? thank! Appreciate any feedback... Hi, PHP newbie here, and my first post. I am in the process of learning PHP. Currently I am looking at forms and DB input. I would like to verify if my current method of keeping the linebreaks from a TEXTAREA field, and still keep the DB input safe is correct. I use the following code to get the input from the TEXTAREA field. Code: [Select] $comments = mysql_real_escape_string(nl2br(filter_var($_POST["comments"], FILTER_SANITIZE_STRING)));Is this the correct way of handling this? Thanks Hi there. I have a page that lists the records of a table. On this page I want to be able to edit/update two attributes of these records by a checkbox - e.g., being able to update multiple records at once. I thought the smartest way to achieve this would be by using arrays. I've implemented one checkbox array and have two fields. Currently when I change both fields and hit submit, the height value changes and the name value is changed to the last record displayed in the table. E.g. Height - 170 -> 160 -> UPDATED TO 160 Name - Test1 -> Test2 -> UPDATED TO VICTORY (last record listed in table; displayed alphabetically) My code is as follows: <?php include("connection.php"); $conn = oci_connect($UName,$PWord,$DB) or die("Database Error - Contact Admin - sjrei5@student.monash.edu"); if (empty($_POST["check"])) { $query = "SELECT * FROM HORSE ORDER BY HORSE_NAME"; $stmt = oci_parse($conn,$query); oci_execute($stmt); $Horses = oci_fetch_array ($stmt); ?> <form method="post" action="horse_multi.php"> <table border="1" id="customers"> <tr> <th>ID</th> <th>EDIT</th> <th>NAME</th> <th>HEIGHT</th> </tr> <?php while ($Horses = oci_fetch_array ($stmt)) { ?> <tr> <td><?php echo $Horses["HORSE_ID"]; ?></td> <td align="center"><input type="checkbox" name="check[]" value="<?php echo $Horses["HORSE_ID"]; ?>"></td> <td align="center"><input type="text" size="5" name="<?php echo $Horses["HORSE_ID"]; ?>" value="<?php echo $Horses["HORSE_HEIGHT"]; ?>"></td> <td align="center"><input type="text" size="20" name="HORSE_NAME" value="<?php echo $Horses['HORSE_NAME']; ?>"></td> </tr> <?php } ?> </table><p /> <h4><input type="submit" value="Update Selected Horses"></h4> </form> <?php oci_free_statement($stmt); } else { foreach($_POST["check"] as $horse_id) { $query = "UPDATE HORSE SET HORSE_NAME= '$_POST[HORSE_NAME]', HORSE_HEIGHT = ".$_POST[$horse_id]." WHERE HORSE_ID ='".$horse_id."'"; $stmt = oci_parse($conn,$query); oci_execute($stmt); } } ?> </body> </html> Any ideas? I am working on a project where I want a select form to display information from a MySQL table. The select values will be different sports (basketball,baseball,hockey,football) and the display will be various players from those sports. I have set up so far two tables in MySQL. One is called 'sports' and contains two columns. Once called 'category_id' and that is the primary key and auto increments. The other column is 'sports' and contains the various sports I mentioned. For my select menu I created the following code. <?php #connect to MySQL $conn = @mysql_connect( "localhost","uname","pw") or die( "You did not successfully connect to the DB!" ); #select the specified database $rs = @mysql_SELECT_DB ("test", $conn ) or die ( "Error connecting to the database test!"); ?> <html> <head>Display MySQL</head> <body> <form name="form2" id="form2"action="" > <select name="categoryID"> <?php $sql = "SELECT category_id, sport FROM sports ". "ORDER BY sport"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['category_id']."\">".$row['sport']."</option>\n "; } ?> </select> </form> </body> </html> this works great. I also created another table called 'players' which contains the fields 'player_id' which is the primary key and auto increments, category_id' which is the foreign key for the sports table, sport, first_name, last_name. The code I am using the query and display the desired result is as follows <html> <head> <title>Get MySQL Data</title> </head> <body> <?php #connect to MySQL $conn = @mysql_connect( "localhost","uname","pw") or die( "Err:Db" ); #select the specified database $rs = @mysql_SELECT_DB ("test", $conn ) or die ( "Err:Db"); #create the query $sql ="SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.sport = 'Basketball'"; #execute the query $rs = mysql_query($sql,$conn); #write the data while( $row = mysql_fetch_array( $rs) ) { echo ("<table border='1'><tr><td>"); echo ("Caetegory ID: " . $row["category_id"] ); echo ("</td>"); echo ("<td>"); echo ( "Sport: " .$row["sport"]); echo ("</td>"); echo ("<td>"); echo ( "first_name: " .$row["first_name"]); echo ("</td>"); echo ("<td>"); echo ( "last_name: " .$row["last_name"]); echo ("</td>"); echo ("</tr></table>"); } ?> </body> </html> this also works fine. All I need to do is tie the two together so that when a particular sport is selected, the query will display below in a table. I know I need to change my WHERE clause to a variable. This is what I need help with. thanks |