PHP - Moved: Simple Form To Update Two Sql Items?
This topic has been moved to PHP Freelancing.
http://www.phpfreaks.com/forums/index.php?topic=347660.0 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 Hi, i have had some help from these forums building a shopping cart system and i can add items to cart, empty cart but i need some help on how to update quantities. Here is the code i use to add items Code: [Select] $pid = $_POST['prodid']; $q = $_POST['qty']; if(array_key_exists($pid, $_SESSION['cart'])) { $_SESSION['cart'][$pid]=$_SESSION['cart'][$pid]+$q; } ELSE { $_SESSION['cart'][$pid]=$q; } Im displaying my items in a table with a text field for quantities which can be changed then click update. i see there is 2 things i need to do, first is to somehow create a loop for all the items in my table, i have no clue where to start on that, and then in that loop i have my update command. im assuming the code to update would be something like Code: [Select] $_SESSION['cart'][$pid]=$_SESSION['cart'][$pid][$qty] where $qty is the value of the text box in my table. Any help would be appreciated. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355809.0 Hi all I am having troubles integrating a shopping cart. $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } Allows me to Delete and Update but not Add an item. [php]$action = (isset($_POST['action']) && $_POST['action'] != '') ? $_POST['action'] : 'view'; Allows me to ADD an item to the cart(add action passed from previous page via form) but not Delete or UPDATE Im not sure if I should have attached the pages or just pasted them but heres the code cart.php <?php require_once 'config.php'; require_once 'cart-functions2.php'; require_once 'functions.php'; require_once 'database.php'; $ID = $_POST["ID"]; $pSize = $_POST["size"]; $pcolour = $_POST["colour"]; ?> <?php $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } $ID = $_POST["ID"]; $cartContent = getCartContent(); $numItem = count($cartContent); $pageTitle = 'Shopping Cart'; // show the error message ( if we have any ) displayError(); if ($numItem > 0 ) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] . "?action=update"; ?>" method="post" name="frmCart" id="frmCart"> <table width="780" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr class="entryTableHeader"> <td colspan="2" align="center">Item</td> <td align="center">Unit Price</td> <td width="75" align="center">Quantity</td> <td align="center">Total</td> <td width="75" align="center"> </td> </tr> <?php $subTotal = 0; for ($i = 0; $i < $numItem; $i++) { extract($cartContent[$i]); $productUrl = "index.php"; $subTotal += $price * $ct_qty; ?> <tr class="content"> <td width="80" align="center"></td> <td><?php echo $pDesc; ?></td> <td align="right"><?php echo displayAmount($price); ?></td> <td width="75"><input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);"> <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>"> <input name="hidProductId[]" type="hidden" value="<?php echo $ID; ?>"> </td> <td align="right"><?php echo displayAmount($price * $ct_qty); ?></td> <td width="75" align="center"> <input name="btnDelete" type="button" id="btnDelete" value="Delete" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>';" class="box"> </td> </tr> <?php } ?> cart-functions <?php require_once 'config.php'; /********************************************************* * SHOPPING CART FUNCTIONS *********************************************************/ function addToCart() { $sid = session_id(); $ID = $_GET["ID"]; $pSize = $_GET["size"]; $pcolour = $_GET["colour"]; // current session id // check if the product is already // in cart table for this session $sql = "SELECT ID FROM cart WHERE ID = '$ID' AND ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { // put the product in cart table $sql = "INSERT INTO cart (ID, ct_qty, ct_session_id, ct_date) VALUES ('$ID', 1, '$sid', NOW())"; $result = dbQuery($sql); } else { // update product quantity in cart table $sql = "UPDATE cart SET ct_qty = ct_qty + 1 WHERE ct_session_id = '$sid' AND ID = '$ID'"; $result = dbQuery($sql); } header('Location: cart2.php'); } /* Get all item in current session from shopping cart table */ function getCartContent() { $cartContent = array(); $sid = session_id(); $sql = "SELECT ct.ct_id, ct.ID, ct.ct_size, ct.ct_colour, ct.ct_qty, pd.pDesc, pd.price, pd.ID FROM cart ct, products pd WHERE ct_session_id = '$sid' AND ct.ID = pd.ID"; $result = dbQuery($sql); while ($row = dbFetchAssoc($result)) { $cartContent[] = $row; } return $cartContent; } /* Remove an item from the cart */ function deleteFromCart($cartId = 0) { if (!$cartId && isset($_GET['cid']) && (int)$_GET['cid'] > 0) { $cartId = (int)$_GET['cid']; } if ($cartId) { $sql = "DELETE FROM cart WHERE ct_id = $cartId"; $result = dbQuery($sql); } header('Location: cart2.php'); } /* Update item quantity in shopping cart */ function updateCart() { $cartId = $_POST['hidCartId']; $productId = $_POST['hidProductId']; $itemQty = $_POST['txtQty']; $numItem = count($itemQty); $numDeleted = 0; $notice = ''; for ($i = 0; $i < $numItem; $i++) { $newQty = (int)$itemQty[$i]; if ($newQty < 1) { // remove this item from shopping cart deleteFromCart($cartId[$i]); $numDeleted += 1; } // update product quantity $sql = "UPDATE cart SET ct_qty = $newQty WHERE ct_id = {$cartId[$i]}"; dbQuery($sql); } exit; } function isCartEmpty() { $isEmpty = false; $sid = session_id(); $sql = "SELECT ct_id FROM cart ct WHERE ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { $isEmpty = true; } return $isEmpty; } /* Delete all cart entries older than one day */ function deleteAbandonedCart() { $yesterday = date('Y-m-d H:i:s', mktime(0,0,0, date('m'), date('d') - 1, date('Y'))); $sql = "DELETE FROM cart WHERE ct_date < '$yesterday'"; dbQuery($sql); } ?> Thanks in advance I have a simple form to add details to the database. I want to use the same form layout to call back details for editting and updating. The main page is showroomedit.php which lists (in an array) the records in the database. I have added an edit.php but cant seem to work the code out. Can some one point me in the right direction. here is edit.php: <?PHP include('dbconnect.php') ?> <HTML> <HEAD> <TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE> </HEAD> <BODY LINK="#000000" ALINK="#000000" VLINK="#000000"> <CENTER><IMG SRC="logo.jpg"></CENTER> <CENTER> <TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0"> <TR> <TD WIDTH="186" valign="top"> <BR> <CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER> <CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER> <CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER> <CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER> <CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER> </TD> <TD WIDTH="30" valign="top"> </TD> <TD valign="top"> <FONT SIZE="2" FACE="ARIAL"> <CENTER><A HREF="addcar.html"><IMG SRC="vehicleadd.jpg" border="0"></A><A HREF="showroomconfig.php"><IMG SRC="vehicleedit.jpg" border="0"></A><A HREF="showroomconfig.php"><IMG SRC="vehicledelete.jpg" border="0"></A></CENTER> <CENTER><B>Update a Vehicle</B></CENTER> <BR> <?php $query1="SELECT cars FROM CarName='$carname', CarTitle='$CarTitle', CarPrice='$carprice', CarMiles='$carmiles', CarDescription='$cardesc'"; mysql_query($query1); mysql_close(); ?> <form action="editvehicle.php" method="post"> <CENTER>Vehicle Name:</CENTER> <CENTER><input type="text" name="CarName" value="<?php echo $carname; ?>"></CENTER> <br> <CENTER>Vehicle Type:</CENTER> <CENTER><input type="text" name="CarTitle" value="<?php echo $cartitle; ?>"></CENTER> <br> <CENTER>Vehicle Price:</CENTER> <CENTER><input type="text" name="CarPrice" value="<?php echo $carprice; ?>"></CENTER> <br> <CENTER>Vehicle Mileage:</CENTER> <CENTER><input type="text" name="CarMiles" value="<?php echo $carprice; ?>"></CENTER> <br> <CENTER>Vehicle Description:</CENTER> <CENTER><textarea name="CarDescription" rows="10" cols="30" value="<?php echo $cardesc; ?>"></textarea></CENTER> <br> <CENTER><input type="Submit"></CENTER> </form> </TD> </TR> </TABLE> <BR><BR><BR><BR> <CENTER><FONT FACE="VERDANA" SIZE="1"> This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010 </CENTER> <BR> <CENTER><A HREF="admin.php">Employee Area</A> </BODY> </HTML> That is not even showing me the table details at all. Im lost . There is an "Update" link in each array in showroom.php in which when the user clicks it opens edit.php . They update the form as they wish... then click update and it updates the database and sends them back to showroomedit.php Much help would be appreciated ! Cheers paul if your out there still This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=346609.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=334480.0 Good morning. I am looking fo some help with an update script to update all rows in a table. This is what I have for a form and all looks well. form.php <?php // run the query and put the results in an array variable called $result $result = mysql_query("SELECT * FROM table ORDER BY 'id', 'title', 'text', 'number'"); print "<form method='post' action='update.php'> <table width='100%' border='0' cellspacing='1' cellpadding='1'><tr> <td align='center'><strong>ID</strong></td> <td align='center'><strong>Title</strong></td> <td align='center'><strong>text</strong></td> <td align='center'><strong>Number</strong></td> </tr>\n"; // start a loop to print all of the courses with their book information // the mysql_fetch_array function puts each record into an array. each time it is called, it moves the array counter up until there are no more records left while ($Update = mysql_fetch_array($result)) { // start displaying the info; the most important part is to make the name an array (notice bookinfo[$i]) print "<td align='center'><p>{$Update['id']}</p></td>\n"; print "<td align='center'><input type='text' name='title' value='{$Update['title']}' /></td>"; print "<td align='center'><input type='text' size='40' name='text' value='{$Update['text']}' /></td>\n"; print "<td align='center'><input type='text' size='40' name='number' value='{$Update['number']}' /></td>\n"; print "</tr>\n"; // add 1 to the count, close the loop, close the form, and the mysql connection } print "<tr> <td colspan='4' align='center'><input type='submit' value='submit' />"; print "</td> </tr> </table> </td> </tr> </form> </table>"; print "</tr>\n"; ?><br /><br /> My question is. How do I update this info into the database with the proper info. ie. Update.php? Hello I am trying to do a simple button that will change a single field in database depending on its already existing value eg: if value is 0 then button should read 0 and on click change value in field to 1, and then button should read 1. Basically an "ON/OFF" button. Any examples to do this in a simple way? First time poster, and very amateur php coder. I am trying to delete items that in a list using ajax. I can't figure out what I am doing wrong. Any help would be greatly appreciated!  Here is a snippet of my javascript... $('.delete-item').click(function() { var itemID = $(this).data('itemID'); var clear = 1; $.ajax({ url: 'includes/delete-item.php', method: 'POST', data: { itemid:itemID, clear:1 }, success: function(data) { $('.content').load('includes/lists.php') } }) })  and here is the relevant php... $item = $_POST['itemid']; $clear = $_POST['clear']; $clearSQL = "DELETE FROM `List_Items` WHERE `item_ID` = $item"; $cleared = mysqli_query($connect, $clearSQL); Hi guys, I have an update page where users can update their information, i have a different update page which works fine with almost the same code, but this one wont update anything. it does show the data but it wont update it, can u help please? <?php session_start(); include ("../../global.php"); //welcome messaage $username=$_SESSION['username']; echo "$username"; $query=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row = mysql_fetch_assoc($query)) { $user_id = $row['id']; } $ref=$_GET['reference']; if (isset($_POST['register']) && $_POST['register']){ $title = addslashes(strip_tags($_POST['title'])); $update=mysql_query("UPDATE msg SET title ='$title' WHERE reference='$ref'"); } ?> <html> <head> </head> <body> <form action='edit-msgs.php' method='POST' enctype='multipart/form-data'> Title:<br /> <input type='text' name='title' id='title' value='<?php $getdata = "SELECT title FROM msg WHERE reference='$ref' AND referal_id='$user_id'"; $result = mysql_query($getdata); $row = mysql_fetch_assoc($result); echo $row['title'];?>'><p /> <input type='submit' name='register' value='Update'> </form> </body> </html> I am trying to do something that a hell of a lot of people must need to do every day, yet despite this I can not find a single example online, or in books, which makes absolutely no sense! Anyway, hopefully it will be blindingly obvious to someone what I'm doing wrong, I really hope so as I can't figure it out... I have a mysl table as follows: tblvenue venue_id PRIMARY KEY (int) venue_name (varchar 50) station_id (int) I have a php/html page as follows: <html> <head> <title>Update & Delete Venues</title> </head> <body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin:0;padding:0" bgcolor="#B0E0E6"> <h1></h1> <form action="venue4.php" method="post"> <table border="1" style="border:solid black" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="center" width="33%">Action</td> <td align="center" width="33%">Venue Name</td> <td align="center" width="33%">Station Name</td> </tr> <?php $station_name=$_POST['station_name']; @ $db = new mysqli('XXX', 'XXX', 'XXX', 'XXX'); $query = "call sp_venue()"; $result = $db->query($query); $num_results = $result->num_rows; function db_result_to_array($result){ //--------------------------------------------------------------------- $res_array = array(); for ($count=0; $row = $result->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array; } //--------------------------------------------------------------------- function get_dataset($server, $user, $password, $database, $query7) { //--------------------------------------------------------------------- $db1 = new mysqli($server, $user, $password, $database); $query1 = $query7; $result1 = $db1->query($query1); $num_results = $result1->num_rows; $result8 = db_result_to_array($result1); return $result8;} //--------------------------------------------------------------------- echo "<tr>"; echo "<td>"; echo "<table width='100%'><td width='33%' align='center'><input type='submit' id='btnupdate' name='btnupdate' value='Update & Delete' ></td>"; echo "<td width='33%' align='center'><input type='submit' name='btncancel'id='btncancel' value='Cancel Updates' ></td>"; echo "<td width='33%' align='center'><input type='submit' value='Add New Venue' name='btnadd'></td></table>"; echo "</td>"; echo "<td><input type='text' name='tbvenue_name'/></td>"; echo "<td>"; ?> <select name="stat_id"> <?php $stat_array=get_dataset('XXX', 'XXX', 'XXX', 'XXX',"call sp_station"); foreach ($stat_array as $thisstat){ echo "<option value=\"".$thisstat['station_id']."\""; echo ">".$thisstat['station_name']."</option>"; } ?> </select> <?php echo "</td>"; echo "</tr>"; echo "<tr>"; while($row = $result->fetch_assoc()) { echo "<td width='33%'>Delete:<input type='Checkbox' id='cbdelete[]' name='cbdelete[]' value='".$row['venue_id']; echo "'>Update:<input type='Checkbox' id='value' name='cbupdate[]' value='".$row['venue_id']."'><input type='hidden' name='venue_id[]' value='".$row['venue_id']."'></td>"; echo "<td width='33%'><input type='Textbox' width='100%' name='venue_names' value='" .$row['venue_name']. "'></td>"; echo "<td width='33%'>" ; echo "<select name='station_id[]' width='100%'>"; $stat_array=get_dataset('localhost', 'root', 'snooker1', 'pool',"call sp_station"); foreach ($stat_array as $thiscat) { echo '<option value="' . $thiscat['station_id'] . '"'; if ($row['station_id'] == $thiscat['station_id']) {echo ' selected';} echo '>' . $thiscat['station_name'] . '</option>'; } echo "</td>"; echo "</tr>"; } echo "</table>"; ?> </form> </body> </html> This displays correctly and when checking the appropriate checkbox and clicking the script venue4.php is run: <?php //Connects to the database $db = new mysqli('XXX', 'XXX', 'XXX', 'XXX'); //Checks to see if the update button has been clicked if (isset($_POST['btnupdate'])) { //Assigns checkbox array to variable $aDel = $_POST['cbdelete']; $aVal = $_POST['cbupdate']; //Loops through rows to delete selected records foreach($_POST['cbdelete'] as $delete11) { //Deletes record $query = "delete from tblvenue where venue_id =".$delete11; $result = $db->query($query); $num_results = $result->num_rows; } //Loops through rows to delete selected records foreach($_POST['cbupdate'] as $update11) { //Gets variable //$Venue = $_POST['venue_names']; //Updates record $query = "update tblvenue set venue_name=".$venue." where venue_id =".$update11; $result = $db->query($query); $num_results = $result->num_rows; } //Checks to see if Add button was clicked } elseif (isset($_POST['btnadd'])) { //Looks for Venue Name & Station Name $tbvenue_name=$_POST['tbvenue_name']; $tbstat_id=$_POST['stat_id']; //Formats variables if(!get_magic_quotes_gpc()) { $tbvenue_name = addslashes($tbvenue_name); $tbstat_id = addslashes($tbstat_id); } //Inserts new record $query = "call sp_insert_venue('".$tbvenue_name."',".$tbstat_id.")"; $result = $db->query($query); } elseif (isset($_POST['btnedit'])) { switch($page) { default: include("venue2.php"); break; } } else { //If cancel button is clicked, goes straight to switch code below } //Closes database connection $db->close(); //Goes back to Venue page switch($page) { default: include("venue.php"); break; } echo var_dump($aval); print_r($aVal); //$test = $_POST['cbupdate']; ?> Deleting records works fine. Inserting records works fine. If I hard code the data (ie. set venue_name = 'blah blah blah') for updates, I can get the relevant row id from cbupdate and update the row in question. However I can not get the data from venue2.php (typed into a textbox on the row in question) and submit this to the database to be updated. This scenario must come up for zillions of developers, but so far no-one has been able to help. Please can anyone assist... I cant figure out why im having this problem. i stuck this at the top of my page on its own and it wont update the row to read Code: [Select] <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> I echo $_GET['pm_id']; and that turn out correct and the number matches the pm_id on the row. everything is lowercase I typed read manually into the column and echo that and it showed read also I have this same exact line of code on another script that works fine. does someone see something im over looking? this is driving me crazy http://localhost/stargate/users/view.php?pm_id=1376672&inbox=2 Code: [Select] <?php require("menu.php"); ?> <html> <body> <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> </body> </html> Hello: I want to create a feedback form that will allow a user to select from 30 or so items on a page, and send the data to an email address. I think it's something like a shopping cart but without a need to process a payment. I want to list items (like a soccer ball, a basket ball, etc.) and allow the user to select the size of the ball, the color, the number of balls, etc. I want the user to be able to select 1 item or many items. Once they are done, they would hit submit, and the data would get sent to an email address. Do I need to use a session to do this? I was trying to work with this code: Code: [Select] <?php session_start(); session_register('product'); session_register('amount'); $_SESSION['product'] = $_POST['product']; $_SESSION['amount'] = $_POST['amount']; //SEND THE EMAIL CODE HERE ???? ?> <form method="post" action=""> <input type="text" size="10" name="product"><br /> <input type="text" size="10" name="amount"><br /> <input type="submit" value="Finish"> </form> But I'm pretty sure I'm not in the ballpark on how to do this. Anyone have any ideas? Thanks in advance. I am a new guy here and don,t have much knowledge of PHP. My problem is complex but let me explain it in simple lines. I have two different codes , 1) This code takes form entries 'website','caption' and 'name' and stores it into the Table named as 'user_info' into mysql database. This page is saved as index.php 2) This code can add add new category as a root or a child of existing category with update(edit & delete) option.This page is saved as categories.php Both codes are working(except upload function),but what i want to do is to combine the both forms (Items and category) into one page so that a user can add : webite :Its any URL caption: Description of website name: name of the person Add category:choosing existing category Add new category:If not exist add new category Tell me how can i combine both codes so that my item entries display under their categories???? 1) code for items -stores in Table 'user_info' <html> <head> <style type="text/css"> body { margin-left: 10.5%; margin-right: 10%; margin-top: 1%;} </style> <style type="text/css"> .italic { font-style:italic; color: #336666; font-family: Calibri; padding:20px; } .bold { font-weight:bold; } </style> <title>submit Bookmarks</title> </head> <body background="wrapper.png"> <form action="index.php" method="post"> <font face="Calibri">Add Your Links Here: </font> <input name="website" maxlength="100" size="58" value="http://www."> <p><font face="Calibri">Description: </font> <input name="caption" maxlength="100" size="58"> </p> <p><font face="Calibri">Your Name: </font> <input name="name" maxlength="100" size="28"> <input type="submit" name="Submit" value="Submit"> <font size="4"> </font></p> <p><font size="4"> OR </font><font color="#008080" size="2"><b><a href="soon.html"> <span style="text-decoration: none"><font color="#008080" face="Calibri">Upload</font></span></a></b></font>|<i><font size="2" face="Calibri">upload your Bookmarks from your computer. e.g., , .Csv,.txt or .mdb files.</font></i></p> <form action='upload.php' method='post'> <input type="hidden" name="sel_file" /> <font face="Calibri">Choose a file: </font> <input name="uploaded_file" type="file" /> <input type="submit" value="Upload" /> </form> </p> </form> </body></html> <?php $hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost $db_user = "username"; // change to your database password $db_password = "Password"; // change to your database password $database = "database-name"; // provide your database name $db_table = "user_info"; // # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); ?> <html> <head> <title>Add Your Bookmarks Here</title> </head> <body> <?php if (isset($_REQUEST['Submit'])) { # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(name,website,caption) values ('".mysql_real_escape_string(stripslashes($_REQUEST['name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['website']))."','".mysql_real_escape_string(stripslashes($_REQUEST['caption']))."')"; $query_auto = "INSERT INTO user_info (entry_date, col_date) VALUE ('DATE: Auto CURDATE()', CURDATE() )"; if($result = mysql_query($sql ,$db)) { echo 'Thank you, your information has been entered into our database<br><br>'; } else { echo "ERROR: ".mysql_error(); } } else { ?> <?php } ?> <?php if(isset($_POST['SUBMIT'])) { $fname = $_FILES['sel_file']['name']; $chk_ext = explode(".",$fname); if(strtolower($chk_ext[1]) == "csv") { $filename = $_FILES['sel_file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into user_info(name,website,caption) values('$data[0]','$data[1]','$data[2]')"; mysql_query($sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } ?> <?php $result = mysql_query("select * from user_info ORDER BY CUR_TIMESTAMP desc"); // Database Query result ?> <?php while ($row = mysql_fetch_array ($result)) { $i++; if ($i & 1) { echo " <div class='color1'> <br/> <span class='bold'>Website:</span> <span class='normalfont' ><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span> <br/> <span class='bold'>Description:</span> <span class='normalfont'>" . $row['caption'] . " </span><span class='italic'>Added by: " . $row['name'] . "</span> <br/> </div>"; } else { echo " <div class='color2'> <br/> <br/> <span class='bold'>Website:</span> <span class='normalfont'><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span> <br/> <span class='bold'>Description:</span> <span class='normalfont'>" . $row['caption'] . "</span><span class='italic'>Added by: " . $row['name'] . "</span> <br/> <br/> </div>"; } } ?> </body> 2) Code for Adding Categories <?php error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Categories Class</title> <style> .code_div{ border:dashed #006600 1px; background:#E8FFEB; font-family:Georgia, "Times New Roman", Times, serif; font-size:11px; width:90%; padding:5px; } </style> </head> <body style="font-family:Tahoma"> <p> <?php // connect to database $hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost $db_user = "username"; // change to your database password $db_password = "password"; // change to your database password $database = "batabase-name"; // provide your database name $db_table = "categories"; // leave this as is # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); require_once("categories.class.php"); // Simple Usage if(!isset($_GET["id"])) $_GET["id"] =0; $ctg_id = $_GET["id"]; $categories = new categories; $categories->name_prefix = " "; ?> </p> <p>Here is it a Html Menu:</p> <br> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories </font><font color="#007700">= new </font><font color="#0000bb">categories</font><font color="#007700">; </font></font><br><font color="#000000"><font color="#ff8000"> </font><font color="#0000bb">$output </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">html_output</font><font color="#007700">(</font><font color="#0000bb">$ctg_id</font><font color="#007700">); <br> echo </font><font color="#0000bb">$output</font><font color="#007700">;</font></font></code> </div> <p> <? // lets display the categories $output = $categories->html_output($ctg_id); echo $output; ?> </p> <hr> <p>now I'll modify the $HtmlTree value a bit.</p> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">HtmlTree </font><font color="#007700">= array( <br> </font><font color="#dd0000">"header" </font><font color="#007700">=> </font><font color="#dd0000">"<table width=200px border=0 cellpadding=2 cellspacing=2>"</font><font color="#007700">, <br> </font><font color="#dd0000">"BodyUnselected" </font><font color="#007700">=> </font><font color="#dd0000">'<tr><td bgcolor=#C4D9FD >[prefix]&raquo;<a href="?id=[id]"><font color=#53507A>[name]</font></a></td></tr>'</font><font color="#007700">, <br> </font><font color="#dd0000">"BodySelected" </font><font color="#007700">=> </font><font color="#dd0000">'<tr><td bgcolor="#E4DB2C">[prefix]&bull;<a href="?id=[id]"><strong><font color="#000000">[name]</font></strong></a></td></tr>'</font><font color="#007700">, <br> </font><font color="#dd0000">"footer" </font><font color="#007700">=> </font><font color="#dd0000">'</table>'</font><font color="#007700">, <br> ); <br> <br> </font><font color="#0000bb">$output </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">html_output</font><font color="#007700">(</font><font color="#0000bb">$ctg_id</font><font color="#007700">); <br> echo </font><font color="#0000bb">$output</font><font color="#007700">; </font></font></code> </div> <?php $categories->HtmlTree = array( "header" => "<table width=200px border=0 cellpadding=2 cellspacing=2>", "BodyUnselected" => '<tr><td bgcolor=#C4D9FD >[prefix]»<a href="?id=[id]"><font color=#53507A>[name]</font></a></td></tr>', "BodySelected" => '<tr><td bgcolor="#E4DB2C">[prefix]•<a href="?id=[id]"><strong><font color="#000000">[name]</font></strong></a></td></tr>', "footer" => '</table>', ); $output = $categories->html_output($ctg_id); echo $output; ?> <hr> <? // lets get an array of the categories for our works $categories = new categories; $categories_list = $categories->build_list(); // lets do some actions if(!isset($_REQUEST['act'])) $_REQUEST['act'] = ""; $act = $_REQUEST["act"]; switch($act) { case "add": // lets add new category // $categories->add_new( category parent , category name , description , icon path , group ) $categories->add_new($_POST['parent'] , $_POST["name"] , $_POST["desc"] , $_POST["icon"] ); echo '<script>alert("Category was inserted successfully into database"); location="class_categories_test.php"; </script>'; break; case "delete": $categories->delete($_GET["id"]); echo '<script>alert("Category and Sub-Categories was successfully deleted"); location="class_categories_test.php"; </script>'; break; case "_update": $cat = $categories->fetch($_GET["id"]); ?> <form name="form1" method="post" action=""> <p> the form below will execute the following. <br> </p> <div class="code_div"> <code><font color="#000000"><font color="#007700"> </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">update</font><font color="#007700">(</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"id"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"parent"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"name"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"desc"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"icon"</font><font color="#007700">] );</font></font></code> </div> <br> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="3"><div align="center">Edit Category </div></td> </tr> <tr> <td width="13%">Child Of : </td> <td width="1%">:</td> <td width="86%"> <select name="parent" id="parent"> <option value="0" selected>ROOT</option> <? foreach($categories_list as $c) { if($cat["id"] == $c["id"]) continue; // we don't list the category to be child of itself !! ?> <option value="<?=$c["id"]?>" <? if($c["id"] == $cat["parent"]) echo "selected"; ?> ><?=$c["prefix"]?>»<?=$c["c_name"]?></option> <? } ?> </select> </td> </tr> <tr> <td>Name:</td> <td>:</td> <td><input name="name" type="text" id="name" value="<?=$cat["c_name"]?>" size="20"></td> </tr> <tr> <td>Description:</td> <td>:</td> <td><textarea name="desc" cols="40" rows="3" id="desc"><?=$cat["c_desc"]?> </textarea></td> </tr> <tr> <td>Icon:</td> <td>:</td> <td><input name="icon" type="text" id="icon" value="<?=$cat["c_icon"]?>" size="30"></td> </tr> <tr> <td colspan="3"><div align="right"> <input name="act" type="hidden" value="update"> <input name="id" type="hidden" value="<?=$ctg_id?>"> <input type="submit" name="Submit" value="Save"> </div></td> </tr> </table> </form> <? die(); break; case "update": $categories->update($_POST["id"] , $_POST["parent"] , $_POST["name"] , $_POST["desc"] , $_POST["icon"] ); echo '<script>alert("Category was updated successfully!"); location="class_categories_test.php"; </script>'; break; } ?> <p align="center"> </p> <p align="center"><strong>You may list all your categories expanded like this</strong></p> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories </font><font color="#007700">= new </font><font color="#0000bb">categories</font><font color="#007700">; <br> </font><font color="#0000bb">$categories_list </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">build_list</font><font color="#007700">(0);</font></font></code> <br>// $categories_list is now an array and you should use foreach command to print something like the following list. </div> <br> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td bgcolor="#4180BE"><font color="#FFFFFF"><strong> Categories List: </strong></font></td> </tr> <? foreach($categories_list as $c) { ?> <tr> <td> <?=$c["prefix"]?>»<?=$c["c_name"]?> - [<a href="?act=_update&id=<?=$c["id"]?>">Edit</a> - <a href="?act=delete&id=<?=$c["id"]?>">Delete</a>] </td> </tr> <? } ?> </table> <p align="center"> </p> <p align="center"><strong>Or you may also use it in a combo box</strong></p> <table width="0" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="72"><select name="category_id" id="category_id"> <? foreach($categories_list as $c) { ?> <option value="<?=$c["id"]?>"><?=$c["prefix"]?>»<?=$c["c_name"]?> </option> <? } ?> </select></td> <td width="0"><input type="button" name="Button" value="Edit" onClick="location='class_categories_test.php?act=_update&id='+document.getElementById('category_id').value;"></td> <td width="0"><input type="button" name="Button" value="Delete" onClick="location='class_categories_test.php?act=delete&id='+document.getElementById('category_id').value;"></td> </tr> </table> <p> </p> <p><hr></p> <form name="form1" method="post" action=""> the form below will execute the following. <br> <div class="code_div"> <code><font color="#000000"><font color="#ff8000"> </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">add_new</font><font color="#007700">(</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">'parent'</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"name"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"desc"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"icon"</font><font color="#007700">] ); </font></font></code></div><br> <table width="400" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="3" bgcolor="#4180BE"><div align="center"><strong><font color="#FFFFFF">Add New Category </font></strong></div></td> </tr> <tr> <td width="13%">Child Of : </td> <td width="1%">:</td> <td width="86%"><select name="parent" id="parent"> <option value="0">ROOT</option> <? foreach($categories_list as $c) { ?> <option value="<?=$c["id"]?>" > <?=$c["prefix"]?>»<?=$c["c_name"]?> </option> <? } ?> </select></td> </tr> <tr> <td>Name:</td> <td>:</td> <td><input name="name" type="text" id="name" size="20"></td> </tr> <tr> <td>Description:</td> <td>:</td> <td><textarea name="desc" cols="40" rows="3" id="desc"></textarea></td> </tr> <tr> <td>Icon:</td> <td>:</td> <td><input name="icon" type="text" id="icon" value="http://" size="30"></td> </tr> <tr> <td colspan="3"><div align="right"> <input name="act" type="hidden" value="add"> <input type="submit" name="Submit" value="Add"> </div></td> </tr> </table> </form> <p align="center"> </p> </body> </html> Sorry for making this long post,hope u won,t mind :-) and will solve my problem Hi guys, Hello, I am trying to pick up php again and just exercising my skills. So I have it so that it fills my form with the values of what I want to edit, and when I click the edit button, it doesn't edit any of the information. When I echo out $result, I get a MYSQL query string that has the same values as the table, so its not getting the new values that are edited. <?php @mysql_connect('localhost', 'root', '') or die("Could not connect to Mysql Server. " . mysql_error()); @mysql_select_db('tutorials') or die("Could not connect to Database. " . mysql_error()); if(isset($_GET['edit'])) { $id = $_GET['edit']; $query = "SELECT `username`, `password` FROM `users` WHERE `id` = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $name = $row['username']; $password = $row['password']; } if(isset($_POST['edit'])) { $id = $_GET['edit']; $query = "UPDATE `users` SET `username` = '$name', `password` = '$password' WHERE `id` = '$id'"; $result = mysql_query($query); echo $query; if(!$result) { echo mysql_error(); }else{ echo 'updated post'; } } ?> <form method="POST" action="" > <input type="text" name="name" value="<?php echo $name; ?>" /> First name <br /> <input type="text" name="password" value="<?php echo $password; ?>" /> Last name <br /> <input type="submit" name="edit" value="edit" /> </form> I believe it has something to do with the values of $name and $password in the form conflicting with the first if isset and the second if isset. Thanks for any help possible I have a webpage where all the database items are displyes in a table format.The table also has a check box.Upon clicking the delete button i need to delete all the items whish has the checkbox checked. How will i do that I'd like to write - or acquire - code that displays a simple table (name, phone number, email address, plus a comments field) on a web page in a password-protected page and allows a user to add his own information, update it or delete it. I figure hundreds of people and companies have written something like this so I'd like to find either an example I can imitate or even an existing package that I can simply customize to the specifics for my own table. Can anyone help me with that? Or am I going to have to reinvent the wheel for the gazillionth time and write it myself? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321612.0 |