PHP - Update Form/function Not Working. Can't Figure Out Why
I've tried a few different methods, but I can't get this damn function to work. Can someone show me where I've gone wrong?
Here's my code & form. I'm still baffled why it doesn't work! :lol: url is update-content.php?id=12 <?php include("../include/session.php"); if(!$session->logged_in) { header('Location: ../login.php'); die; } require_once('../include/functions.php'); function content($id) { $id = $_GET['id']; $connection = db_connect(); $query = sprintf("select * from content where id = '$id'", mysql_real_escape_string($id) ); $result = mysql_query($query); $number_of_posts = mysql_num_rows($result); if ($number_of_posts == 0) { return false; } $row = mysql_fetch_array($result); return $row; } function update($param) { // Get the content id from url to output into the editor $id = $_GET['id']; $connect = db_connect(); $page = mysql_real_escape_string($_POST['page']); $page_id = mysql_real_escape_string($_POST['page_id']); $title = mysql_real_escape_string($_POST['title']); $text = mysql_real_escape_string($_POST['text']); $query = ("UPDATE content SET page = '$page' page_id = '$page_id' title = '$title' text = '$text' WHERE id = '$id' "); $result = mysql_query($query); if (!$result) { return false; } else { return true; } } ?> <?php // Send form data to mysql if(isset($_POST['text'])) { $result = update($_POST); if($result === true) { echo 'Success!'; die(); } } ?> And the form.. <form form name="editor" id="editor" method="post" action="update-content.php"> <p><br /> <b>Assign to page</b><br /> <input name="page" id="page" size="60" maxlength="500" value="<?php $page = content($id); echo stripslashes($page['page']); ?>" /> <br /> <br /> <b>Page id</b> <input name="page_id" id="page_id" size="4" maxlength="4" value="<?php $page_id = content($id); echo stripslashes($page_id['page_id']); ?>" /> <br /> <br /> <b>Title</b> <span class="smalltext">(Just a short name this piece of content)</span><br /> <input name="title" id="title" size="60" maxlength="200" value="<?php $title = content($id); echo stripslashes($title['title']); ?>" /> <br /> <br /> <br /> <strong>Content</strong> <span class="smalltext">(paste html in here)</span><br /> <textarea name="text" id="text" cols="75" rows="15"><?php $text = content($id); echo stripslashes($text['text']); ?></textarea> <?php //turn the text area into CK Editor echo $ckeditor_ini; ?> <br /> <input type="image" src="../images/button_submit.gif" alt="submit" name="submit" value="submit" /> <a href="index.php"><img src="../images/button_cancel.gif" alt="Cancel" width="120" height="26" border="0" /> </form> Similar TutorialsI am trying to create a CMS management website, but I can't seem to get the update function to work. Everything else works fine but not the update function. Can anyone please tell me why or what the problem is? I have spent too long trying to fix it and have failed. It is correctly linked to the database when I hit the edit button all i get is UPDATE_CONTENT_FORM($_GET['ID'])?>where the text boxes should be is . Please help, I am really stuck. (sorry about spelling ) code in CMS_Class.php Class modernCMS{ var $host='localhost'; var $username='lmcmanus13'; var $password='k0gl0zfh3g1ccm4v'; var $db='lmcmanus13'; function connect(){ $con = mysql_connect($this->host, $this->username, $this->password); mysql_select_db($this->db,$con); } function get_content($id =''){ if ($id != ""): $id = mysql_real_escape_string($id);//helps to protect database from beening hacked $sql = "SELECT * FROM `CMS_Content` WHERE id ='$id'"; else: $sql = 'SELECT * FROM `CMS_Content` WHERE 1'; endif; //$query = 'SELECT * FROM `CMS_Content` WHERE 1'; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result)!=0): while($row= mysql_fetch_assoc($result)){ echo '<h1><a href="Animals.php?id=' . $row['id'] . '">' . $row['Title'] . '</h1>'; echo '<p>' . $row['Body'] . '</p>'; } else: echo '<p> we are sorry there seems to be a problem with your request</p>'; endif; echo $return='<p><a href ="Animals.php">Back</a></p>'; } function add_content($_POST){ $Title= mysql_real_escape_string($_POST['Title']); $Body= mysql_real_escape_string($_POST['Body']); if(! $Title || ! $Body): if(!$Title=""): echo"<p>The Title is required<p>"; endif; if(!$Body=""): echo"<p>The Body is required<p>"; echo '<a href="add-content.php">Try Again</a>'; endif; else: $sql="INSERT INTO `CMS_Content`(`id`, `Title`, `Body`) VALUES ('null','$_POST[Title]','$_POST[Body]')"; $result = mysql_query($sql) or die(mysql_error()); echo "<meta http-equiv='refresh' content='0;url=added.php'>"; endif; } function manage_content (){ echo '<div id ="manage">'; $sql = 'SELECT * FROM `CMS_Content`'; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)): echo '<h1><a id=' . $row['id'] . '">' . $row['Title'] . '</h1>' ?> <div> <span ><a href="update-content.php?id=<?php= echo= $row['id']?>">Edit</a>|<a href="?delete=<?php echo $row['id']; ?>">Delete</a></a></span> </div> <?php endwhile; echo '</div>';//closes the manages div } Function delete_content($id){ if(!$id){ return false; }else{ $id=mysql_real_escape_string($id); $sql="DELETE FROM CMS_Content WHERE id='$id'"; $result = mysql_query($sql) or die(mysql_error()); echo "<meta http-equiv='refresh' content='0;url=deleted.php'>"; } function update_content_form($id) { $id = mysql_real_escape_string($id); $sql = "SELECT * FROM CMS_Content WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res) ?> <form action="Animals.php" method="post" > <input type="hidden" name="update" value="true" /> <input type="hidden" name="id" value="<?php=$row['id']?>" /> <div> <label for="title">Title:</label> <input type="text" name="Title" id="Title" value="<?php=$row['Title']?>" /> </div> <div> <label for="body">Body:</label> <textarea name="body" id="body" rows="8" cols="40"><?php=$row['Body']?></textarea> </div> <input type="submit" name="submit" value="Update content" /> </form> <?php function update_content($p) { $title = mysql_real_escape_string($s['title']); $body = mysql_real_escape_string($s['body']); $id = mysql_real_escape_string($p['id']); if(!$title | !$body): if(!$title): echo "<p>The Title is Required</p>"; endif; if(!$body): echo "<p>The body is Required</p>"; endif; echo '<p><a href=" update_content.php?id=' . $id . '">Try Again</a></p>'; else: $sql = "UPDATE CMS_Content SET title = '$title', body = '$body' WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Updated Successfully!"; endif; } } }//end of class } ?>code in Animals.php <h1> Our Animals </h1> <ul> <li><a href="manage-content.php">Manage Content</a></li> <li><a href="add-content.php">Add Content</a></li> </ul> <?php if(isset($_POST['add'])): $obj->add_content($_POST); elseif(isset($_POST['update'])): $obj->update_content_form($_POST); endif; ?> Code in update-content.php <h1> Our Animals j,j</h1> <h1> Update Content </h1> <?=$obj->update_content_form($_GET['id']) ?> Edited by Ch0cu3r, 10 December 2014 - 11:47 AM. Added code tags Hi, i have a user update function in my code so I can easily change user fields int he database public function updateUser ($username, $value, $what) { $q = "UPDATE `users` SET ? = ? WHERE username = ?"; if ($stmt = $this->db_connection->prepare($q)) { $stmt->bind_param("sis", $what, $value, $username); $stmt->execute(); } } The database is connected successfully, but say i run a updateUser('blaine0002', 'blah', 'password'); nothing would get updated and no errors are thrown. Am i doing something wrong? Thank you! The table is: next next_id id 0 2 1 1 3 2 0 4 3 0 1 4 The form: <?php include 'dbc.php'; page_protect(); if(!checkAdmin()) { header("Location: login.php"); exit(); } if($_POST['doSubmit'] == 'Create') { list($next_id) = mysql_fetch_row(mysql_query("select next_id from users where id='$id'")); mysql_query("update users set approved='1' where id='$id'"); mysql_query("update users set next='1' where id='$next_id'"); mysql_query("update users set next='0' where id='$id'"); list($to_email) = mysql_fetch_row(mysql_query("select user_email from users where id='$id'")); $ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str']; header("Location: $ret"); exit(); $message = "Hello \n "; @mail($to_email, "Aaaaack", $message, "From: \"Lobo\" <auto-reply@$host>\r\n" . "X-Mailer: PHP/" . phpversion()); } ?> Code: [Select] <html> <body> <table width="80%" border="0" cellpadding="5" cellspacing="2" class="myaccount"> <tr> <td>i<form name="form1" method="post" action="form.php"> <input name="doSubmit" type="submit" id="doSubmit" value="Create"> </p> </form> </td> </tr> </table> </body></html> I am sorry if this is posted in the wrong place! Here to learn. Thank you for any clues! Ok, so there are two functions, one encrypts data, the other one must decrypt. But I do not know how to implement it to decrypt. I need to know how to use the second function (number_decrypt). I need it so I enter the encrypted string into a text field and it outputs the decypted string. I dont need the html, I just dont understand how to implement it. Can someone look at this for me and possibly tell me how I could achieve this? Heres the code: function number_encrypt($plain) { mt_srand ((double) microtime() * 1000000); $password = ''; for ($i=0; $i<10; $i++) { $password .= rand(1,1000); } $salt = substr(md5($password), 0, 2); $password = md5($salt . $plain) . ':' . $salt; return $password; } function number_decrypt($encrypted,$plain) { $stack = explode(':', $encrypted); if (sizeof($stack) != 2) return false; if (md5($stack[1] . $plain) == $stack[0]) { return true; } return false; } Thanks! Can anyone post a generic update function to update mysql table. The manual approach: update $tablename set $column1='a', $column2='b' where $id=$value; hello all, i can't get this to work; i'm able to echo both accts entered into the form via the _get but can't pull both balances using the $from_acct and $to_acct only the first query working do I have it formated wrong <?php //check for submit $submit = $_GET['submit']; //end looking for submit //set varibles if submit is present if (!$submit) { echo "Sorry Mate I don't see you have submitted anything for me to process"; } else { //make the connecting and set some varibles from _get $from_acct = $_GET['from_acct']; $to_acct = $_GET['to_acct']; $amount = $_GET['amount']; $connect = mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db('users') or die ("no such database exisit"); $query = mysql_query("SELECT * from members WHERE bankaccount=$from_acct") or die ("Could not locate to account"); $query2 = mysql_query("SELECT * from members WHERE bankaccount=$to_acct") or die ("Could not locate to account"); while ($result = mysql_fetch_assoc($query) && $result2 = mysql_fetch_assoc($query2)) { $fromb = $result['balance']; $tob = $result2['balance']; } //make a check to see if the account that is sending has the money to send if ($fromb<$amount) { echo "Mate you don't have enough cash to transfer " .$amount. "to this account<br />"; echo "Your Current Balance available for transfer is " .$fromb; } else { $newbalancefrom = $fromb - $amount; $newbalanceto = $tob + $amount; //make the transfer $transfer = mysql_query("UPDATE 'users' . 'members' SET 'balance' = '$newblanceto' WHERE bankaccount='$to_acct'") or die ("could not write to profile"); $transfer2 = mysql_query("UPDATE 'users' . 'members' SET 'balance' = '$newblancefrom' WHERE bankaccount='$from_acct'") or die ("Could Not Write to From Account"); if ($transfer) { echo "Transfer Complete Thanks!"; } else { echo "There was a error in the transfer process please try again"; } } } echo $fromb . "<br />"; echo $tob . "<br />"; echo $from_acct . "<br />"; echo $to_acct . "<br />"; ?> <h2>Peer to Peer Transfer</h2><br><br> <form action="testtrans.php" method="get"> Amount to Transfer: <input type="text" size="8" name="amount"><br> From Account: <input type="text" size="15" name="from_acct"> To Account: <input type="text" size="15" name="to_acct" /><br /> <input type="submit" name="submit" value="transfer" /> </form> I have a link echo '<p>View All Items listed for <a href="item.php?mem-items='.$mem_id.'">"'.$name.'"</a></p>'; That goes to a file http://localhost/folder/item.php?mem-items=26 with 26 being an actual member id number I use the GET function like this if (isset($_GET['mem-items']) && is_numeric($_GET['$mem-items'])) { $mem_items = $_GET['mem-items']; } My problem is $mem_items isn't assigned a variable, but when I take the "is_numeric($_GET['$mem-items'])" out, it works like a charm. I use this same format on the same file for "if (isset($_GET['item']) && is_numeric($_GET['item']))" AND it works great. Can anyone see what's wrong. Thanks Hi guys Probably a simple but trying to figure out why I cant get this while loop to work (at least I think its the loop) Query works as it returns 1 row, but not all of them. Any help would be great! $sql = "SELECT * FROM requests ORDER BY leave_after DESC"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo '<div id="resultholder">'; echo "<p>Request ID:" . $row['id'] . ", User ID: " . $row['user_id'] . ", Departing From: " . $row['departing'] . ", Going To: " . $row['destination'] . " , Leaving After: " . $row['leave_after'] . " , but Arriving Befo " . $row['arrive_before'] ."</p></div>"; echo '</div>'; } } } Thanks! if ($template->load($maintemplatefile,$values)) { //load every php file in the plugin folder //Handle invalid page Requests } else { echo '404 File Not Found'; //exit; } //print page code echo $template->html(); } I call the above code it prints out the template file but it does not recursively replace the <TEMPLATE_LOADTEMPLATE_$1> that is in the file even though it properly parses both the $tag and $value variables going to the $this->replace($tag,$value); line. Any idea why this does not work? <?php class Template { var $code=''; function load($file,$values) { if (file_exists($file)) { //get template directory $dir=substr($file,0,strrpos($file,'/')) . '/'; //get template $this->code=file_get_contents($file); //check if any recurseve templates to add $tags=$this->tags(); //process all internal template tags $newValues=array_slice($values,1); foreach ($tags as $tag) { //handle inserting new template file if (substr($tag,0,13)=='LOADTEMPLATE_') { $file=substr($tag,13); if ($file[0]=='$') { $file=$values[(substr($file,1)-1)]; } $temp=new Template; $filename=$dir . $file . '.xhtml'; if ($temp->load($filename,$newValues)) { $value=$temp->html(); } else { $value='File Not Found'; } $this->replace($tag,$value); } } return true; } else { return false; } } function tags() { preg_match_all('/<TEMPLATE_[^<]+?>/', $this->code, $tags); $tags=$tags[0]; foreach ($tags as $key=>$value) { $tags[$key]=substr($value,10,-1); } return array_unique($tags); } function replace($tag,$value) { $this->code = ereg_replace('<TEMPLATE_' . $tag . '>',$value . '',$this->code); } function replaceSection($tag,$value) { $replace='~<TEMPLATE_' . $tag . '>[\s\S]*?</TEMPLATE_' . $tag . '>~'; $this->code = preg_replace($replace,$value . '',$this->code); } function compress() { $this->code = ereg_replace("\n",'',$this->code); $this->code = ereg_replace(" ",' ',$this->code); $this->code = ereg_replace("\r",'',$this->code); } function html() { //remove <TEMPLATE_*> & </TEMPLATE_*> tags then return html. return preg_replace('/(<\/?)TEMPLATE_[^<]+?>/','',$this->code); } } ?> All code listed is available for use under GNU public license. Wordpress gave me the following error when uploading the this themeforest theme. failed opening '/srv/htdocs/wp-content/themes/QuickFixWebiste(Wordpress)/../../../wp-admin/includes/class-walker-nav-menu-edit.php' for inclusion (include_path='.:/usr/local/php7.2/lib/php') in /srv/htdocs/wp-content/themes/QuickFixWebiste(Wordpress)/library/core/admin/edit-menu-walker.php Can anyone tell me how to resolve this? The source code in the edit-menu-walker.php on lines 1-4 is: <?php if (!class_exists('Walker_Nav_Menu_Edit')){ include_once(get_template_directory() . '/../../../wp-admin/includes/class-walker-nav-menu-edit.php'); }
Hi Guys, I want my UPDATE function from the code below to only update those fields that are NOT empty - if they are empty on submit then do not update or change any values from that field. I know that sounds odd, but with my file fields, when I submit to change something else at a later date it will overwrite the photo, download1,2 & 3 values and as a result I loose my files from the mysql table. Cheers, S <?php include('config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; if (isset($_POST['submitted'])) { //Photo & Document Upload Upload $timestamp_photo = time(); $timestamp_download1 = time(); $timestamp_download2 = time(); $timestamp_download3 = time(); //This is the directory where the files will be saved //Photos $photo_target = "images/"; $photo_target = $photo_target .$timestamp_photo. basename( $_FILES['photo']['name']); //Documents $download_target = "documents/"; $download_target1 = $download_target .$timestamp_download1. basename( $_FILES['download1']['name']); $download_target2 = $download_target .$timestamp_download2. basename( $_FILES['download2']['name']); $download_target3 = $download_target .$timestamp_download3. basename( $_FILES['download3']['name']); //This gets all the other information from the form $photo = ($_FILES['photo']['name']); $download1 = ($_FILES['download1']['name']); $download2 = ($_FILES['download2']['name']); $download3 = ($_FILES['download3']['name']); //Pause Photo/Document Upload foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql= "UPDATE `ter` SET `Ter` = '{$_POST['Ter']}' , `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' , `Theme` = '{$_POST['Theme']}' , `LocalInfo` = '{$_POST['LocalInfo']}' , `BranchInfo` = '{$_POST['BranchInfo']}' , `photo` = '$timestamp_photo{$_FILES['photo']['name']}' , `download1` = '$timestamp_download1{$_FILES['download1']['name']}' , `download1name` = '{$_POST['download1name']}' , `download2` = '$timestamp_download2{$_FILES['download2']['name']}' , `download2name` = '{$_POST['download2name']}' , `download3` = '$timestamp_download3{$_FILES['download3']['name']}' , `download3name` = '{$_POST['download3name']}' WHERE `Ter` = '$ter' "; mysql_query($sql) or die(mysql_error()); //Unpause Photo/Document Upload //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $photo_target)) { echo "<br />The file ".$timestamp_photo. basename( $_FILES['photo']['name']). " has been uploaded. <br />"; } else { echo ""; } //End of Photo/Document Upload //Writes the photo to the server if(move_uploaded_file($_FILES['download1']['tmp_name'], $download_target1)) { echo "<br />The file ".$timestamp_download1. basename( $_FILES['download1']['name']). " has been uploaded. <br />"; } else { echo ""; } //End of Photo/Document Upload //Writes the photo to the server if(move_uploaded_file($_FILES['download2']['tmp_name'], $download_target2)) { echo "<br />The file ".$timestamp_download2. basename( $_FILES['download2']['name']). " has been uploaded. <br />"; } else { echo ""; } //End of Photo/Document Upload //Writes the photo to the server if(move_uploaded_file($_FILES['download3']['tmp_name'], $download_target3)) { echo "<br />The file ".$timestamp_download3. basename( $_FILES['download3']['name']). " has been uploaded. <br />"; } else { echo ""; } //End of Photo/Document Upload echo (mysql_affected_rows()) ? "<br />Edited Branch.<br />" : "<br />Nothing changed. <br />"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); ?> Hi 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 When I echo the POST, it echoes the correct value. The MySQL portion seems to just ignore it all together. I've tried changing the dropdown option to just a text field, same thing occurred. I have text fields right above this particular one that update just fine with the SAME exactly scripting. if POST, update query, done. Works. This one for some reason will not. MySQL portion: if ($_POST['bUpdate']){ mysql_query("UPDATE `Patients` SET `b` = '$_POST[bUpdate]' WHERE `id` = '".$_GET['id']."'"); } echo $_POST['bUpdate']; Form Portion: Code: [Select] <tr onmouseover="color(this, '#baecff');" onmouseout="uncolor(this);"> <td width="310" colspan="2" align="center"><span class="fontoptions">Postcard Status </span><br /> <? if ($data['b'] == 1){ echo '<select name="bUpdate"><option value="1" selected>Yes</option><option value="0">No</option></select>'; } else { echo '<select name="bUpdate"><option value="1">Yes</option><option value="0" selected>No</option></select>'; } ?> </td> </tr> I have a form-to-email that I am trying to use. I'm testing, but I am not getting the orders that I send. Everything else I send to that email I get fine, so something definately wrong with my code somewhere. Thought I was ok (as a beginner) with PHP, but now my ego is taking a beating It is contained all on 1 page - the below coding is the entire page: Code: [Select] <?php if(isset($_POST['t1'])){ // **** CHANGE EMAIL, AFFILIATE ID & AFFILIATE LINK! **** $mymail = 'rjmatthews15@cfl.rr.com'; $cc = 'Website installation (plus124)'; $BoDy = ' '; $FrOm = "From: $_POST[t2]"; $FrOm .= "\r\nReply-To: $_POST[t2]"; $FrOm .= "\r\nX-MAILER: PHP".phpversion(); //Body sends all the sign up info to the $mymail address $BoDy .= 'Website Chosen: '; $BoDy .= $_POST['t1']; $BoDy .= "\n"; $BoDy .= 'eMail Address: '; $BoDy .= $_POST['t2']; $BoDy .= "\n"; $BoDy .= 'Confirm eMail: '; $BoDy .= $_POST['t3']; $BoDy .= "\n"; $BoDy .= 'Hosting Info: '; $BoDy .= $_POST['t4']; $BoDy .= "\n"; $BoDy .= 'Hosting Password: '; $BoDy .= $_POST['t5']; $BoDy .= "\n"; $BoDy .= 'Sign Up Method: '; $BoDy .= $_POST['t6']; $BoDy .= "\n"; $send = mail("$mymail", "$cc", "$BoDy", "$FrOm"); ///Redirect user to your homepage.... if($send) { echo '<html><head>'; echo '<meta http-equiv="refresh" content="0;URL=http://www.affiliscripts.com/124-thanks.php">'; echo '</head><body>Email send....'; echo '</body></html>'; } }else{ ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link href="style.css" rel="stylesheet" type="text/css" /> <link href="layout.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jquery.js"></script> <script> function toggle1(id){ if(id == 1){$('#method1').slideDown('slow'); $('#method2').slideUp('slow'); } if(id == 2){$('#method2').slideDown('slow'); $('#method1').slideUp('slow'); } } </script> </head> **** ALL BODY COING HERE <?php include 'footer.php'; ?> <?php } ?> If anyone can see what I am doing wrong, I would LOVE it if you could let me know. I am sure it's something stupid... but I've looked at this coding for 2 days now and can't find a thing! Thanks, Rob 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? Anyone have any idea why this is not wokring? if ($_POST[partsyes] == 'yes'){ $sql10="insert into tbl_partsordered (col_ticketid, col_price, col_orderedfrom, col_part, col_date) values ($_SESSION[ticketid], '$_POST[pprice]', '$_POST[pfrom]', '$_POST[part]', CURDATE( ))"; $result10=mysql_query($sql10) or die ('Error: '.mysql_error ()); //get tech comments so we can add our parts ordered to them. $sql11="SELECT col_techcomments FROM tbl_ticket where id = $_SESSION[ticketid]"; $result11=mysql_query($sql11) or die ('Error: '.mysql_error ()); while($row11 = mysql_fetch_array($result11)) { $newtechcomments = $row11[col_techcomments] . " " . "Ordered Parts" . " " .$_POST[part] . " " .$_POST[pprice] . " " . "From:" .$_POST[pfrom] . " ". $today; $sql12="update tbl_ticket set col_techcomments='$newtechcomments' where id = $_POST[ticketid]"; $result12=mysql_query($sql12) or die ('Error: '.mysql_error ()); } } The first query pull data out of the database. then concatenates that string with other strings. The update query never runs? If I add echo $sql2; and copy the sql that is displayed on the screen and paste it into phpadmin it updates just fine. I tried putting a typo in on the query just to see if it failed. It does. so I know its running the query This is driving me nuts. I know it's gotta be a typo somewhere. Also don't make fun of my code.. I know It's gotta be bad. Hello all, I have tried the following syntax to update a record from the $_POST method, and I cannot get it to update the record. Can anyone spot where I'm going wrong in my code Code: [Select] <?php $idstudent = $_POST["idstudent"]; $childname = $_POST["childname"]; $parentname = $_POST["parentname"]; $dated = $_POST["dated"]; $datem = $_POST["datem"]; $datey = $_POST["datey"]; $dob = $datey ."-". $datem ."-".$dated; $age = $_POST["age"]; $lastupdate = date("Y\-m\-d"); $gender = $_POST["gender"]; $address1 = $_POST["address1"]; $address2= $_POST["address2"]; $city = $_POST["city"]; $postcode = $_POST["postcode"]; $phone = $_POST["phone"]; $mobile = $_POST["mobile"]; $email = $_POST["email"]; $pass= $_POST["password"]; $height = $_POST["height"]; $neck = $_POST["neck"]; $chest = $_POST["chest"]; $hips = $_POST["hips"]; $waist = $_POST["waist"]; $insideleg = $_POST["insideleg"]; $dress = $_POST["dress"]; $shoe = $_POST["shoes"]; $haircolour = $_POST["haircolour"]; $hairlength = $_POST["hairstyle"]; $eyes = $_POST["eyecolour"]; $ethnicity = $_POST["ethnicity"]; $image = $_POST["image"]; $approve = "0"; $actor = $_POST["actor"]; $standin = $_POST["standin"]; $voiceover = $_POST["voiceover"]; $stagecombat = $_POST["stagecombat"]; $daballet = $_POST["daballet"]; $dasalsa = $_POST["dasalsa"]; $dabreak = $_POST["dabreak"]; $dadisco = $_POST["dadisco"]; $dahiphop = $_POST["dahiphop"]; $dajazz = $_POST["dajazz"]; $damodern = $_POST["damodern"]; $dastreet = $_POST["dastreet"]; $datap = $_POST["datap"]; $dacontemp = $_POST["dacontemp"]; $dafreestyle = $_POST["dafreestyle"]; $daswing = $_POST["daswing"]; $dawaltz = $_POST["dawaltz"]; include ('../../source/db_config.php'); $db = mysql_connect($host,$username,$password) or die(mysql_error()); mysql_select_db($database, $db) or die(mysql_error()); $update = "UPDATE 'students' SET 'childname'='$childname', 'parentname'='$parentname', 'dob'='$dob', 'age'='$age', 'lastupdate'='$lastupdate', 'gender'='$gender', 'address1'='$address1', 'address2'='$address2', 'city'='$city', 'postcode'='$postcode', 'phone'='$phone', 'mobile'='$mobile', 'email'='$email', 'password'='$pass', 'height'='$height', 'neck'='$neck', 'chest'='$chest', 'hips'='$hips', 'waist'='$waist', 'insideleg'='$insideleg', 'dress'='$dress', 'shoe'='$shoe', 'haircolour'='$haircolour', 'hairlength'='$hairlength', 'eyes'='$eyes', 'ethnicity'='$ethnicity', 'actor'='$actor', 'standin'='$standin', 'stagecombat'='$stagecombat', 'daballet'='$daballet', 'dasalsa'='$dasalsa', 'dabreak'='$dabreak', 'dadisco'='$dadisco', 'dahiphop'='$dahiphop', 'dajazz'='$dajazz', 'damodern'='$damodern', 'dastreet'='$dastreet', 'datap'='$datap', 'dacontemp'='$dacontemp', 'dafreestyle'='$dafreestyle', 'daswing'='$daswing', 'dawaltz'='$dawaltz' WHERE 'id'='$idstudent'"; mysql_query($update); ?> Don't worry about the password either.. it is passed through md5 encryption. But any help will be greatly appreciated Hey guys been asking a bunch of my friends that know some php to try and help me with this issue im having with no success .. so i come here hoping to get answers i need.
The delete function works but add and update dont work.
<?php session_start(); require 'approve.php'; ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Contacts</title> <!-- Include jQuery --> <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script> <style type='text/css'> body { background-color: #333; color: #999; font: 12px/1.4em Arial,sans-serif; } #wrap { margin: 10px auto; background: #666; padding: 10px; width: 1024px; } #header { background-color: #666; color: #FFF; } #logo { font-size: 30px; line-height: 40px; padding: 5px; } #navWrap { height: 30px; } #nav { padding: 5px; background: #999; } #nav ul { margin: 0; padding: 0; } #nav li { float: left; padding: 3px 8px; background-color: #FFF; margin: 0 10px 0 0; color: #F00; list-style-type: none; } #nav li a { color: #F00; text-decoration: none; } #nav li a:hover { text-decoration: underline; } br.clearLeft { clear: left; }​ </style> <script type='text/javascript'> //<![CDATA[ $(function() { // Stick the #nav to the top of the window var nav = $('#nav'); var navHomeY = nav.offset().top; var isFixed = false; var $w = $(window); $w.scroll(function() { var scrollTop = $w.scrollTop(); var shouldBeFixed = scrollTop > navHomeY; if (shouldBeFixed && !isFixed) { nav.css({ position: 'fixed', top: 0, left: nav.offset().left, width: nav.width() }); isFixed = true; } else if (!shouldBeFixed && isFixed) { nav.css({ position: 'static' }); isFixed = false; } }); }); //]]> </script> </head> <body> <div id="wrap"> <!-- The header code, including the menu --> <div id="header"> <div id="logo">Contacts<br /></div> <div id="navWrap"> <div id="nav"> <ul> <li><a href="#" class="smoothScroll"><a href="export.php">Export Contacts</a></a></li> </ul> <br class="clearLeft" /> </div> </div> </div> <?php $separate = ''; ini_set('display_errors', 'On'); ini_set("xdebug.var_display_max_depth", -1); ini_set("xdebug.var_display_max_children", -1); ini_set("xdebug.var_display_max_data", -1); $con = mysql_connect("66.150.xxx.xxx","contact","xxx"); if (!$con){ die("Can not connect: " . mysql_error()); } mysql_select_db("zadmin_contact",$con); if (isset($_POST['update'])){ $UpdateQuery = "UPDATE contact SET ID='$_POST[id]',Title='$_POST[title], First Name='$_POST[firstname]', Last Name='$_POST[lastname]', Company='$_POST[company]', Job Title='$_POST[jobtitle]', Business Phone='$_POST[businessphone]',Home Fax='$_POST[homefax]', Home Phone='$_POST[homephone]', Mobile Phone='$_POST[mobilephone]', E-mail Address='$_POST[email]' WHERE Name='$_POST[hidden]'"; mysql_query($UpdateQuery, $con); }; if (isset($_POST['delete'])){ $DeleteQuery = "DELETE FROM contact WHERE ID='$_POST[hidden]'"; mysql_query($DeleteQuery, $con); }; if (isset($_POST['add'])){ $AddQuery = "INSERT INTO contact (ID, Title, First Name, Last Name, Company, Job Title, Business Phone, Home Fax, Home Phone, Mobile Phone, E-mail Address) VALUES ('$_POST[uid]','$_POST[utitle]', '$_POST[ufirstname]', '$_POST[ulastname]', '$_POST[ucompany]', '$_POST[ujobtitle]', '$_POST[ubusinessphone]', '$_POST[uhomefax]', '$_POST[uhomephone]', '$_POST[umobilephone]', '$_POST[uemail]')"; mysql_query($AddQuery, $con); }; $sql = "SELECT * FROM contact"; $myData = mysql_query($sql,$con); echo "<table border=1 bgcolor=#FFFFFF align=center> <tr> <th>ID</th> <th>Title</th> <th>First Name</th> <th>Last Name</th> <th>Company</th> <th>Job Title</th> <th>Business Phone</th> <th>Home Fax</th> <th>Home Phone</th> <th>Mobile Phone</th> <th>E-mail Address</th> </tr>"; while ($record = mysql_fetch_array($myData)) { echo "<form action=\"dashboard.php\" method=\"post\">"; echo "<tr>"; echo "<td>" . "<input type=\"text\" name=\"id\" value=\"" . $record['ID'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"title\" value=\"" . $record['Title'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"firstname\" value=\"" . $record['First Name'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"lastname\" value=\"" . $record['Last Name'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"company\" value=\"" . $record['Company'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"jobtitle\" value=\"" . $record['Job Title'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"businessphone\" value=\"" . $record['Business Phone'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"homefax\" value=\"" . $record['Home Fax'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"homephone\" value=\"" . $record['Home Phone'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"mobilephone\" value=\"" . $record['Mobile Phone'] . "\"> </td>"; echo "<td>" . "<input type=\"text\" name=\"email\" value=\"" . $record['E-mail Address'] . "\"> </td>"; echo "<input type=\"hidden\" name=\"hidden\" value=\"" . $record ['ID'] . "\">"; echo "<td>" . "<input type=\"submit\" name=\"update\" value=\"update\"> </td>"; echo "<td>" . "<input type=\"submit\" name=\"delete\" value=\"delete\"> </td>"; echo "</tr>"; echo "</form>"; } echo "<form action=\"dashboard.php\" method=\"post\">"; echo "<tr>"; echo "<td><input type=\"text\" placeholder=\"ID\" name=\"uid\"></td>"; echo "<td><input type=\"text\" placeholder=\"Title\" name=\"utitle\"></td>"; echo "<td><input type=\"text\" placeholder=\"Fist Name\" name=\"ufirstname\"></td>"; echo "<td><input type=\"text\" placeholder=\"Last Name\" name=\"ulastname\"></td>"; echo "<td><input type=\"text\" placeholder=\"Company\" name=\"ucompany\"></td>"; echo "<td><input type=\"text\" placeholder=\"Job Title\" name=\"ujobtitle\"></td>"; echo "<td><input type=\"text\" placeholder=\"Business Phone\" name=\"ubusinessphone\"></td>"; echo "<td><input type=\"text\" placeholder=\"Home Fax\" name=\"uhomefax\"></td>"; echo "<td><input type=\"text\" placeholder=\"Home Phone\" name=\"uhomephone\"></td>"; echo "<td><input type=\"text\" placeholder=\"Mobile Phone\" name=\"umobilephone\"></td>"; echo "<td><input type=\"text\" placeholder=\"E-mail Address\" name=\"uemail\"></td>"; echo "<td>" . "<input type=\"submit\" name=\"add\" value=\"add\"></td>"; echo "</form>"; echo "</table>"; mysql_close($con); ?> <p>Copyright © <?php echo date("Y"); ?> Kuro. All rights reserved.</p> Edited by syntax556, 15 July 2014 - 08:04 AM. I would like to edit a record that I already have in my database but my query is not working for some reason. Hope someone can help. The errors i get are Notice: Undefined variable: first_name in C:\chemicaluser\www\editinfo.php on line 40 Notice: Undefined variable: last_name in C:\chemicaluser\www\editinfo.php on line 40 Notice: Undefined variable: log_number in C:\chemicaluser\www\editinfo.php on line 40 .... line 40 = my query $query = "UPDATE table1 SET first_name = '$first_name', last_name = '$last_name' WHERE log_number = '$log_number' "; Very simple database, 1 table w/ 2 fields table name = table1 fields = first_name, last_name my php file Code: [Select] <?php require ('/menu.php'); require_once('sqlconnect.php'); if (isset($_GET['log_number']) && isset($_GET['first_name']) && isset($_GET['last_name']) ) { $log_number = $_GET['log_number']; $first_name = $_GET['first_name']; $last_name = $_GET['last_name']; } else if (isset($_POST['log_number']) && isset($_POST['first_name']) && isset($_POST['last_name']) ) { $log_number = $_POST['log_number']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; } if (isset($_POST['submit'])) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "UPDATE table1 SET first_name = '$first_name', last_name = '$last_name' WHERE log_number = '$log_number' "; $result = mysqli_query($dbc, $query) or die ('Error querying database'); mysqli_close($dbc); } ?> my form Code: [Select] <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="first_name">First name</label> <input type="text" id="first_name" name="first_name" value="<?php if (!empty($first_name)) echo $first_name; ?>"/> <label for="last_name">Last Name</label> <input type="text" id="last_name" name="last_name" value="<?php if (!empty($last_name)) echo $last_name; ?>" /> <input type="submit" value="Edit Information" name="submit" /> </form> Believe me!! I have looked and tried so many snippets of code I am exausted! TableName: keywords Row: id productid keywords Good morning... I have been struggling with update, I dont know why... it seems easy eneough and it dosent look that different than a simple insert. Would someone please take a look at the if statement below, more specificly the update section. I am getting an error (Parse error: syntax error, unexpected T_STRING in...... ). Code: [Select] <? $keywd = substr(implode(",", array_keys($arr_tem)),0,200); $productid = intval($_GET['product_id']); // Make a MySQL Connection mysql_connect("localhost", "xxxxxxxxx", "xxxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxxx") or die(mysql_error()); $get = "SELECT * FROM keywords WHERE productid = $productid"; $SQ_query = mysql_query($get) or die("Query failed: $get\n" . mysql_error()); $fetch = mysql_fetch_array($SQ_query); $id = $fetch['productid']; $key = $fetch['keywords']; // Evaluates to true because $var is empty if (empty($id)) { mysql_query("insert into keywords (productid, keywords) VALUES('$productid','$keywd')"); } else{ if (isset($id)) { echo '$var is set even though it is empty'; $mysql_query = mysql_query(UPDATE keywords SET keywords = '$keywd' WHERE productid = '$productid'); // $mysql_query = mysql_query(UPDATE keywords set keywords = "$keywd" WHERE productid = "$productid"); } endif; ?> |