PHP - Update A Profile Not Working
ok, so I have found this code to edit profiles online, only problem is that the data is not being posted to the database, there are no errors, just basically refreshes the page. could you take a look and see if you can help me?
Code: [Select] <?php } //action: edit user ----------------------------------------------------------------------------- if (isset($_GET['edit']) && isset($_GET['id'])) { $userid = (int) $_GET['id']; if ($userid == 0) { die("Invalid ID provided."); } //execution when completed the edit user form and pressed submit button --------------------- if (isset($_POST['editUser'])) { //validate data ------------------------------------------------------------------------ //check empty fields //passwords won't be checked, as they are not required foreach ($_POST as $k=>$v) { if ($v == "" && !in_array($k,$notRequired)) { $error[$k] = "<strong>This field is empty</strong>"; } } //escape string $name = mysql_real_escape_string($_POST['name']); $phone = mysql_real_escape_string($_POST['phone']); $address = mysql_real_escape_string($_POST['address']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $zip = mysql_real_escape_string($_POST['zip']); $cell = mysql_real_escape_string($_POST['cell']); $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $badges = mysql_real_escape_string($_POST['badges']); $rank = mysql_real_escape_string($_POST['rank']); $accounttype = mysql_real_escape_string($_POST['accounttype']); //check email validation, the function is available at config.php if (!check_email($_POST['email'])) { $error['email'] .= " <strong>Email is not valid!</strong>"; } //check email exists in database $res = mysql_query("SELECT email FROM members WHERE email='".$email."' AND userid != '".$userid."'"); if (mysql_num_rows($res) == 1) { $error['email'] .= " <strong>Email already existst in database!</strong>"; } //check username exists in database $res = mysql_query("SELECT username FROM members WHERE username='".$username."' AND username != '".$username."'"); if (mysql_num_rows($res) == 1) { $error['username'] .= " <strong>Username already existst in database!</strong>"; } //check both passwords are the same when password fields are not empty //end validate data --------------------------------------------------------------------- //save to database when no errors are detected ------------------------------------------ if (count($error) == 0) { $query = "UPDATE members SET username='".$username."', email='".$email."',name='".$name."', phone='".$phone."',address='".$address."', city='".$city."',state='".$state."', zip='".$zip."',cell='".$cell."', accounttype='".$accounttype."',badges='".$badges."', rank='".$rank."' "; $query .= "username='".$username."', email='".$email."',name='".$name."', phone='".$phone."',address='".$address."', city='".$city."',state='".$state."', zip='".$zip."',cell='".$cell."', accounttype='".$accounttype."',badges='".$badges."', rank='".$rank."' WHERE userid='".$userid."'"; //update username session if you edit yourself if ($userid == $_SESSION['auth_admin_userid']) { $_SESSION['auth_admin_username'] = $username; } if (mysql_query($query)) { echo "<p><strong>User has been edited and saved to the database.</strong></p>"; } else { echo "<strong>User has NOT been edited and saved into the database. ".mysql_error()."</strong>"; } } } //get user from the database and put data into $_POST variables. $rs = mysql_query("SELECT name, username, phone, address, city, state, zip, cell, email, badges, rank, accounttype FROM members WHERE userid = ".$userid.""); if (mysql_num_rows($rs) == 0) { die("User does not exists!"); } $row = mysql_fetch_assoc($rs); $_POST['name'] = $row['name']; $_POST['username'] = $row['username']; $_POST['phone'] = $row['phone']; $_POST['address'] = $row['address']; $_POST['city'] = $row['city']; $_POST['state'] = $row['state']; $_POST['zip'] = $row['zip']; $_POST['cell'] = $row['cell']; $_POST['email'] = $row['email']; $_POST['badges'] = $row['badges']; $_POST['rank'] = $row['rank']; $_POST['accounttype'] = $row['accounttype']; //if is admin, then $_POST['admin'] exists ?> <div id="TabbedPanels1" class="TabbedPanels"> <ul class="TabbedPanelsTabGroup"> <li class="TabbedPanelsTab" tabindex="0">My Info</li> <li class="TabbedPanelsTab" tabindex="0">Merit Badges</li> <li class="TabbedPanelsTab" tabindex="0">Scout Rank</li> </ul> <div class="TabbedPanelsContentGroup"> <div class="TabbedPanelsContent"> <form action="admin.php?edit&id=<?php echo $userid;?>" method="post"> <table align="center" cellpadding="8" cellspacing="8"> <tr> <td><div align="right">Name:</div></td> <td> <p><input type="text" name="name" value='<?php echo $_POST['name'];?>' /> <?php echo(isset($error['name']))?$error['name']:"";?></p></td> </tr> <tr> <td>Phone Number:</td> <td><input type="text" name="phone" value='<?php echo $_POST['phone'];?>' /> <?php echo(isset($error['phone']))?$error['phone']:"";?></td> </tr> <tr> <td><div align="right">Address:</div></td> <td><input type="text" name="address" value='<?php echo $_POST['address'];?>' /> <?php echo(isset($error['address']))?$error['address']:"";?></td> </tr> <tr> <td><div align="right">City:</div></td> <td><input type="text" name="city" value='<?php echo $_POST['city'];?>' /> <?php echo(isset($error['city']))?$error['city']:"";?></td> </tr> <tr> <td><div align="right">State:</div></td> <td><input type="text" name="state" value='<?php echo $_POST['state'];?>' /> <?php echo(isset($error['state']))?$error['state']:"";?></td> </tr> <tr> <td><div align="right">Zip Code:</div></td> <td><input type="text" name="zip" value='<?php echo $_POST['zip'];?>' /> <?php echo(isset($error['zip']))?$error['zip']:"";?></td> </tr> <tr> <td><div align="right">Email:</div></td> <td> <p> <input type="text" name="email" value='<?php echo $_POST['email'];?>' /> <?php echo(isset($error['email']))?$error['email']:"";?></p></td> </tr> <tr> <td><div align="right">Cell Phone:</div></td> <td><input type="text" name="cell" value='<?php echo $_POST['cell'];?>' /> <?php echo(isset($error['cell']))?$error['cell']:"";?></td> </tr> <tr> <td class="aaaaaaa" align="right">Username:</td> <td><label for="username"></label> <input type="text" name="username" value='<?php echo $_POST['username'];?>' /> <?php echo(isset($error['username']))?$error['username']:"";?></p> </td> </tr> </table> <p> </p> <input name="submit" type="submit" value="Save" /> </form> </div> <div class="TabbedPanelsContent"> <label for="badges"></label> <input name="badges" type="text" id="badges" value="<?php echo "$badges"; ?>" /> </div> <div class="TabbedPanelsContent"> <input name="badges2" type="text" id="badges2" value="<?php echo $rank; ?>" /> </div> </div> </div> <script type="text/javascript"> var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1"); </script> <?php } ?> Similar Tutorialsi get a message saying i cannot be authorised - i have keys, tokens, passwords, users etc but do not know how to implement them or update this script. any help for a super novice would be great! Code: [Select] <html><head><title>Title</title> <?php if (!isset($_POST['submit'])) { // if page is not submitted to itself //echo the form } else { $username = $_POST["username"]; $password = $_POST["password"]; $image = $_POST["image"]; ////// ////// ////// If you are using file uploads from your form, use the following block ////// NOTE: this particular example code uses file uploads from the input form ////// ////// $filename = $_FILES["image"]['name']; $tmpfilename = $_FILES["image"]['tmp_name']; $fileparts = explode(".", $filename); /* get file extension */ $ext = $fileparts[count($fileparts) - 1]; $newfilename = substr($tmpfilename, 0, strlen($tmpfilename) - strlen($ext)) . "." .$ext; //echo $newfilename; /* * this next line creates a "corrected" file ending in .gif/.png/.jpg so * the post headers are correct when CURL makes the request */ copy($tmpfilename, $newfilename); ////// ////// ////// Else If you are using canned files local to your server, use the following block ////// NOTE: you MUST use full path to image! ////// // // /* windows, notice FORWARD SLASHES */ // $newfilename = "c:/www/path/to/image.jpg"; // // // /* *nix */ // $newfilename = "/www/path/to/image.jpg"; // // The twitter API address $url = 'http://twitter.com/account/update_profile_image.xml'; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array("image" => "@$newfilename")); curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password"); $buffer = curl_exec($curl_handle); curl_close($curl_handle); echo $buffer; // if you want to delete the local temp image from uploading, uncomment this next line: // unlink($newfilename); } ?> </head> <body> <form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF;?>"> Username:<input type="text" size="12" maxlength="12" name="username"><br /> Password:<input type="password" size="12" maxlength="36" name="password"><br /> <input type="file" name="image"> <input type="submit" value="submit" name="submit"><br /> </form><br /> </body> </html> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342583.0 Hi all, I'm trying to create a PHP script for user's profile to display the amount of times they've been viewed. I'm looking to have this script increase on a unique view, and it should update the variable in the database. Profiles are accessed by the following link: userprofile.php?userid=X (where X is the ID, e.g. 1, 2, 1001, 345982, etc.). The database variable I'm looking to update is called ProfileViews. I began developing the script, which is as follows: Code: [Select] $_SESSION['Viewed'] = 0; if ($_SESSION['Viewed'] == 0) { $profileViewsQuery = mysql_query("SELECT ProfileViews FROM Users WHERE UserID='????'"); $getProfileViews = mysql_fetch_array($profileViewsQuery); $profileViews = $getProfileViews['ProfileViews']; $profileViews = $profileViews + 1; mysql_query("UPDATE Users SET ProfileViews='$profileViews' WHERE UserID='????'"); $_SESSION['Viewed'] = 1; } However, I'm stumped on a couple things. Could you possibly help me out? 1. How can I get the script to recognize the link accessed's ID? E.g. when a user goes to userprofile.php?userid=1001, how can I get the script to identify the ID to update should be 1001? This is where the "????" would be replaced in the code. 2. On page load, the variable is always going to be $_SESSION['Viewed'] = 0, which isn't going to produce unique hits. Do you have any recommendations how I could achieve unique hits using this method? Thanks very much for reading. Right ive got a user profile that i want a add friend button but i coded a little something what i fort wud work but no luck <?php session_start(); include "includes/db_connect.php"; include "includes/functions.php"; include"includes/smile.php"; logincheck(); $username=$_SESSION['username']; $viewuser=$_GET['viewuser']; $fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$viewuser'")); if (!$fetch){ echo "No such user"; $totalf = mysql_num_rows(mysql_query("SELECT * FROM friends WHERE username = '$viewuser' AND active='1'")); $invite_text="<div>$username Has Sent You A Friend Request<br> <input name=Yes_Accept type=submit id=yes value=Accept Invite class=abutton> <input name=No_accept type=submit value=Decline Invite class=abutton></div><input type=hidden name=invite_id value=$bar2>"; if (($_GET['fri'])){ $exicst=mysql_query("SELECT * FROM users WHERE username='$viewuser'"); $nums=mysql_num_rows($exicst); $adding=mysql_fetch_object($exicst); $already=mysql_num_rows(mysql_query("SELECT * FROM friends WHERE type='Friend' AND person='$viewuser' AND username='$username'")); if ($already != "0"){ echo "<center><font color=orange><b><br>This user is already your friend.<br><br></font>"; }elseif ($already == "0"){ mysql_query("INSERT INTO `friends` ( `id` , `username` , `person` , `type` , `active`) VALUES ( '', '$username', '$viewuser', 'Friend' , '0' )"); mysql_query("INSERT INTO `friends` ( `id` , `username` , `person` , `type` , `active`) VALUES ( '', '$viewuser', '$username', 'Friend' , '0' )"); mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `subject` , `date` , `read`) VALUES ( '', '$viewuser', '$username', '$invite_text' , 'Friend Request' , '$date' , '0' )"); $bar2=mysql_insert_id(); echo "<center><font color=orange><br>Your Friend Invitation Was Sent To $viewuser<br><br></font>"; exit(); } }} ?> <a href=?fri=Yes>Add Friend +</a> It just adds a blank person and comes back with No Such User and Your Friend Invitation Was Sent To I think ive put some things in the wrong place to be honest but as im not a pro i easily miss things Hi all, I am currently facing a problem, if you look at 'viewprofile.jpg' attachment, you can see that there is an uploaded profile picture. However when I click to edit the profile, the picture is missing (editprofile.jpg), I am just wondering what went wrong? Can someone guide me in troubleshooting this problem? Code: [Select] <?php if (isset($_POST['submit'])) { // Validate and move the uploaded picture file, if necessary if (!empty($new_picture)) { if ((($new_picture_type == 'image/gif') || ($new_picture_type == 'image/jpeg') || ($new_picture_type == 'image/pjpeg') || ($new_picture_type == 'image/png')) && ($new_picture_size > 0) && ($new_picture_size <= CT_MAXFILESIZE)) { //0 indicates a success, other values indicate failure if ($_FILES['file']['error'] == 0) { // Move the file to the target upload folder $target = CT_UPLOADPATH . basename($new_picture); if (move_uploaded_file($_FILES['new_picture']['tmp_name'], $target)) { // The new picture file move was successful, now make sure any old picture is deleted if (!empty($old_picture) && ($old_picture != $new_picture)) { @unlink(CT_UPLOADPATH . $old_picture); } } else { // The new picture file move failed, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Sorry, there was a problem uploading your picture.</p>'; } } } else { // The new picture file is not valid, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Your picture must be a GIF, JPEG, or PNG image file no greater than ' . (CT_MAXFILESIZE / 1024). '</p>'; } } // Grab the profile data from the POST $name = mysqli_real_escape_string($dbc, trim($_POST['name'])); $nric = mysqli_real_escape_string($dbc, trim($_POST['nric'])); $gender = mysqli_real_escape_string($dbc, trim($_POST['gender'])); $old_picture = mysqli_real_escape_string($dbc, trim($_POST['old_picture'])); $new_picture = mysqli_real_escape_string($dbc, trim($_FILES['new_picture']['name'])); $new_picture_type = $_FILES['new_picture']['type']; $new_picture_size = $_FILES['new_picture']['size']; list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']); $error = false; // Update the profile data in the database if (!$error) { if (!empty($name) && !empty($nric) && !empty($gender)) { $query = "UPDATE tutor_profile SET name = '$name', nric = '$nric', gender = '$gender' WHERE tutor_id = '" . $_GET['tutor_id'] . "'"; mysqli_query($dbc, $query) or die(mysqli_error($dbc)); // Confirm success with the user echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile.php?tutor_id=' . $_GET['tutor_id'] . '">view your profile</a>?</p>'; mysqli_close($dbc); exit(); } else { echo '<p class="error">You must enter all of the profile data (the picture is optional).</p>'; } } } // End of check for form submission else { // Grab the profile data from the database $query = "SELECT name, nric, gender FROM tutor_profile WHERE tutor_id = '" . $_GET['tutor_id'] . "'"; $data = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); // The user row was found so display the user data if (mysqli_num_rows($data) == 1) { $row = mysqli_fetch_array($data); if ($row != NULL) { $name = $row['name']; $nric = $row['nric']; $gender = $row['gender']; } else { echo '<p class="error">There was a problem accessing your profile.</p>'; } } } mysqli_close($dbc); ?> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo CT_MAXFILESIZE; ?>" /> <ul id="tabSet_ep"> <li><a href="#panel1">Personal Profile</a></li> <li><a href="#panel2">Qualifications</a></li> <li><a href="#panel3">Tutor\'s Comments/Commitment</a></li> <li><a href="#panel4">Tutoring Levels/Subjects</a></li> </ul> <!--Personal Profile--> <div id="panel1"> <label for="new_picture">Pictu </label> <input type="file" id="new_picture" name="new_picture" /> <?php if (!empty($old_picture)) { echo '<img class="profile" src="' . CT_UPLOADPATH . $old_picture . '" alt="Profile Picture" />'; } ?><br /> <label for="firstname">First name:</label> <input type="text" id="firstname" name="firstname" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="lastname">Last name:</label> <input type="text" id="lastname" name="lastname" value="<?php if (!empty($nric)) echo $nric; ?>" /><br /> <label for="gender">Gender:</label> <select id="gender" name="gender"> <option value="M" <?php if (!empty($gender) && $gender == 'M') echo 'selected = "selected"'; ?>>Male</option> <option value="F" <?php if (!empty($gender) && $gender == 'F') echo 'selected = "selected"'; ?>>Female</option> </select><br /> </div> <input type="submit" value="Save Profile" name="submit" /> </form> 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> 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. 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. Hi, i am currently designing a new website and am testing a few different compnents of it. One part gathers two variables of the url using the GET method and selects the relevant data from the database. It then performs an UPDATE of a field called balance before INSERTING a new record. Everything works and gets inserted except for the UPDATE. Here is the code Code: [Select] <?php include ("connect.php"); $id = ""; $offerid = ""; $id = $_GET['user_id']; $offerid = $_GET['offer_id']; $sql_user = mysql_query("SELECT * FROM user_info WHERE id = $id"); $sql_offer = mysql_query("SELECT * FROM offers WHERE offerid = $offerid"); $balance += $payout; mysql_query("UPDATE user_info SET balance = $balance WHERE id = $id"); mysql_query ("INSERT INTO offer_credited (id, offerid, date_credited, payout_to_user) VALUES ('$id', '$offerid', CURDATE(), '$payout')") or die(mysql_error()); echo "Your Offer has been recorded and Updated" ?> The balance field is a float that i want to increase by the amount of the payout variable which is from the offers table. However, the balance never gets updated and remains at 0. Any ideas what it could be, i am thinking it is something to do with, Code: [Select] $balance += $payout; But i can't think of what else to do. Hopefully this isn't too confusing. Thanks for the help 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> Hello people, At the moment I am really desperate. I've done this script over 20 times now, always with the same script but all of a suddon, it doesn't work anymore. heres the problem: I made a very simple "patient database" for a doctor. Where he can upload patients, alter and delete them. The script to add the patients works fine. now im trying to make a script where he can alter the variables agian, using the UPDATE command. but instead of updating the variables it cleares all the date in the row. can someone help me? here s the entire code: Code: [Select] <?PHP include'connect.php'; ?> <?PHP $SQL = mysql_query("SELECT * FROM leys_patienten WHERE patientid='".$_REQUEST['patientid']."'"); while ($row = mysql_fetch_array($SQL)) { ?> <?PHP if ($_POST[submit]) { if (!$_POST[volgnummer]) { echo "<font size=\"2\" color=\"#990000\"><b>--> Vul een volgnummer in a.u.b. <--</b></font>"; } elseif (!$_POST[naam]) { echo "<font size=\"2\" color=\"#990000\"><b>--> Vul een naam in a.u.b. <--</b></font>"; } elseif (!$_POST[voornaam]) { echo "<font size=\"2\" color=\"#990000\"><b>--> Vul een voornaam in a.u.b.! <--</b></font>"; } else { mysql_query("UPDATE leys_patienten SET volgnummer='$volgnummer',naam='$naam',voornaam='$voornaam',adres='$adres',postcode='$postcode',plaats='$plaats',telefoon='$telefoon',email='$email',geboortedatum='$geboortedatum',geboorteplaats='$geboorteplaats',opmerkingen='$opmerkingen' WHERE patientid='".$_REQUEST['patientid']."'") or die(mysql_error()); echo "Het patientendossier is succesvol gewijzigd, let op doorschakeling.";?> <meta http-equiv="Refresh" content="1; url=patient.php?patientid=<?PHP echo $row['patientid']?>" /> <? } } ?></p> <form action="<?$PHP_SELF?>" method="post" name="post" id="post"> <table width="805" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="table_forms">Volgnummer*</td> <td class="table_forms"><label><input name="volgnummer" type="text" id="volgnummer" value="<?PHP echo $row['volgnummer']?>" size="40" /></label></td> </tr> <tr> <td width="146" class="table_forms">Naam*</td> <td width="659" class="table_forms"><label><input name="naam" type="text" id="naam" value="<?PHP echo $row['naam']?>" size="40" /></label></td> </tr> <tr> <td class="table_forms">Voornaam*</td> <td class="table_forms"><font color="#FFFFFF" size="2"> <label><input name="voornaam" type="text" id="voornaam" value="<?PHP echo $row['voornaam']?>" size="40" /></label> </font></td> </tr> <tr> <td class="table_forms">Adres </td> <td><font color="#FFFFFF" size="2"> <label><input name="adres" type="text" id="adres" value="<?PHP echo $row['adres']?>" size="40" /></label> </font></td> </tr> <tr> <td class="table_forms">Postcode</td> <td><font color="#FFFFFF" size="2"> <label><input name="postcode" type="text" id="postcode" value="<?PHP echo $row['postcode']?>" size="6" /></label> </font></td> </tr> <tr> <td class="table_forms">Plaats</td> <td><font color="#FFFFFF" size="2"> <label><input name="plaats" type="text" id="plaats" value="<?PHP echo $row['plaats']?>" size="40" /></label> </font></td> </tr> <tr> <td class="table_forms">Telefoon</td> <td><font color="#FFFFFF" size="2"> <label><input name="telefoon" type="text" id="telefoon" value="<?PHP echo $row['telefoon']?>" size="40" /></label> </font></td> </tr> <tr> <td class="table_forms">E-mail</td> <td><font color="#FFFFFF" size="2"> <label><input name="email" type="text" id="email" value="<?PHP echo $row['email']?>" size="40" /></label> </font></td> </tr> <tr> <td class="table_forms">Geboortedatum</td> <td><font color="#FFFFFF" size="2"> <label><input name="geboortedatum" type="text" id="geboortedatum" value="<?PHP echo $row['geboortedatum']?>" size="40" /></label> </font></td> </tr> <tr> <td class="table_forms">Geboorteplaats</td> <td><font color="#FFFFFF" size="2"> <label><input name="geboorteplaats" type="text" id="geboorteplaats" value="<?PHP echo $row['geboorteplaats']?>" size="40" /></label> </font></td> </tr> <tr> <td valign="top" class="table_forms">Opmerkingen</td> <td><font color="#FFFFFF" size="2"> <label><textarea name="opmerkingen" cols="40" rows="4" id="opmerkingen"><?PHP echo $row['opmerkingen']?></textarea></label> </font></td> </tr> <tr> <td valign="top" class="table_forms"> </td> <td><span class="body_tekst"> <input type="submit" id="submit" name="submit" value="verstuur" /> </span></td> </tr> </table> <p class="body_tekst"> </p> </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; ?> I have <?php /** This file is responsible for processing all the add and modify requests for the movies, games and customer section of the admin page. The various functions here can be called into the pages we need inorder to make code management cleaner and easier to handle. **/ include('databaseconfig.php'); //Add a new customer to the data base. $query = mysql_query("update customer set customer_id = '" .$_POST['cust_id'] . "', first_name = '" .$_POST['fname'] . "', last_name = '" .$_POST['lastname'] . "', adress = '" .$_POST['address'] . "', postal_code= '" .$_POST['postalcode'] . "', phone_number= '" .$_POST['phonenumber'] . "', user_name = '" .$_POST['fname'] . "', user_pass = '" .$_POST['lastname'] . "'"); echo("<h1>Output</h1>"); echo($query); echo("<h1>Possible Errors</h1>"); //Echo errors echo mysql_errno($query) . ": " . mysql_errno($query); ?> Which should get the information from the forum feilds and insert that into the data base, throwing errors if I left feilds null. But when I run it and leave everything blank and hit submit or even actually enter the required data all I get is a page that states Code: [Select] Output Possible Errors : I 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! Hi guys need some help.I created a simple Update Customer Details page Where you Enter the Customer ID ,The Customer Details Get Displayed inside a Form and you make changes within the Form.But the update query I wrote is not working as it should be.It Executes the Query ,when I hardcode the Customer ID inside the Update query but fails when I need to Enter the Customer ID directly from the form using post.In This Code I tried to Update only the Customer's Firstname.Thanks Here Is The Code Code: [Select] <?php $db=mysql_connect("localhost","root","") or die('Unable to Connect To Database.Please check the Database Parameters'); mysql_select_db('ecommerce') or die(mysql_error()); if(isset($_POST['enterid'])) { $_POST['inputid']; } $query="SELECT * FROM customer WHERE Cid='$_POST[inputid]'"; $result=mysql_query($query) or die(mysql_error()); $row=mysql_fetch_array($result); $new_cid=$row['Cid']; $new_firstname=$row['Cfname']; $new_lastname=$row['Clname']; $new_email=$row['Email_id']; $new_address=$row['Address']; $new_pincode=$row['Pincode']; $new_payment=$row['Mode_of_payment']; $new_city=$row['City']; $new_state=$row['State']; $new_phone=$row['Phone']; $html1=<<<HTML1 <form action="updatecustomer.php" method="post"> <p class="inputidentifier">Please Enter The Customer's ID</p><input type="text" style="width:375px;height:40px;font-size:30px;" name="inputid" size="20"><br><br> <input type="submit" name="enterid" style="height:40px"> HTML1; print($new_cid); if(isset($_POST['update'])) { $query1="UPDATE customer SET Cfname='$_POST[firstname]' WHERE Cid='$_POST[inputid]'"; mysql_query($query1) or die(mysql_error()); if(mysql_affected_rows()==1) print("Query sucessful"); else print("Something went wrong"); } ?> <html> <head> <style type="text/css"> .inputtext {width:300px; height:40px;font-size:30px;} .inputidentifier{font-size:25px;font-family:"Arial"} .h1type{font-family:"Arial"} </style> <title>Test</title> </head> <body> <?php print($html1); ?> <h1 align="center" class="h1type">Update Customer Details</h1> <form action="updatecustomer.php" method="POST"> <table align="center" cellspacing="10" cellpadding="10" border="0" width="60%"> <tr> <td align="right" class="inputidentifier">First Name</td> <td align="left"><input type="text" class="inputtext" name="firstname" placeholder="eg:Kevin" value="<?php print($new_firstname) ?>"></td> </tr> <tr> <td align="right" class="inputidentifier">Last Name</td> <td><input type="text" class="inputtext" name="lastname" placeholder="eg:Aloysius" value="<?php print($new_lastname) ?>"></td> </tr> <tr> <td align="right" class="inputidentifier">E-mail</td> <td align="left"><input type="email" style="width:500" class="inputtext" name="email" placeholder="yourname@email.com" value="<?php print($new_email) ?>"> </tr> <tr> <td align="right" class="inputidentifier">Phone Number</td> <td align="left"><input type="text" class="inputtext" name="phone" placeholder="How Do We Call You?" value="<?php print($new_phone) ?>"></td> </tr> <tr> <td align="right" class="inputidentifier">Address</td> <td><textarea style="width:500;height:150" wrap="virtual" class="inputtext" name="address" placeholder="Where is your Crib?"><?php print($new_address) ?></textarea></td> </tr> <tr> <td align="right" class="inputidentifier">State</td> <td align="left"><input type="text" style="width:500" class="inputtext" name="state" placeholder="State" value="<?php print($new_state) ?>"> </tr> <tr> <td align="right" class="inputidentifier">City</td> <td align="left"><input type="text" class="inputtext" name="city" placeholder="City" value="<?php print($new_city) ?>"> </tr> <tr> <td align="right" class="inputidentifier">Pin Code</td> <td><input type="text" class="inputtext" name="pincode" placeholder="Mulund 400080" maxlength="6" value="<?php print($new_pincode) ?>"></td> </tr> <tr> <td align="right" class="inputidentifier">How do Pay for your Bling?</td> <td align="left"> <input type="text" class="inputtext" name="payment" value="<?php print($new_payment)?>"> </tr> <tr> <td></td> <td><input type="submit" name="update" value="Update!" style="width:100px;height:60px;"></td> </tr> </table> </form> </body> </html> can anyone see anything wrong here?? it wont update the Ships table.. i should of gone bed hours ago but its bugging me: <?php $sql="SELECT * FROM ships ORDER BY auction='Yes' DESC"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Active?</strong></td> <td align="left"><strong>typeID</strong></td> <td align="left"><strong>Item Name</strong></td> <td align="left"><strong>Base Price</strong></td> <td align="left"><strong>Market Price</strong></td> <td align="center"><strong>Auction</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <?php if ($rows['auction'] != "Yes") { ?> <td align="center"><img src="../images/site/delete.png" /></td> <?php } else { ?> <td align="center"><img src="../images/site/accept.png" /></td> <? } ?> <td align="left"><span class="isk"> <? $typeID[]=$rows[typeID]; ?> <? echo $rows['typeID']; ?></span></td> <td align="left"><span class="eveyellow"><? echo $rows['typeName']; ?></span></td> <td align="left"><span class="normal"><?php echo number_format($rows['basePrice'])?> isk</span></td> <td align="left"><input name="marketPrice[]" type="text" size="10" id="marketPrice" value="<? echo $rows['marketPrice']; ?>"> <span class="credits">(<?php echo number_format($rows['marketPrice']/1000000, 2)?> m)</span></td> <td align="center"><input name="auction[]" type="text" size="6" id="auction" value="<? echo $rows['auction']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" 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 ships SET marketPrice='$marketPrice[$i]', auction='$auction[$i]' WHERE typeID='$typeID[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:ship.php"); } mysql_close(); ?> typeID is my primary key in the table and i only want to update "marketPrice" and "auction" upon submit. its a update multiple rows form by the way. thank you so much for helping me... again.. would be lost without phpfreaks. This is the weirdest thing ever. I've been programming php for years yet I have been pulling my hair out for hours over something that seems so simple! I have a table in my db named last_num_used with 2 fields: id, num which are both type int. It only has one row, so I don't need to use WHERE to update when I execute the command via php: Code: [Select] $sql = "UPDATE last_num SET num='4'"; echo $sql; if (!mysql_query($sql)) {die('Error: ' . mysql_error());}everything works fine and I see the echoed command UPDATE last_num SET num='4' But, when I have a variable $var and try to update it, it will only update properly if $var=1 or $var=2. If $var equals a value greater than 2, then for some reason it updates the column so that num=1. Note the exact problem in example 3 below. Example 1: Code: [Select] $var=1; $sql = "UPDATE last_num SET num='$var'"; echo $sql; if (!mysql_query($sql)) {die('Error: ' . mysql_error());}Result: echoed to screen: UPDATE last_num SET num='1' database updated and num=1 Example 2: Code: [Select] $var=2; $sql = "UPDATE last_num SET num='$var'"; echo $sql; if (!mysql_query($sql)) {die('Error: ' . mysql_error());}Result: echoed to screen: UPDATE last_num SET num='2' database updated and num=2 Example 3: Code: [Select] $var=3; $sql = "UPDATE last_num SET num='$var'"; echo $sql; if (!mysql_query($sql)) {die('Error: ' . mysql_error());}Result: echoed to screen: UPDATE last_num SET num='3' database updated and num=1 view_leader.php
|