Search the Community
Showing results for tags 'update'.
-
Hey guys! First time post here and I am only a begginer in programming. Anyway I have a few questions as I am stuck and have been for quite a while. I know this is a long post but it will cover the whole entire process of what I am doing at the moment. I really appreciate the time anyone can give me and will be happy to paypal someone over some $ for any help they can give me. Firstly, I am working with a bit of javascript and PHP. I am using a javascript method to update content from my table data in mysql without reloading the page. It works very well but I want to simplify the way i do things with the javascript so I am not left with repetative lines of code. Here is my javascript: $(document).ready(function() { //Edit link action (1) $('.edit_link').click(function(){$('.text_wrapper').hide(); var data=$('.text_wrapper').html(); $('.edit').show();$('.editbox').html(data);$('.editbox').focus();}); //Edit link action (2) $('.edit_link2').click(function(){$('.text_wrapper2').hide(); var data=$('.text_wrapper2').html();$('.edit2').show(); $('.editbox2').html(data);$('.editbox2').focus();}); //Mouseup textarea false (1) $(".editbox").mouseup(function(){return false}); //Mouseup textarea false (2) $(".editbox2").mouseup(function(){return false}); //Textarea content editing (1) $(".editbox").change(function(){$('.edit').hide();var boxval = $(".editbox").val(); var dataString = 'data='+ boxval;$.ajax({type: "POST",url: "update.php",data: dataString,cache: false,success: function(html){$('.text_wrapper').html(boxval);$('.text_wrapper').show();}});}); //Textarea content editing (2) $(".editbox2").change(function(){$('.edit2').hide(); var boxval = $(".editbox2").val();var dataString = 'data2='+ boxval;$.ajax({type: "POST",url: "update.php",data: dataString,cache: false,success: function(html){$('.text_wrapper2').html(boxval);$('.text_wrapper2').show();}});}); //Textarea without editing (1) $(document).mouseup(function(){$('.edit').hide();$('.text_wrapper').show();}); //Textarea without editing (2) $(document).mouseup(function(){$('.edit2').hide();$('.text_wrapper2').show();}); }); As you can see I am having to repeat the functions and all I do is change the name. Instead of repeating the script like I am over and over again to recognise different textareas is there a way I can array it or something like this so I don't have endless lines of the same code over and over again? I have allot more then just 2 textareas but of course shortened it for this post. Here is how I UPDATE the data in MySQL. I am looking into moving this over to PDO as I have be learning that PDO is the more safe and finctional option. My question here would be is there a simple way to UPDATE the rows instead of the way I doing this by repeating this process over and over again? I know I can use the: if (isset()); but I am troubled to work out how I would define the "id" of the data I am changing? <?php include("connection.php"); if($_POST['data']) { $data=$_POST['data']; $data = mysql_escape_String($data); $sql = "update slider set content='$data' where id='1'"; mysql_query( $sql); } if($_POST['data2']) { $data2=$_POST['data2']; $data2 = mysql_escape_String($data2); $sql = "update slider set content='$data2' where id='2'"; mysql_query( $sql); } ?> The HTML is quite simple. The form is wrapped in a div and the "edit" link is defined by class which again I repeat by just copy and past, the select is done via "id" which I need to define in the UPDATE section: <a href="#" class="edit_link" title="Edit">Edit</a> <? $sql=mysql_query("select content from slider where id='1'"); $row=mysql_fetch_array($sql); $profile=$row['content']; ?> <div class="text_wrapper" style=""><?php echo $profile; ?></div> <div class="edit" style="display:none"> <textarea class="editbox" cols="23" rows="3" name="profile_box"></textarea> </div> <a href="#" class="edit_link2" title="Edit">Edit</a> <? $sql=mysql_query("select content from slider where id='2'"); $row=mysql_fetch_array($sql); $profile=$row['content']; ?> <div class="text_wrapper2" style=""><?php echo $profile; ?></div> <div class="edit2" style="display:none"> <textarea class="editbox2" cols="23" rows="3" name="profile_box"></textarea> </div> I hate asking for help but I really need some guidence here as myself and Javascript are not good friends and myself and PHP are just starting a relationship, if you know what I mean. Any examples of how to achieve this? I do beleive if anyone could put me in the right direction it would be a great script to share around as it is very functional. I apologize for such a large post, however I really am stuck and have gone this far. I have researched google but find i just keep getting stuck. Idealy I just want to simplify the whole script, make it more functional and save myself the repetative task of going over the same thing again and again.
-
i'm trying to add data into specific user in database. the one who login in the form is admin and the admin will add information to the user's database.. here's the php code <?php session_start(); if ($_SESSION['UserId'] == "") { echo "Please Login first"; } else { echo "<h1> Appliances's adding list</h1>"; echo "<table>"; echo "<form action ='addappliancesprocess.php' method = 'POST'>"; echo "<tr> <td>Appliances Name: <input type='text' name='appliancesname'></td> </tr>"; echo "<tr> <td>Port Number: <select name = 'port' value='port'> <option value 'RB0'>RB0</option> <option value 'RB1'>RB1</option> <option value 'RB2'>RB2</option> <option value 'RB3'>RB3</option> <option value 'RB4'>RB4</option> <option value 'RB5'>RB5</option> <option value 'RB6'>RB6</option> <option value 'RB7'>RB7</option> </select> </tr>"; echo "<tr> <td>Insert characters on: <input type='text' name='charon'></td> </tr>"; echo "<tr> <td>Insert characters off: <input type='text' name='charoff'></td> </tr>"; echo "<tr> <td colspan=2 align= 'right'><br> <INPUT Type='button' VALUE='Back' onClick='history.go(- 1);return true;'> <input type='submit' name='update' value='Submit'> </td> </tr>"; echo "</table>"; } ?> and here is the process <?php session_start(); $appliancesname=$_POST['appliancesname']; $port=$_POST['port']; $username=$_REQUEST['username']; $charon=$_POST['charon']; $charoff=$_POST['charoff']; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myfyp", $con); ?> <?php $query="SELECT from user where UserId = '".$_SESSION ['UserId']."'"; //if ($username != UserId) { //echo "no user"; //}else{ $sql="INSERT INTO appliances VALUES ('','$appliancesname','$port','$username','','$charon','$charoff')"; echo $query; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "You have choose the following:<br>"; echo "<br>Appliances: $appliancesname</br>"; echo "<br>Port Number: $port</br>"; echo "<br>Character on: $charon</br>"; echo "<br>Character off: $charoff</br>"; echo "<br><INPUT Type='button' VALUE='Back' onClick='history.go(- 1);return true;'>"; //} ?> when i try to add it will add to the database but the port is not updated and the userid is empty.. i'm sorry.. i am new to php.. there are lots that i don't know..
- 5 replies
-
- phpdatabase
- add
-
(and 1 more)
Tagged with:
-
Hello, I'm trying to display the results of my query in a text box so that they can be edited, if need be, and updated in the database. I'm getting the error below, with the code below. I've tried a couple of different ways to format the "value" of the text box as you can see by the second one that's commented out and still a no go. Thanks for any help in advance guys. The error below is referring to the code just below here. echo "<td><input type="text" name="firstname" value="$firstname"></td>"; Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\ $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table><tr>"; echo "<th>First Name</th>"; echo "<th>Middle Initial</th>"; echo "<th>Last Name</th>"; echo "<th>Full Name</th>"; echo "<th>Provider ID</th></tr>"; while (odbc_fetch_row($rs)) { $firstname=odbc_result($rs,"provider_first_name"); $middleinitial=odbc_result($rs,"provider_middle_name"); $lastname=odbc_result($rs,"provider_last_name"); $fullname=odbc_result($rs,"provider_full_name"); $provider_id=odbc_result($rs,"provider_id"); echo "<tr><td>$firstname</td>"; echo "<td><input type="text" name="firstname" value="$firstname"></td>"; echo "<td>$middleinitial</td>"; echo "<td>$lastname</td>"; echo "<td>$fullname</td>"; echo "<td>$provider_id</td>"; // echo "<td><input type="text" name="textfield" value='".$providerid."'"></td>"; echo "<td>$providerid</td></tr>"; } odbc_close($conn);
-
im trying to make a script where the user can update there details, (in this case the email) but when the script is running it comes up sucess to say its worked and updated. however when i open up my database in notepad or sql workbench the email has not changed its still the same. any ideas what it could be? or maybe im reading my database info wrong? CODE: <?php session_start(); $user_name = "root"; $password = ""; $database = "fixandrun"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $currentemail = $_POST['currentemail']; $newemail = $_POST['newemail']; $confirmnew = $_POST['confirmemail']; $user = $_SESSION["username"]; if ($db_found) { $dbemail =mysql_query("SELECT email FROM staff WHERE username= '$user'"); //echo "$currentemail"; //echo "$newemail"; //echo "$confirmnew"; //echo "$dbemail"; if($currentemail == $dbemail || $newemail == $confirmnew) { $query = "UPDATE staff SET email = '$confirmnew' WHERE username = '$user'"; if(mysql_query($query)){ echo "updated";} else{ echo "fail";} } else { echo" some of your details are incorrect please try again. check that your current email is entered correctly and the new email matches."; } } else { print "Database NOT Found."; mysql_close($db_handle); } ?>
-
Noob here learning PHP with a MySQL database. I know that this isn't the best way to connect to a database and I should probably be using variables as well as stored procedures. I just want to make this functional then I will go back and learn how to make it more secure. I've put a database together with 5 fields, id, author, title, date, body. id is the primary key set as autoincrement. Currently I have a page that displays each row in the database and has an option at the bottom to add a new entry. I want to add the option to edit a current entry. I've spent the last 2 hours doing trial/error and reading forums and I don't really feel like I've made any headway. My Main page <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXX", $con); $result = mysql_query("SELECT * FROM news"); echo "<table border='1'> <tr> <th>ID</th> <th>Author</th> <th>Title</th> <th>Date</th> <th>Body</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['author'] . "</td>"; echo "<td>" . $row['title'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['body'] . "</td>"; echo "<td><a href='file133.php?id=" . $row['id'] . "'>edit</a></td>"; echo "</tr>"; } echo "</table>"; echo "<form action='file132.php' method='post'> <table> <tr><td>Author:</td><td> <input type='text' name='author'></td></tr> <tr><td>Title:</td><td> <input type='text' name='title'></td></tr> <tr><td>Body:</td><td> <input type='text' name='body' size='75'></td></tr> <tr><td></td><td><input type='submit' value='Submit'></td></tr> </table> </form>"; mysql_close($con); ?> Clicking Edit takes you to this page where you can enter in the new data <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_GET['id']) AND $_GET['id'] > 0) { mysql_select_db("XXXXX", $con); echo "<form action='file134.php' method='post'> <table> <tr><td>Author:</td><td> <input type='text' name='author'></td></tr> <tr><td>Title:</td><td> <input type='text' name='title'></td></tr> <tr><td>Body:</td><td> <input type='text' name='body' size='75'></td></tr> <tr><td></td><td><input type='submit' value='Submit'></td></tr> </table> </form>"; } mysql_close($con); ?> When you click submit it goes to this page. I know this code below is all wrong because it just displays the actual code from the 0) to the end. I just need some direction on how to make this functional. <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_GET['id']) AND $_GET['id'] > 0) { mysql_select_db("XXXXX", $con); $mysql_query = "UPDATE news SET Author = '$_POST[author]', title = '$_POST[title]', date = NOW(),body = '$_POST[body]' WHERE id= $row['id'] "; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Record updated, click <a href='file130.php'>here</a> to return to the list of records."; mysql_close($con); ?>
-
Hiya i'm working on a project, which involves a list of checkboxes which are automaticly populated by the database which is currently working at while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $hotbox = $row['hot_job']; ?> <form name='hotbox' action='hot_update.php' method='POST'> <tr><td><strong><?php echo $id; ?></strong></td> <td><input name="ONOFF<? echo $row['id']; ?>" type="checkbox" id="ONOFF" value="1" <?php if ($row['hot_job'] == 'YES') { echo "checked";} else {} ?> </td></tr> <?php } ?> however when the user has unchecked/checked the correct boxes and clickes update, nothing changes. Here is my current code foreach($_POST['id'] as $id) { $onoff = 0; if (isset($_POST["ONOFF".$id])) { $onoff = 1; } if($onoff == 1) { $sql1="UPDATE jobs SET hot_job='".$onoff."' WHERE id='".$id."'"; } else { $sql1="UPDATE jobs SET hot_job='".$onoff."' WHERE id='".$id."'"; } echo $id; echo $onoff; $result1=mysql_query($sql1); } ?> The mysql setup is id hot_job 1 YES 2 YES 3 NO 4 YES ect Any help would be greatly appreciated
-
I have a data base that updates the photo 1) A error occurs everytime i update the database error:- Error in Query: 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 '\0JFIF\0\0`\0`\0\0ÿÛ\0C\0 ' at line 3 code:- $sql = "UPDATE freelancer SET image=$imgData, name='{$_FILES['image']['name']} WHERE id=$in"; here $imgData is image with slashes 2) this is the error for Error in Query: 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 ''image-04.jpg WHERE id=29' at line 3 code:- $sql = "UPDATE freelancer SET image='$imgData', name='{$_FILES['image']['name']} WHERE id=$in"; please help for the error
-
Hi guys, Say I got two tables, Table1 - columns A, B, C, flag - approx 200 000 rows Table2 - columns A, B, C - approx 20 000 rows What I want to do is: Update Table1 Set flag = 1 Where "at least one row from Table2 has the same entries in columns A, B and C" Right now I am solving this with a "select distinct A, B, C from Table2" and transform this into a long where condition (with php). afterwards I apply the above update with this where condition. However this aproche needs about 5 minutes to run and I believe this could be much faster when I just know the right MySql command for this. Can anyone help me? cheers, Peter
-
My code is working (ie updating the database) on my local site using MAMP however, it is not updating in my remote site. Can anyone understand why? I have copied my local files up to my remote and have not changed anything. The code runs through the mysql query and display the error message. The code starts going through the loop then stops at the end of the first record in the recordset and spits out the error message. I don't understand why it works okay on local and not on remote. Would it be something on the remote server side? Please help urgently. Thanks. Regards. cracker1 <?php $size = count($_POST['OrderNumber']); $i = 0; while ($i < $size) { $OrderNumber= $_POST['OrderNumber'][$i]; $OrderDate= $_POST['OrderDate'][$i]; $RequiredDate= $_POST['RequiredDate'][$i]; $fk_TrophyCode= $_POST['fk_TrophyCode'][$i]; $Customer= $_POST['Customer'][$i]; $PartCode= $_POST['PartCode'][$i]; $PartDescription= $_POST['PartDescription'][$i]; $PartQty= $_POST['PartQty'][$i]; $Freight= $_POST['Freight'][$i]; $Supplier= $_POST['Supplier'][$i]; $OrderDetailID = $_POST['OrderDetailID'][$i]; $query = "UPDATE tbl_OrderDetails SET OrderNumber = '$OrderNumber', OrderDate = '$OrderDate', RequiredDate = '$RequiredDate', fk_TrophyCode = '$fk_TrophyCode', Customer = '$Customer', PartCode = '$PartCode', PartDescription = '$PartDescription', PartQty = '$PartQty', Freight = '$Freight', Supplier = '$Supplier' WHERE OrderDetailID = '$OrderDetailID'"; mysql_query($query) or die ("Error in update query: $query"); ++$i; } ?>
-
I have a problem when i Click the Edit button int he form, the database doesn't update, In the beginning i thought i had a problem with the query, but I did a check as a query and everything was fine. Can someone suggest something please. //this is the file - album.func.php function edit_album($album_id, $album_name, $album_description) { $album_id = ((int)$album_id); $album_name = mysql_real_escape_string($album_name); $album_description = mysql_real_escape_string($album_description); mysql_query("UPDATE `albums` SET `name`='$album_name', `description`='$album_description' WHERE `album_id`='$album_id' AND `user_id`=".$_SESSION["user_id"]); } //this is the file - edit_album.php if (!empty($errors)) { foreach ($errors as $error) echo $error; }else { edit_album($album_id, $album_name, $album_description); header('Location: index.php'); exit(); }} ?> <?php $album_id = $_GET["album_id"]; $album_data = album_data($album_id, 'name', 'description'); ?> //this is the form <form action="?album_id=<?php echo $album_id; ?>" method="post"> <p>Name:</br><input type="text" name="album_name" maxlength="55" value="<?php echo $album_data["name"]; ?>"/></p> <p>Description:</br><textarea name="album_description" rows="6" cols="35" maxlength="500"><?php echo $album_data["description"]; ?>
-
My plugin is a custom export/update plugin that lets the user export his products, update the price grids, and upload the csv to change the data quicker than using the visual editor. The price grids are stored as a serialized array in the post's meta (_cp_array). To test my plugin, I uploaded a csv with data identical to that which was already in the DB. The function below informed that the Table Rates had not changed (because they hadn't!). Next, I changed ONE value in ONE row of the csv. Tested again. This time, the function informed that for the product I changed, the post meta had been updated. However, the meta is never actually updated. Looking in the DB for the meta (_cp_array), the serialized string stays the same after running my upload function multiple times, with update_post_meta returning true each time, and echoing the "updated" message. For debugging purposes, I used var_export($unserialized) to see what it outputted, and also var_export(serialize($unserialized)) to see what the data should look like when writing the serialized array/string to the DB. The var_export (serialized and not) on my plugin screen always displays the new, changed data from the csv. It gets even stranger...next I tried adding new metadata to a product that didn't have anything for that specific metadata (it was empty and the meta key didn't exist for that product). The function displays that it updated the metadata for that product. However, looking in the DB reveals that the serialized value for that product's meta (_cp_array) was very different from the data I entered! The var_export displays the correct array and serialized string, but the DB had very different keys and values! All relevant examples/info: http://pastebin.com/jYjuzg6G Why is the plugin not changing the metadata, even though the function returns true? And why, when it added new metadata, did it add incorrect metadata, even though the serialized array was correct when outputted to the screen? The below code is responsible for updating the product's _cp_array: if(update_post_meta($id, '_cp_array', $unserialized)) echo 'Table Rate Prices Updated.<br />'; else echo 'No Table Rate Change.'; var_export($unserialized); echo '<br />'; var_export(serialize($unserialized));
-
I would like to update a table or insert if a specific combination of indices do not already exist. The table is very simple. CREATE TABLE `sessProdLnk` ( `products_id` varchar(20) NOT NULL, `sessions_id` varchar(255) NOT NULL, `qty` int(6) NOT NULL, KEY `products_id` (`products_id`), KEY `sessions_id` (`sessions_id`) ENGINE=MyISAM DEFAULT CHARSET=latin1 So, I would like to search for a match between my data, and any row in sessProdLnk where both the sessions_id and products_id match. Then I would like to update any entries in qty where they match, and insert a new row for any data pairs that do not have matches. I know some of this comparison may have to be done programmatically in the php script, but I am still getting to know MYSQL and was wondering how much of the work it will do for me given these parameters.
-
I have an html form that takes a date and send it to an php script: <form action='tupdatecompletiondate.php' method='post'><input type='hidden' name='idtosubmit' value=$id><tr> <td><label>Date:</label></td> <td><input type= 'date' name= 'date' value='Select Date' id='popupDatepicker'></td> </tr><input type='submit' value='Click to Update'></form> I've got it going to this script: $id = $_POST['idtosubmit']; $date = $_POST['date']; $datetoset = date('Y-m-d', strtotime($date)); $sql = "UPDATE needs SET completiondate=$datetoset WHERE ID=$id"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } mysql_close(); Confused as to why it's not working. It takes the date, sends it to the php script, makes it into a format that is accepted by the DATE column, and then puts it in that column....well at least its supposed to.
-
I have a database class that uses PDO and it all works until i need to do an update where I increment the value What I have is a table and one of the columns is called 'counter' and I need to update this table every time a page is visited This is the function that handles all the PDO and creates the query /** * update * @param string $table A name of table to insert into * @param string $data An associative array * @param string $where the WHERE query part */ public function update($table, $data, $where) { ksort($data); $fieldDetails = NULL; foreach($data as $key=> $value) { $fieldDetails .= "`$key`=:$key,"; } $fieldDetails = rtrim($fieldDetails, ','); $sth = $this->prepare("UPDATE $table SET $fieldDetails WHERE $where"); foreach ($data as $key => $value) { $sth->bindValue(":$key", $value); } $sth->execute(); } and this is how I call the function by passing parametres to the function $board = ucwords(str_replace('-',' ',$board)); $sql = "SELECT boardid from boards WHERE boardname = :board"; $rows = $this->db->select($sql, array(':board' => $board)); $postData = array( 'counter' => 'counter+1', ); $this->db->update('topics', $postData, "`topicid` = {$topic} AND `boardid` = {$rows[0]['boardid']}"); It fails the update with this error message The counter column is of type INT
-
kaspersky detected vulnerability in my php Affected products: PHP versions earlier than 5.4.39 PHP 5.5 versions earlier than 5.5.23 PHP 5.6 versions earlier than 5.6.7 mine is i guess 5.3 bcz it's in c:\program files (x86)\IIS Express\v5.3\php.exe Solution: Update to the latest version: http://php.net/downloads.php so what am i exactly supposed to do ? can i remove the 5.3 version and install latest 5.6.8? how do i remove 5.3. and how do i install 5.6.8 ? just delete the v5.3 folder and replace it ? which file from http://php.net/downloads.php do i download ? or do i download from http://windows.php.net/download#php-5.6 ? also which one ? i'm on windows 7 using microsoft webmatrix 3 and visual studio express 2013 for web.