PHP - Save Each Record Into Database And Then Update Table For All Users
Hello,
Here is my current code:
index.php
<html> <body> <form id="hey" name="hey" method="post" onsubmit="return false"> Name:<input type="text" name="name"> <input type="submit" name="submit" value="click"> </form> <table class="table table-bordered" id="update"> <thead> <th>Name</th> </thead> <tbody> <script type="text/javascript"> $("#hey").submit(function() { $.ajax({ type: 'GET', url: 'response.php', data: { username: $('#name').val()}, success: function (data) { $("#update").prepend(data); }, error: function (xhr, ajaxOptions, thrownError) { alert(thrownError); } }); }); </script> </tbody> </table>response.php <?php $username = $_GET['username']; echo "<tr>"; echo "<td>$username</td>"; echo "</tr>"; ?>This code works fine, it prints out the rows as what the user enters. Now what I want to do is, log all these entries to a mySQL database and also, display these rows over the site. i.e., any user who is online, should be seeing this without having to refresh the page too.. Real time updates in a way. How can I achieve that? Thanks! Similar TutorialsHello folks I am new to php and I have been trying to put together a database that a user can search and choose from the results. I have managed to make this script by copying code from google searches and trial and error. The script so far has been tested and works. The hard part is the code for choosing from the results, I have tried some things but I have been far from the mark, the thing is I can't get my head around the problem, if the first field is a number which is unique to each row, how can I pick that up in a php argument. I have tried making the first field an href link to send that number to a different table which would collect the results of the users choices, but I'm just not sure what to put in the code. Could someone throw me a lifeline here I've searched for hours on google to find any code that looks like it would work with no luck. // Get the search variable from URL $var = @$_GET['a'] ; $trimmed1 = trim($var); //trim whitespace from the stored variable $var = @$_GET['b'] ; $trimmed2 = trim($var); $var = @$_GET['c'] ; $trimmed3 = trim($var); $var = @$_GET['d'] ; $trimmed4 = trim($var); $var = @$_GET['e'] ; $trimmed5 = trim($var); $var = @$_GET['f'] ; $trimmed6 = trim($var); //connect to your database mysql_connect("localhost","root",""); //(host, username, password) //specify database mysql_select_db("a2149809_MV") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "SELECT * FROM `table` WHERE `field1` LIKE \"%$trimmed1%\" AND `field2` LIKE \"%$trimmed2%\" AND `field3` LIKE \"%$trimmed3%\" AND `field4` LIKE \"%$trimmed4%\" AND `field5` LIKE \"%$trimmed5%\" AND `field6` LIKE \"%$trimmed6%\" order by `field1`"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); <table width="100%" border=2 cellspacing=2 cellpadding=2> <tr><form name="form" action="" method="get"> <td colspan="6"><input type="submit" name="Submit" value="Search" /> </td> </tr> <tr> <td><input type="text" name="a" value="" size="4" /></td> <td><input type="text" name="b" value="" size="40" /></td> <td><input type="text" name="c" value="" size="3" /></td> <td><input type="text" name="d" value="" size="10" /></td> <td><input type="text" name="e" value="" size="10" /></td> <td><input type="text" name="f" value="" size="10" /></td> </form></tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"Field1"); $f2=mysql_result($result,$i,"Field2"); $f3=mysql_result($result,$i,"Field3"); $f4=mysql_result($result,$i,"Field4"); $f5=mysql_result($result,$i,"Field5"); $f6=mysql_result($result,$i,"Field6"); ?> <tr> <td><?php echo $f1; ?></td> <td><?php echo $f2; ?></td> <td><?php echo $f3; ?></td> <td><?php echo $f4; ?></td> <td><?php echo $f5; ?></td> <td><?php echo $f6; ?></td> </tr> <?php $i++; } ?> </table> 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> Hello I'm trying to set up a user area for my site where it displays the current logged in users ranking and other information in the future. <? ini_set('display_errors', 1); require_once "header.php"; $sql = "SELECT * FROM users WHERE username = ?"; if($stmt = mysqli_prepare($link, $sql)){ mysqli_stmt_bind_param($stmt, 's', $_SESSION['username']); if(mysqli_stmt_execute($stmt)){ $info = mysqli_fetch_array($stmt); echo "Current rank:" . $info['rank']; } else { echo "Can't find user"; } } mysqli_stmt_close($stmt); ?> That's the code I currently have but it gives me the error "but get an error message of mysqli_fetch_array() expects parameter 1 to be mysqli_result" 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..
currently i am developing client dashboard using php/mysql.Here is my problem i need to create a tab named as notes.Using this tab the logged in users can add a new note or edit his existing note and save as text file.. Hi guys, Doing a small project and i'm pretty new to php/mysql so hoping someone can help. Also i wasn't sure if this should be in php section or mysql, so apologises if it's in the wrong section. Basically... I have a form with a table in it with the fields (id, model, current stock level, new stock level) The table is populated using a mysql query to get the data from 1 table in a database. In the new stock column there's a simple text box to put a number in. Sooo like (ID) (Model) (current stock level) (new stock level) 1 AAA 3 [ ] 2 BBB 1 [ ] 3 CCC 4 [ ] A user will then put a new number in the 'new stock level' text box and when it gets submitted the new number replaces the number in 'current stock level' Basically i know how to do it if it was just the one record, but how do i get it to update all the ones with numbers in the new stock level column at the same time, and ignore it if it doesn't have anything entered in the text box? appreciate any help! thanks! My form has 40 fields, and I want to re-generate it to be reviewed as it was when submitted. Next, I want to be able to UPDATE the forms values, where necessary. Is there an easy way to UPDATE the entire form from the reviewable version. Is it smarter to update ONLY the specific items that need modification? Any examples would be helpful. Hi, I have a simple mySQL database and I would like to update using a simple html form. One of the field is "accepted" and is type "boolean". I have a texbox where I will write the record id and another button which will change the "accepted" value from 0 to 1 for that record id. The problem is that I don't know how to start.... Thanks in advance Sergio I'm having an issue updating a records. The insert and delete functions are working fine. The $submit variable is being passed 'Update' ~ that is working. This is some extremely old code that has migrated to a new server and is no longer working. Code: [Select] <?php $id = $_GET["id"]; $delete = $_GET["submit"]; $sortorder = $_POST["sortorder"]; $name = $_POST["name"]; $content = $_POST["content"]; $submit = $_POST["submit"]; require'../include/maindb.php'; if($submit=="Submit") { $sql="INSERT INTO biography (id, sortorder, name, content) VALUES (NULL, '".$sortorder."', '".nl2br(addslashes(trim($name)))."', '".htmlentities(addslashes(trim($content)))."')"; } if ($submit == "Update") { $sql="UPDATE biography SET sortorder='".$sortorder."', name='".nl2br(addslashes(trim($name)))."', content='".htmlentities(addslashes(trim($content)))."' WHERE id='".$id."'"; } if ($delete=="Delete") { $sql="DELETE FROM biography WHERE id='".$id."'"; } mysql_query($sql); echo(mysql_error()); header('Location: index.php'); ?> Anyone have any idea what I did wrong this time? This is def where my problem is Code: [Select] // UPDATE THE RECORD WITH THE CURRENT FORM DATA $edit_query_insert="UPDATE client_information SET account_number = '$account_number', name_first = '$name_first', name_last = '$name_last', address = '$address', city = '$city', state = '$state', zipcode = '$zipcode', telephone = '$telephone', telephone_alt = '$telephone_alt', email = '$email'"; This is the code for the page itself: Code: [Select] // SELECT THE DATABASE mysql_select_db("terra_elegante_operations", $con); // GET THE FORM DATA FROM PREVIOUS PAGE // ASSIGN NEW VARIABLES $account_number = $_POST['account_number']; $name_first = $_POST['name_first']; $name_last = $_POST['name_last']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zipcode = $_POST['zipcode']; $telephone = $_POST['telephone']; $telephone_alt = $_POST['telephone_alt']; $email = $_POST['email']; // UPDATE THE RECORD WITH THE CURRENT FORM DATA $edit_query_insert="UPDATE client_information SET account_number = '$account_number', name_first = '$name_first', name_last = '$name_last', address = '$address', city = '$city', state = '$state', zipcode = '$zipcode', telephone = '$telephone', telephone_alt = '$telephone_alt', email = '$email'"; if (!mysql_query($edit_query_insert,$con)) { die('Error: ' . mysql_error()); } ?> <table border="0" cellspacing="0" cellpadding="3" width="960" bordercolor="#000000"> <tr> <td valign="top" width="50%"><!-- Open Main left Cell --><table border="0" cellspacing="0" cellpadding="1" width="100%" bordercolor="#000000"><tr><td colspan="4"><B>CLIENT PROFILE</B></td></tr> <?php // Query & assign to the $client_information table. $get_client_information = "SELECT * from client_information where account_number = $account_number"; $client_information = mysql_query($get_client_information) or die (mysql_error()); // The Array & Output - Included HTML Output here for $client_information while ($row = mysql_fetch_array($client_information)) { ?> <tr> <td width="30%"><font face="verdana" size="2" color="#000000">Account Number:</font></td><td colspan="2"><font face="verdana" size="2" color="#000000"><?php echo $row['account_number']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Last Name:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['name_last']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">First Name:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['name_first']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Address:</font></td><td><font face="verdana"size="2" color="#000000"><?php echo $row['address']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">City:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['city']; ?></font></td> </tr> <tr> <td width="10%"><font face="verdana" size="2" color="#000000">State:<font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['state']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Zipcode:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['zipcode']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Telephone:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['telephone']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Telephone 2:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['telephone_alt']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">E-mail</td></td><td><font face="verdana" size="2" color="#000000"><?php echo "<a class=\"bubble_nav\" href='mailto:?id=$row[email]'>$row[email]</a\>"; } ?></font></td> </tr> </table> <?php include('includes/footer.php'); ?> Hi, I am trying to update the status of the record. I don't want to insert the record if not exists. I just want to know the update is success or not. I tried using affected_rows but it returns 0 if the existing status is same as the new status or if no record exists. Please help. Thanks for reading my post. How can I update the ten rows from MYSQL Thanks in advance Hi all, Im having some trouble trying to update my table using an array, It processes and doesnt throw up any errors so im at a loss as to whats happening as its not updating my table? my page is Code: [Select] mysql_select_db($database_saucy_connection, $saucy_connection); $query_allphotos = "SELECT * FROM model_login, model_pictures WHERE model_pictures.user_id=model_login.id"; $allphotos = mysql_query($query_allphotos, $saucy_connection) or die(mysql_error()); $row_allphotos = mysql_fetch_assoc($allphotos); $totalRows_allphotos = mysql_num_rows($allphotos); ?><!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> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center">Picture Name</td> <td align="center">Upload Date</td> <td align="center"><strong>No Downloads</strong></td> <td align="center"> Approved? </td> <td align="center"> Hunnies Gallery </td> <td align="center"> Hunks Gallery </td> <td align="center"> Default Pic </td> <td align="center"> Theme Pic </td> <td align="center"> Homepage Pic </td> </tr> <?php while($rows=mysql_fetch_array($allphotos)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><? $user_picture[]=$rows['user_picture']; ?><?php echo $rows['user_picture']; ?></td> <td align="center"><? $user_picture_date[]=$rows['user_picture_date']; ?><?php echo $rows['user_picture_date']; ?></td> <td align="center"><? $picture_downloads[]=$rows['picture_downloads']; ?><?php echo $rows['picture_downloads']; ?></td> <td align="center"><? $user_pic_approval[]=$rows['user_pic_approval']; ?><?php echo $rows['user_pic_approval']; ?> </td> <td align="center"><? $hotties_gallery[]=$rows['hotties_gallery']; ?><?php echo $rows['hotties_gallery']; ?> </td> <td align="center"><? $hunks_gallery[]=$rows['hunks_gallery']; ?><?php echo $rows['hunks_gallery']; ?> </td> <td align="center"><? $default_pic[]=$rows['default_pic']; ?><?php echo $rows['default_pic']; ?> </td> <td align="center"><? $theme_gallery[]=$rows['theme_gallery']; ?><?php echo $rows['theme_gallery']; ?> </td> <td align="center"><? $homepage=$rows['homepage_pic']; ?><?php echo $rows['homepage_pic']; ?> </td> </tr> <?php } ?> <tr> <td colspan="5" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $model_pictures SET user_pic_approval='$user_pic_approval[$i]', hotties_gallery='$hotties_gallery[$i]', hunks_gallery='$hunks_gallery[$i]', default_pic='$default_pic[$i]', theme_gallery='$theme_gallery[$i]', homepage_pic='$homepage_pic[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } Hello,
Anyone can suggest me what is the best way to update table records. I'm kinda scared to make an update on a table because it may damage the system and I am not really good on SQL commands.
Right now I just made a process on PHP to update table records. It does update email records on but it stop because of the limit of loading the page. Is there anyway accurately update all the data of the table.
Here is what I want to achieve.
I have a table with an "email" field on it, those email data from "email" field on tb_one must be change to cID records base on tb_two.
tb_one
Field =
- id
- email
- etc.
tb_two
Field =
- id
- email (same as on tb_one)
- cID
hi my db table has 2 field: ID - Place 1 France 2 Germany My form has 2 text field (printed with while cycle). mysql_query("UPDATE mytable SET Place = '" . $_POST['place'] . "' WHERE ID=". $_POST['ID']." "); This query doesn't work, because updates only the last record. Where is wrong? many thanks There are 50 csv files. each csv file have the same column's name. some content in the column are the same, some don't. eg:test1.csv, example1.csv, hello.csv, world.csv.......test70.csv. now, i want to make a change to two column's content. a, all csv files have a column named qty. whose rows content are all 0. now, i want to change it into Code: [Select] 888 b, all csv files have a column named image. whose rows content are all Code: [Select] upload/img1.jpg upload/img2.jpg upload/img3.jpg upload/img01.jpg upload/img14.jpg upload/img01.jpg .......If i open each csv file then do a search and replace. i fell it too bored. Thank you in advance. i want to delete Uploadin the image column, change 0 to 888 in the qty column. i using the file change.php to update the record. one csv file. http://phplist.xxmn.com/women.csv the code: Code: [Select] <?php $dir = getcwd(); $files = array_diff(scandir($dir), array('..', '.','change.php')); foreach ($files as $file) { if (($handle = fopen($file, "r")) !== FALSE) { $new_content = ''; while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { //var_dump($data); $data[2]=888; $new_content .= implode(',', $data); //var_dump($new_content); } file_put_contents($file, $new_content); echo 'down'; } } ?> the code doesn't work how to correct it . thank u 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"); ?> Hi there i have webpages that are viewed through an iframe on my index page. Ive just added an update form on the index page itself and on redirection it doesnt go to the page within the iframe anymore, just the page itself. Code: [Select] <iframe src="../swb/main2.php" width="80%" height="800"> </iframe> The update code is: Code: [Select] <?php $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE player SET Repair=%s WHERE PlayerName=%s", GetSQLValueString($_POST['repair'], "int"), GetSQLValueString($_POST['player'], "text")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); $updateGoTo = "repairs.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?> So maybe i can this line: $updateGoTo = "repairs.php"; to something like $updateGoTo = "repairs.php target='iframe src="../swb/repairs.php'"; Is this possible?? Thanks hi - i'm trying to update mysql databse but not working... any ideas??? Code: [Select] [php] <?php ob_start(); require_once('../xconfig.php'); if(isset ($_GET['quote'])&& $_GET['quote']!=""){ $quote_id=$_GET['quote']; mysql_select_db($database, $makeconnection); $sql_find_quote = "SELECT * FROM tbl_quote WHERE quote_id = $quote_id"; $find_quote = mysql_query($sql_find_quote, $makeconnection) or die(mysql_error()); $row = mysql_fetch_assoc($find_quote); $totalRows = mysql_num_rows($find_quote); $quote_author = $_POST['quote_author']; $quote_desc = $_POST['quote_desc']; if (isset($_POST['submitted'])&&($_POST['submitted'] == "yes")) { $register_query = "SELECT quote_desc FROM tbl_quote WHERE quote_desc='$quote_desc'"; mysql_select_db($database, $makeconnection); $register_check=mysql_query($register_query, $makeconnection); $register_found_quote = mysql_num_rows($register_check); if($register_found_quote>1){ header ("Location: quote_modify.php?error=quoteexists"e=$quote_id"); }else{ $sql_modify = "UPDATE tbl_quote SET quote_desc = '$quote_desc' quote_author = '$quote_author' WHERE quote_id = '$quote_id'"; } mysql_select_db($database, $makeconnection); $Result1 = mysql_query($sql_modify, $makeconnection) or die(mysql_error()); header ("Location: quote.php"); } } ob_flush(); ?> [/php] here's my HTML form Code: [Select] <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> <p> <input name="quote_author" type="text" class="active-field" id="quote_author" value="<? echo $row['quote_author'];?>"/> <br /> <input name="quote_desc" type="text" class="active-field" id="quote_desc" value="<? echo $row['quote_desc'];?>" /> <br /> <input name="submitted" type="hidden" id="submitted" value="yes" /> <input name="submit" type="submit" id="submit" class="submit-button" value="modiy"/> <br /> </p> </form> Hey guys, I'm just trying to add a form button to my site that updates a user's data in the mysql database. However I'm struggling trying to find a way to define which field to edit, can someone tell me if I'm along the correct lines: Page with submit button: Code: [Select] <?php $result = mysql_query("SELECT * FROM members WHERE Username='$_SESSION[Username]'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo '<b>Resources</b><br />'; echo 'Wood: ' . $row['res1'] . ' <br />'; echo 'Iron: ' . $row['res2'] . ' <br />'; echo 'Credits: ' . $row['credits'] . ' <br />'; } echo 'Offence Power: '; echo $offencepower; echo '<br />'; echo 'Defence Power: '; echo $defencepower; echo '<br />'; echo 'Total Power: '; echo $totalpower; ?> <br /><br /> <form action="update.php" method="post"> <input type="hidden" name="Memberid" value="' . $row['Memberid'] . '"> <input type="submit" name="submit" value="submit"> </form> Update.php: Code: [Select] <?php include ('config.php'); ?> <?php $Memberid = mysql_real_escape_string($_POST['Memberid']); if (isset($_POST['Memberid'])) { $query=("UPDATE members SET totalpower = '10' WHERE Memberid='$Memberid'"); mysql_query($query); echo $query; /* header('Location: ' . $_SERVER['HTTP_REFERER']);*/ } ?> When echoing the query I'm getting: Quote UPDATE members SET totalpower = '10' WHERE Memberid='\\\' . $row[\\\'Memberid\\\'] . \\\'' Thanks |