PHP - Utterly Baffled- Update A Table
Hi
I'm trying to update a form to a mysql database- it's simply all text fields except for one integer which is the primar key (auto increment etc) http://www.arts.ulster.ac.uk/interviews/test.php http://www.arts.ulster.ac.uk/interviews/thanks3.php test.php holds the form and the recaptcha which all seems to be fine and it posts to thanks3.php which (when i switched to $_GET) is passing the variables to that page but those values are not being stored. I then input my query into the mySQL query browser: INSERT INTO UCASinterviews VALUES ('','$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents'); which updated the values i put in but gave this error: Incorrect integer value: '' for column 'ID' at row 1 thanks3.php just won't transfer that info to the table no matter what I try. I used $_GET, I used PHP_SELF, I stripped the rest of the page away to make sure nothing was conflicting and now I'm totally stumped- please could someone look at this with fresh eyes? test.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <form action="thanks3.php" method="post" id="form2" style="margin-left:15px; display:;"> <dl id="contform"> <dd><label>Name:</label><br /> <input class="padform" type="text" name="name" size="43" maxlength="20" tabindex="2"/></dd> <label>UCAS ID:</label><br /> <input class="padform" name="UCAS" type="text" id="UCAS" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Email:</label><br /> <input class="padform" name="email" type="text" id="email" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Mobile:</label><br /> <input class="padform" name="mob" type="text" id="mob" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Landline:</label><br /> <input class="padform" name="tel" type="text" id="tel" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Subject:</label><br /> <select name="subject" tabindex="1" class="padform"> <option value="English">English</option> <option value="European Studies">European Studies</option> <option selected value="Film Studies">Film Studies</option> <option value="French">French</option> <option value="German">German</option> <option value="History">History</option> <option value="Irish">Irish</option> <option value="Spanish">Spanish</option> <option value="Journalism">Journalism</option> <option value="Photo Imaging">Photo Imaging</option> <option value="Media Studies and Production">Media Studies & Production</option> <option value="Interactive Media Arts">Interactive Media Arts</option> </select></dd> <dd><label>Address:</label><br /> <textarea class="padform"name="address" cols="40" rows="15" id="address" tabindex="5"/> </textarea></dd> <dd> <label>Preferred Interview Date:</label> <select name="interviewdate" class="padform"> <option value="26/02/11">26 February 2011</option> <option selected value="12/03/11">12 March 2011</option> </select> </dd> <dd> <label>Preferred Interview Time:</label> <select name="interviewtime" class="padform"> <option value="AM">Morning (AM)</option> <option selected value="PM">Afternoon (PM)</option> </select> </dd> <dd> <label>Parents/Guardians:</label> <select name="parents" class="padform"> <option value="1">1</option> <option selected value="2">2</option> </select> </dd> <dd> <p> <?php require_once('recaptcha/recaptchalib.php'); $publickey = "6LdU2b4SAAAAAGsh6Z78HjunUL6Mt-ZqCXtIimOs"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> </p> </dd> <dd style="background:none;"><input class="btn" type="submit" name="submit" value="Send" tabindex="6" id="submit" /></dd> </dl> </form> </div> </body> </html> thanks3.php <?php require_once('recaptcha/recaptchalib.php'); $privatekey = "6LdU2b4SAAAAAN_Z9rLyvle0vb4n4EbyAVyXDa6V"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification require_once("../includes/db_connect.php"); if($_POST['submit']=="true"){ $name=$_POST['name']; $address=$_POST['address']; $UCAS=$_POST['UCAS']; $mobile=$_POST['mob']; $email=$_POST['email']; $tel=$_POST['tel']; $subject=$_POST['subject']; $interviewdate=$_POST['interviewdate']; $interviewtime=$_POST['interviewtime']; $parents=$_POST['parents']; $addEntry="INSERT INTO UCASinterviews VALUES ('','$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents');"; $addResult=mysql_query($addEntry,$db); } } ?> I have other forms working with this near enough the same structure/layout/code - i'm ready to have a coronary! Is it the database setup? It's same as it ever was myISAM, UTF unicode... Similar TutorialsCan anyone post a generic update function to update mysql table. The manual approach: update $tablename set $column1='a', $column2='b' where $id=$value; I'm new to PHP and I was able to figure out how to populate data from my database into my text fields. I am trying to add the update information to the same php file; however, I am now receiving errors within the data I was able to populate,
Notice: Undefined variable: stmt in C:\xampp\htdocs\Cust_App\update.php on line 47 and errors with the Update statement
Notice: Undefined variable: stmtupdate in C:\xampp\htdocs\Cust_App\update.php on line 96 I had defined the customerID variable above in the code, but it isn't being captured from here. I tried setting up this query like the one which gathered the data, but I'm off by a little bit. I would like the option to be able to update all fields. Any help is appreciated. I'm trying to learn as I may get asked to update other forms in the future. (new boss asks a lot) <?php require_once('database.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <!-- the head section --> <head> <title>My Guitar Shop</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <!-- the body section --> <body> <div id="page"> <div id="header"> <h1>SportsPro Technical Support</h1> <p>Sports management software for the sports enthusiast.</p></h1> </div> <div id="main"> <h1>View/Update Customer</h1> <form action="update.php" method="get" > <?php if(isset($_GET['customerID'])) { $customerID = filter_input(INPUT_GET, 'customerID', FILTER_SANITIZE_NUMBER_INT); $sql = "SELECT * FROM customers WHERE customerID =$customerID "; $stmt = $db->query($sql); } ?> <div id="content"> <!-- display a table of products --> <h2>Customers</h2> <form method = "edit"> <?php foreach ($stmt as $cust) { ?> <div> <label>First Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['firstName']; ?>"> </div><br> <div> <label>Last Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['lastName']; ?>"> </div><br> <div> <label>Address</label> <input type="text" name="address" class ="form-control" value ="<?php echo $cust['address']; ?>"> </div><br> <div> <label>City</label> <input type="text" name="city" class ="form-control" value ="<?php echo $cust['city']; ?>"> </div><br> <div> <label>State</label> <input type="text" name="state" class ="form-control" value ="<?php echo $cust['state']; ?>"> </div><br> <div> <label>Country</label> <input type="text" name="countryCode" class ="form-control" value ="<?php echo $cust['countryCode']; ?>"> </div><br> <div> <label>Zip Code</label> <input type="text" name="postalCode" class ="form-control" value ="<?php echo $cust['postalCode']; ?>"> </div><br> <div> <label>Email </label> <input type="text" name="email" class ="form-control" value ="<?php echo $cust['email']; ?>"> </div><br> <div> <label>Phone Number </label> <input type="text" name="phone" class ="form-control" value ="<?php echo $cust['phone']; ?>"> </div><br> <div> <label>Password </label> <input type="text" name="password" class ="form-control" value ="<?php echo $cust['password']; ?>"> </div><br> <div> <?php } ?> <input type="Submit" name="Update_Data" value="Update Data"></input> <?php $sql2 = "UPDATE customers SET firstName = ". $stmtupdate['firstName']." WHERE customerID =$customerID "; $stmtupdate = $db->query($sql2); ?> </div> </div> <div id="footer"> <p> © <?php echo date("Y"); ?> SportsPro, Inc. </p> </div> </div><!-- end page --> </body> </html>
Hey everyone, I'm getting an error on this code and I'm having a difficult time sorting it out. Most of this page is in html, but here is what little PHP I'm using as of now: Code: [Select] <select class="ddbox2" name="occasion"> <option value="select" selected>- Select -</option> <?php $resdate = "02/20/2012"; $result = mysql_query("SELECT `time` FROM delivery_times WHERE `index` > '0'"); while ($row = mysql_fetch_row($result)) { $posstime = $row[0]; $reserved = mysql_query("SELECT * FROM reservations WHERE `resdate` = '$resdate' AND `deltime` == '$posstime'"); $rowcheck = mysql_num_rows($reserved); // <-- THIS IS LINE 198 if ($rowcheck == 0) { echo "<option value='$posstime'>$posstime</option>"; } } ?> </select> What I'm doing is creating a dropdown menu for an html form depending on what is in my database, but here is the error that I'm getting: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\new_site\custform.php on line 198" When I change line 198 to read: $rowcheck = mysql_num_rows($result); I don't get the error, but I don't get the information that I need to complete my task. I was thinking that maybe this query isn't allowed in a while loop for some reason, but I don't think that would be the case. Any ideas on what I could be doing wrong? Hello,
NOTE: I'm not asking for help to modify the code below, only looking for feedback regarding why it is working
I'm working over other's people code and I found this lines:
<div class="button-container" style="top:20px; left:0px"> <input type="submit" name="submit" value="Get Report" <a href="#" class="large-button" style="left: 0px" > <div class="button-glare"> </div> </a> </div>Clearly the input tag is wrong (W3C validator confirm it), however works fine and does what is supposed to do (apply some css styles over the submit button). IE11 Developer tools detect the errors, but FF nor Chrome does. this is what it looks like (attached image) and this is the related CSS /* CSS Document */ /* Button Containers */ .button-container { float: left; overflow: visible; position: relative; } .button-container .large-button { background: linear-gradient( to top, green, lightgray); border-radius: 6px; font-size: 14px; font-weight: bold; color: #FFFFFF; line-height: 14px; padding: 10px 20px 8px; text-shadow: -1px -1px 1.5px rgba(0, 0, 0, 0.5); position: relative; } .button-container .button-glare { border-radius: 4px; height: 50%; left: 1px; position: absolute; right: 1px; top: 1px; z-index: -1; }any idea why it does work? thanks Miko The alias form isn't being read for some reason, with having $alias = $_POST['alias']; i don't quiet understand why this isn't it isn't being picked up as a variable below, any clues? cheers Code: [Select] <?php include("header.php"); if(isset($_POST['formAlias']) && $_POST['formAlias'] == 'Yes') { $alias = $_POST['alias']; $alias = preg_replace("/[^a-zA-Z0-9_]/", "", $alias); $namelength = strlen($alias); if($namelength < 3){ $error1="Your alias must be at least 3 characters!</span></div>"; echo $error1; }else{ } $query = sprintf("SELECT COUNT(id) FROM players WHERE UPPER(alias) = UPPER('$alias')", mysql_real_escape_string($alias)); $result = mysql_query($query); list($count) = mysql_fetch_row($result); if($count >= 1) { $error1="$alias is already taken."; echo $error1; }else{ } $sql = "updatehereble"; mysql_query($sql) or die(mysql_error()); }else{ } ?> </p> <p> <input name="alias" type="text" id="alias"> </p> <form action="alias.php" method="post"> Do you wish to use an alias? <input type="checkbox" name="formAlias" value="Yes" /> <input type="submit" name="formSubmit" value="Submit" /> </form> Hello I have three tables User diysmps usergroup usergroupid is common in the three tables. diysmps is joined on usergroup, so running this sql SELECT diysmps.name, diysmps.email, diysmps.sumbit, diysmps.message, diysmps.ID, usergroup.title FROM diysmps INNER JOIN usergroup ON diysmps.usergroupid = usergroup.usergroupid ORDER BY diysmps.ID DESC see results i get in picture attached. the result (PENDIN REGISTRATION) is what i need to be updated WHEN the user register to the forums. when the user register to the forums, an account with his EMAIL will be created into the (USER) table. So, I need to look out for the email FROM (diysmps TABLE) into the user table _search user table for email from diysmps table_ and if found to update the USERGROUPID in (diysmps TABLE) withe the USERGROUPID from (USER) table (related to the email searched) so, when user registers, status from PENDING REGISTRATION to REGISTERED will be shown I know it looks complex for me, but thats how i can describe Thanks all PHP = 5.5.14
MySQL = 5.2.17
I've cloned a mysqli_connect() statement in a 'require' file placed in a non-public access location on the server. It's the same format (and location) currently working fine with another application, EXCEPT i changed the database name to what I need to use for this application, AND added the $con= part on the front end to substitute for the commented out $con= line in the example code I'm modifying to insert data into a new MySQL DB Table.
The dB Table is fine and I have Inserted data via myPHPAdmin with no problems. Only two form variables are in the simple PHP script thus far just to test if it will work before proceeding.
I've used pseudonames for the actual /home/.... location and filename, and am now Baffled about the Line 2 Error Message I'm getting (below the code).
<?php require '/home/myusername/domains/mydomain.com/myclonedrequire.php'; //$con=mysqli_connect("example","uid","pwd","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // escape variables for security $year = mysqli_real_escape_string($con, $_POST['year']); $callsign = mysqli_real_escape_string($con, $_POST['callsign']); $sql="INSERT INTO `lqplogs` (`year`, `callsign`) VALUES ('$year', '$callsign'); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>ERROR Message: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in (above file & location) on line 2 There are NO '\' characters in any of my files. Here is the simple Form file code: <?php ?> <html: <head><title></title></head> <body> <form action="insert.php" method="post"> YEAR: <input type="text" name="year"> CALLSIGN: <input type="text" name="callsign"> <input type="submit"> </form> </body> </html> <?php ?>Thanks for any assistance! -FreakingOUT I have made a thread earlier but i did not get any help. changeapp.php Code: [Select] <form method="post" name="memberadd" action="change_app_complete.php"> <label>Name:</label> <select name="member"> <?php $con = mysql_connect("host","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sqlquery="SELECT * FROM `application` Order By Name"; $result=mysql_query($sqlquery,$con); while($row=mysql_fetch_array($result)) { echo "<option value='".$row['ID']."'>".$row['Name']." (".$row['Status'].")</option>"; } ?> </select> <br> <label>Status:</label> <select name="Status"> <option value="PENDING">PENDING</option> <option value="ACCEPTED">ACCEPTED</option> <option value="DENIED">DENIED</option> <br> <input type="submit" value="submit" /> </form> change_app_complete.php Code: [Select] <?php $status=$_POST['Status']; $member=$_POST['Name']; $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sql="UPDATE application SET Status = '$status' WHERE Name= '$member'"; if(mysql_query($sql,$con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } mysql_close($con); ?> This does not return any errors and does not change the Status... ---- I can not do this : $sql = mysql_query("UPDATE myMembers SET email_activated='1' WHERE id='$id' AND password='$hashpass'"); ---- i get this: $msgToUser = "<br /><br /><h3><strong><font color=red>Your account could not be activated!</font></strong><h3><br /> <br /> Please email site administrator and request manual activation. "; thanks guys ok so here is whats going on i have this small little php to update one thing in a table but it's not updating the mysql_error is You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check=1 WHERE id='21'' at line 1 what is the prob because i spent a hour on this and cant git it? here is the php Code: [Select] <?php include '../config.php'; $id = $_GET['del']; mysql_query("UPDATE call_list SET check=1 WHERE id='$id'")or die(mysql_error()); header("Location: index.php"); ?> I'm pretty inexperienced with coding and trying to get a row of a MySQL database to update when a form is submitted, but can't seem to get it to work. Here's what I have... Code: [Select] if($_POST['action'] == 'update'){ //update $rename = $_POST['rename']; $uid = $_POST['rowid']; mysql_query("UPDATE `master` SET `name` = '$rename' WHERE `id` = '$uid'"); } Then the form... Code: [Select] <?php $result = mysql_query("SELECT * FROM `master`"); if(mysql_num_rows($result)){ while ($row = mysql_fetch_array($result)){ ?> <td><?php echo $row['name']; ?></a></td> <td><input type="text" size="5px" name="rename" value="" /></td> <td><input type="hidden" name="rename" value="<?php echo $row['name']; ?>" /><input type="hidden" name="rowid" value="<?php echo $row['id']; ?>" /><input type="hidden" name="action" value="update" /><input type="submit" value="Update" /></td> </tr> <?php } } ?> Can anyone give me some hints as to why this won't work? Thaks! hey forum people can you help me on one problem so i have script what should update mysql table by username Code: [Select] UPDATE data SET username='$name' WHERE value1='$value1' AND value2='$value2' AND value3='$value3' AND value4='$value4' AND value5='$value5'any ideas ? hey guys im really stuck and need help with this. im trying to update a mysql table from an array. basically i have 12 records what are pulled using a query. each record has its own ID to distinguish it from the rest. i then have 2 tick boxes for the user to select one for accept and one for deny. what i need is for the query to look at each record on the table and insert the selection boxes value if ticked. my code is below but i have altered it to the hilt and cannot get it to work so please help Code: [Select] <?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/Apollo/dbc.php"; include_once($path); $rs_results = mysql_query("SELECT * FROM off WHERE IsItAuthorised='0' and isitsick='0' ORDER BY DayOff"); ?> <html> <head> <title>Administration Main Page</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <?php if (isset($_POST['submit'])) { //Assign each array to a variable $id = $_POST['id']; $approve = $_POST['approve']; $deny = $_POST['deny']; $limit = count($id); $values = array(); // initialize an empty array to hold the values for($k=0;$k<$limit;$k++){ $msg[] = "$limit Holidays Updated"; $id[k] = $id; $approve[k] = $approve; $deny[k] = $deny; $id = implode($id); $approve = implode( $approve); $deny = implode( $deny); $query = "UPDATE off SET Authorised = $approve , Deny = $deny WHERE OffID = $id " ; } $Event = "INSERT INTO events (UserName, Event ) VALUES ('$_SESSION[user_name]', 'Entered New KPI' )"; echo $query; if (!mysql_query($query,$link)){ die('Error: ' . mysql_error()); } else { mysql_query($Event); echo "<div class=\"msg\">" . $msg[0] . "</div>"; } } ?> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="14%" valign="top"><?php ?> </td> <td width="74%" valign="top" style="padding: 10px;"> <p><?php if(!empty($msg)) { echo $msg[0]; } ?></p> <p> <?php $cond = ''; $sql = "select * from off "; $rs_total = mysql_query($sql) or die(mysql_error()); $total = mysql_num_rows($rs_total); ?> <p> <form name "searchform" action="/Apollo/Admin/HolidayRequests.php" method="post"> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr class="mytables"> <td width="4%"><font color="white"><strong>ID</font></strong></td> <td width="4%"> <font color="white"><strong>Staff Member</font></strong></td> <td width="10%"><font color="white"><strong>Day Off</font></strong></div></td> <td width="10%"><font color="white"><strong>Is It Authorized</font></strong></div></td> <td width="15%"> </td> </tr> <tr> <td> </td> <td width="10%"> </td> <td width="17%"><div align="center"></div></td> <td> </td> </tr> <?php while ($rrows = mysql_fetch_array($rs_results)) {?> <tr> <td><input name="id[]" id="id[]" size="4" value="<?php echo $rrows['OffID'];?>" /></td> <td><?php echo $rrows['StaffMember']; ?></td> <td><?php echo date('d/m/Y', strtotime($rrows['DayOff']));?></div></td> <td> <span id="approve<?php echo $rrows['id']; ?>"> <?php if(!$rrows['IsItAuthorised']) { echo "Pending"; } else {echo "Authorized"; }?> </span> </td> <td> <input type="hidden" name="approve[]" id="approve[]" value="0"> <input type="checkbox" name="approve[]" id="approve[]" value="1"> Approve <input type="hidden" name="deny[]" id="deny[]" value="0"> <input type="checkbox" name="deny[]" id="deny[]" value="1"> Deny </td> </tr> <?php } ?> </table> <input name="submit" type="submit" id="submit" value="Submit"> </form> </p> <?php ?> <p> </p> <p> </p> <p> </p> <p> </p></td> <td width="12%"> </td> </tr> </table> </body> </html> I have no idea if this is possible or not, but I've got a form that searches a DB for a record. If that record is found, it displays a form that people can edit the record. Now, if that person wants to change (for example) 1 record out of 16 called "status" from "lost" to "found" but leave all the rest as they are, how would I go about this? Basically, I need to check all the fields ON SUBMIT if they're different from the original values in the DB and only update if they are. Any help would be appreciated. Cheers, Dave Not sure how to update a record in my table here. I got my insert and delete statement working. Just can't get the update to work correctly. I'm not really sure how to do it. Here is my code for my page, and my update and delete page Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (grade_id, student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:grade_id, :student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_id', $_SESSION['grade_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_point']); $statement->execute(); $statement->closeCursor(); $grade_type = $_POST['grade_type']; if ($grade_type == 'Lab') { $final *= .60; } echo $final; $grade_type = $_POST['grade_type']; if ($grade_type == 'Mid-Term') { $final *= .20; } echo $final; $grade_type = $_POST['grade_type']; if ($grade_type == 'Final') { $final *= .20; } echo $final; } ?> <!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>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="delete_grade.php" method="post"> <input type="submit" name="remove" value="Delete" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> My delete and update page Code: [Select] <html> <head> <title>Delete Grade</title> </head> <body> <form method="post" action="delete_grade.php"> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') or die(mysql_error()); //delete grades if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } echo 'user has been deleted.<br />'; } if (isset($_POST['update'])) { foreach($_POST['update'] as $update_id) { $query = "UPDATE grades SET grade_id = $grade_id"; mysqli_query($dbc, $query) or die ('can\'t update user'); } } //Display grade info with checkbox to delete $query = "SELECT * FROM grades"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '" name="delete[]" />'; echo ' ' .$row['grade_type'] .' '. $row['grade_name']; echo '<br />'; } mysqli_close($dbc); ?> <input type="submit" name="remove" value="Remove" /> <input type="submit" name="update" value="Update" /> </form> </body> </html> Good morning: This is the output of my test database table: 2011-05-30 Chevrolet Monte Carol 1975 9000 15000 James Bond's 007-1212 james@bond.com B I am setting the rocord for bond's most active movies. 2011-05-31 Dodge Stratus 2008 5000 7500 James Cagney 555-1818 jc@hollywood.com S This is not going to be the best of time's. Ain't it? Within my table I have two important fields--the record date-created field shown on the left and the (hidden) EXPIRED field--on which the UPDATE function depends. This is my code for (wherein lies the problem) UPDATING the record within my table and setting the EXPIRED field to 'Y' for filtering and easy deletion of the record(s). Code: [Select] <?php // Connect to database. include("connect.php"); // Access the database @mysql_select_db($database,$con) or die( "Unable to select database"); $result = mysql_query("SELECT * FROM Autos"); //read all records into array while($row = mysql_fetch_array($result)) //loop through array { if (1 - strcmp(date("Y-m-d"),$row['DateCreated']) == 0) //compare current date with record date and act when result is zero { mysql_query("UPDATE Autos SET Expired = 'Y' WHERE Expired == 'N'"); //if ready to expire then update table EXPIRED field } else { if ($row['BuyerSeller'] == 'B') { echo "Contact buyer below"; } elseif ($row['BuyerSeller'] == 'S') { echo "Contact seller below"; } echo "<br />"; echo $row['DateCreated'] . " " . $row['Make'] . " " . $row['Model'] . " " . $row['Year'] . " " . $row['MinPrice'] . " " . $row['MaxPrice'] . " " . $row['POC'] . " " . $row['POCPhone'] . " " . $row['POCEmail'] . " " . $row['Notes']; echo "<br />"; } } mysql_close($con) ?> Lastly, does the mysql_close function with the single parameter $con also close the database? MOD EDIT: code tags added. hai this is mani,i am new to php and mysql ...first of all forgive for my english...i am having problem with my mysql .i am having a table 'user' and fields 'id','name','status' .i can enter the values to the table. for example.... id=1,name="db' status='first' what i need is i have to update the status value to 'second' automatically after one year. how can i do that? OK I have no idea why this will not update the table but here is the code I wrote. I just can't see it Code: [Select] <?php //CONNECT TO DATABASE include("sharons_dbinfo.inc.php"); mysql_connect(localhost,$user,$password); mysql_select_db($database) or die( "Unable to select database"); //OPEN THE ZIP FILE $handle = gzopen('Newegg_com-Daily_Deals_Feed.txt.gz', 'r'); //READ THE WHOLE FILE LINE BY LINE while (!gzeof($handle)) { $buffer = gzgets($handle, 4096); $buffer = str_replace("'" , "" , $buffer); $buffer = str_replace("\"" , "" , $buffer); $data = explode(",", $buffer); //SKIP THE FIRST LINE OF COLUMN NAMES if ($data[4] == "NAME"){} else{ //PUT THIS IN TO MAKE SURE IT WAS LOOKING FOR THE RIGHT RECORD print "Looking for: ". $data['4'] . " to update with new date " . $data['3']."<br>"; $item_name = $data['4']; //QUERY THE TABLE FOR PRODUCT NAME FROM ZIP FILE $query = ("SELECT * FROM `computer_memory` WHERE `NAME` = '$item_name'"); $results = mysql_query($query) or die(mysql_error()."<br /><br />".$query); $result = mysql_fetch_array($results); $num=mysql_numrows($results); //IF THE NAME EXISTS PROCEED TO UPDATE THE RECORD WITH THE NEW INFORMATION if ($num >0) { //UPDATE TABLE WITH THE NEW INFORMATION $update = ("UPDATE `computer_memory` SET `PROGRAMNAME`= '$data[0]', `PROGRAMURL`= '$data[1]', `CATALOGNAME`= '$data[2]', `LASTUPDATED`= '$data[3]', `NAME`= '$data[4]', `KEYWORDS`= '$data[5]', `DESCRIPTION`= '$data[6]', `SKU`= '$data[7]', `MANUFACTURER`= '$data[8]', `MANUFACTURERID`= '$data[9]', `UPC`= '$data[10]', `ISBN`= '$data[11]', `CURRENCY`= '$data[12]', `SALEPRICE`= '$data[13]', `PRICE`= '$data[14]', `RETAILPRICE`= '$data[15]', `FROMPRICE`= '$data[16]', `BUYURL`= '$data[17]', `IMPRESSIONURL`= '$data[18]', `IMAGEURL`= '$data[19]', `ADVERTISERCATEGORY`= '$data[20]', `THIRDPARTYID`= '$data[21]', `THIRDPARTYCATEGORY`= '$data[22]', `AUTHOR`= '$data[23]', `ARTIST`= '$data[24]', `TITLE`= '$data[25]', `PUBLISHER`= '$data[26]', `LABEL`= '$data[27]', `FORMAT`= '$data[28]', `SPECIAL`= '$data[29]', `GIFT`= '$data[30]', `PROMOTIONALTEXT`= '$data[31]', `STARTDATE`= '$data[32]', `ENDDATE`= '$data[33]', `OFFLINE`= '$data[34]', `ONLINE`= '$data[35]', `INSTOCK`= '$data[36]', `CONDITION`= '$data[37]', `WARRANTY`= '$data[38]', `STANDARDSHIPPINGCOST`= '$data[39]' WHERE `ID`= '$id'"); mysql_query($update) or die(mysql_error()."<br /><br />".$update); //if ($update){print "UPDATED ".$result['ID'];} }else{ //IF THE NAME DID NOT EXIST INSERT A NEW RECORD INTO THE TABLE $import="INSERT into computer_memory (`ID`,`PROGRAMNAME`,`PROGRAMURL`,`CATALOGNAME`,`LASTUPDATED`,`NAME`,`KEYWORDS`,`DESCRIPTION`,`SKU`,`MANUFACTURER`,`MANUFACTURERID`,`UPC`,`ISBN`,`CURRENCY`,`SALEPRICE`,`PRICE`,`RETAILPRICE`,`FROMPRICE`,`BUYURL`,`IMPRESSIONURL`,`IMAGEURL`,`ADVERTISERCATEGORY`,`THIRDPARTYID`,`THIRDPARTYCATEGORY`,`AUTHOR`,`ARTIST`,`TITLE`,`PUBLISHER`,`LABEL`,`FORMAT`,`SPECIAL`,`GIFT`,`PROMOTIONALTEXT`,`STARTDATE`,`ENDDATE`,`OFFLINE`,`ONLINE`,`INSTOCK`,`CONDITION`,`WARRANTY`,`STANDARDSHIPPINGCOST`) values('','$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[13]','$data[14]','$data[15]','$data[16]','$data[17]','$data[18]','$data[19]','$data[20]','$data[21]','$data[22]','$data[23]','$data[24]','$data[25]','$data[26]','$data[27]','$data[28]','$data[29]','$data[30]','$data[31]','$data[32]','$data[33]','$data[34]','$data[35]','$data[36]','$data[37]','$data[38]','$data[39]')"; mysql_query($import) or die(mysql_error()); } } } gzclose($handle); ?> I hope someone can see what I can't Thanks everyone Hi all, I need to create a button my page that when clicked will update my mysql table. I also need a command that will find 3 'x' values and update them accordingly, It needs to update the theme column in my model pictures table, Would something similiar like this work? Code: [Select] UPDATE theme SET name = '5' WHERE name = '1 or 2 or 4';[code] Does this make sense? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348465.0 |