PHP - Mysql Update Not Working For 1 Value, But Working With Other Values
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> Similar TutorialsHi everyone, I have been trying to get this code working but no matter what I try it will not work, I am trying to allow a user to update their personal details when they login to my website. I have created a form and submit button, the code is shwn below: <?php echo $_SESSION['myusername']; ?> <br><br> <form action="updated.php" method="post"> Firstname: <input type="text" name="firstname" /><br><br> Surname : <input type="text" name="surname" /><br><br> Date Birth: <input type="text" name="dob" /><br><br> Total Wins: <input type="text" name="wins" /> Total Loses: <input type="text" name="loses" /><br><br> Email Add: <input type="text" name="email" /><br><br> Country : <input type="text" name="born" /><br><br> Other Info: <input type="text" name="other" /><br><br> <input type="submit" name="Submit" value="Update" align="right"></td> </form> The updated.php file <?php mysql_connect ("localhost","root","") or die("Cannot connect to Database"); mysql_select_db ("test"); $sql=mysql_query("UPDATE memberdetails SET firstname='{$_POST['firstname']}', surname='{$_POST['surname']}', dob='{$_POST['dob']}', totalwins='{$_POST['wins']}', totalloses='{$_POST['loses']}', email='{$_POST['email']}', country='{$_POST['born']}', info='{$_POST['other']} WHERE username=$_SESSION['myusername']); if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "Details Updated"; ?> This is the error i recieve: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\website\updated.php on line 45 Line 45 is $sql=mysql_query line If anybody can help it will be very much appreciated! hi - i'm trying to update mysql databse but not working... any ideas??? Code: [Select] [php] <?php ob_start(); require_once('../xconfig.php'); if(isset ($_GET['quote'])&& $_GET['quote']!=""){ $quote_id=$_GET['quote']; mysql_select_db($database, $makeconnection); $sql_find_quote = "SELECT * FROM tbl_quote WHERE quote_id = $quote_id"; $find_quote = mysql_query($sql_find_quote, $makeconnection) or die(mysql_error()); $row = mysql_fetch_assoc($find_quote); $totalRows = mysql_num_rows($find_quote); $quote_author = $_POST['quote_author']; $quote_desc = $_POST['quote_desc']; if (isset($_POST['submitted'])&&($_POST['submitted'] == "yes")) { $register_query = "SELECT quote_desc FROM tbl_quote WHERE quote_desc='$quote_desc'"; mysql_select_db($database, $makeconnection); $register_check=mysql_query($register_query, $makeconnection); $register_found_quote = mysql_num_rows($register_check); if($register_found_quote>1){ header ("Location: quote_modify.php?error=quoteexists"e=$quote_id"); }else{ $sql_modify = "UPDATE tbl_quote SET quote_desc = '$quote_desc' quote_author = '$quote_author' WHERE quote_id = '$quote_id'"; } mysql_select_db($database, $makeconnection); $Result1 = mysql_query($sql_modify, $makeconnection) or die(mysql_error()); header ("Location: quote.php"); } } ob_flush(); ?> [/php] here's my HTML form Code: [Select] <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> <p> <input name="quote_author" type="text" class="active-field" id="quote_author" value="<? echo $row['quote_author'];?>"/> <br /> <input name="quote_desc" type="text" class="active-field" id="quote_desc" value="<? echo $row['quote_desc'];?>" /> <br /> <input name="submitted" type="hidden" id="submitted" value="yes" /> <input name="submit" type="submit" id="submit" class="submit-button" value="modiy"/> <br /> </p> </form> 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> view_leader.php
Hello, I have this simple php form that updates the table, and also shows what the information in it is. Here it is: <strong>Update multiple rows in mysql</strong><br> <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>Month</strong> <strong>Date</strong> </td> <td align="center"><strong>Lastname</strong></td> <td align="center"><strong>Email</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td> <td align="center"><input name="month[]" MAXLENGTH="3" size="3" type="text" id="month" value="<?php echo $rows['month']; ?>">- <input name="date[]" MAXLENGTH="2" size="2" type="text" id="date" value="<?php echo $rows['date']; ?>"> </td> <td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['lastname']; ?>"></td> <td align="center"><input name="email[]" type="text" id="email" value="<?php echo $rows['email']; ?>"></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 (isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $month = $_POST['month']; $date = $_POST['date']; $lastname = $_POST['lastname']; $email = $_POST['email']; $name = $month."<br>".$date; $sql1="UPDATE $tbl_name SET name='$name[$i]', month='$month[$i]', date='$date[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update2.php"); } ?> <?php $result = mysql_query("SELECT * FROM test_mysql") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['lastname']; echo "</td></tr>"; } echo "</table>"; ?> What it does is this, it gets the row from the database, echos it and I am able to edit it and then save. The thing is, it works with the updating but im trying to combine 2 variables into 1 and update that one also. Im trying to combine month and date textboxes into one variable in the database that is name. It for some reason updates the column name to A instead of what I had in the 2 fields month and date. Here is where I combine both fields into one. $name = $month."<br>".$date; And here is where $month and $date is set. $month = $_POST['month']; $date = $_POST['date']; Here is a picture. Hi there, I'm having a problem with updating a record with an UPDATE mysql query and then following that query with a SELECT query to get those values just updated. This is what I'm trying to do...I'd like a member to be able to complete a recommended task and upon doing so, go to a page in their back office where they can check off that task as "Completed". This completed task would be recorded in their member record in our database so that when they return to this list, it will remain as "Completed". I'm providing the member with a submit button that will call the same page and then update depending on which task is clicked as complete. Here is my code: Code: [Select] $memberid = $_SESSION['member']; // Check if form has been submitted if(isset($_POST['task_done']) && $_POST['task_submit'] == 'submitted') { $taskvalue = $_POST['task_value']; $query = "UPDATE membertable SET $taskvalue = 'done' WHERE id = $memberid"; $result = mysqli_query($dbc, $query); } $query ="SELECT task1, task2, task3 FROM membertable WHERE id = $memberid"; $result = mysqli_query($dbc, $query); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); $_SESSION['task1'] = $row['task1']; $_SESSION['task2'] = $row['task2']; $_SESSION['task3'] = $row['task3']; ?> <h4>Task List</h4> <table> <form action="" method="post"> <tr> <td>Task 1</td> <td><?php if($_SESSION['task1'] == 'done') {echo '<div>Completed</div>';} else{ echo '<input type="submit" name="task_done" value="Mark As Completed" />';} ?></td> </tr> <input type="hidden" name="task_value" value="task1" /> <input type="hidden" name="task_submit" value="submitted" /> </form> <form action="" method="post"> <tr> <td>Task 1</td> <td><?php if($_SESSION['task1'] == 'done') {echo '<div>Completed</div>';} else{ echo '<input type="submit" name="task_done" value="Mark As Completed" />';} ?></td> </tr> <input type="hidden" name="task_value" value="task2" /> <input type="hidden" name="task_submit" value="submitted" /> </form> <form action="" method="post"> <tr> <td>Task 1</td> <td><?php if($_SESSION['task1'] == 'done') {echo '<div>Completed</div>';} else{ echo '<input type="submit" name="task_done" value="Mark As Completed" />';} ?></td> </tr> <input type="hidden" name="task_value" value="task3" /> <input type="hidden" name="task_submit" value="submitted" /> </form> </table> The problem that I am having is that the database is not updated with the value "done" but after submission, the screen displays "Completed" instead of "Mark As Completed". So the value is being picked up as "done", but that is why I have the SELECT after the UPDATES, so that there is always a current value for whether a task is done or not. Then I refresh and the screen returns the button to Mark As Complete. Also, when I try marking all three tasks as, sometimes all three are updated, sometimes only one or two and again, I leave the page or refresh and the "Marked As Completed" buttons come back. Bizarre. If anyone can tell me where my logic is going wrong, I would appreciate it.
Hello. I activate the Payment Gateway Platform (by Redsys in Spain), and it works fine asking you for card number and it goes through correctly and says PAYMENT OK, but the notification.PHP FILE does not work. Could my server (SSL) configuration be the problem? or is it the CODE? Any help about this, please, would be highly appreciated. Thank you. Part of the Nofication.php code is: __________________________________________________________________________________
<?php $handle = fopen("_redsys.log", "a");
require_once("include/dbcommon.php"); $miObj = new RedsysAPI;
$version = postvalue("Ds_SignatureVersion");
// $version = "HMAC_SHA256_V1";
$claveModuloAdmin = 'sq7HjrUOBfKmC576ILgskD5srU870gJ7';
if ($signatureCalculada === $signatureRecibida && $res["Ds_AuthorisationCode"]!="++++++" && !isset($res["Ds_ErrorCode"]) {
$sql = "SELECT Espacio FROM Espacios WHERE Id_Espacio=" . $values["Id_Espacio"];
// echo '<img src="data:image/jpeg;base64,'.$imageData.'">';
_______________________________________________________________________________________________ I have been pulling my hair out for the lasy 3 hours i am trying to update a MySql table but i cant get it too work, i just keep getting MySql error #1064 - You have an error in your SQL syntax; if i just update 1 field it works fine but if i try to update more than 1 field it dosent work, Help Please! <?php $root = $_SERVER['DOCUMENT_ROOT']; require("$root/include/mysqldb.php"); require("$root/include/incpost.php"); $con = mysql_connect("$dbhost","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$dbame", $con); mysql_query("UPDATE Reg_Profile_p SET build='$build' col='$col' size='$size' WHERE uin = '$uinco'"); ?> Hello everyone I need code for this question
would you help me please..?
I am pulling 5 addresses and I am wanting to store these 5 addresses in columns in a separate table. On the query string I put LIMIT 5. How can I store the results of each of the 5 loops into columns in a separate table? The columns are A1(for name), A2(for address), A3 (for city), A4 (for state), A5 (for zip), A6 (for phone), A7 (for miles), .... then I also have B1-B7, C1-C7, D1-D7, and E1-E7. I am basically wanting to store up to 5 addresses in an array and then update them into a mysql table. Code: [Select] foreach ($zips as $key => $value) { $result = mysql_query("SELECT State FROM extreme WHERE Zip = '$key' AND Type='store' AND `InStore` <> 'NO' LIMIT 5", $db); $num_rows = mysql_num_rows($result); while($myrow = mysql_fetch_array ($result)) { $Dealer=$myrow['Dealer']; $Address=$myrow['Address']; $City=$myrow['City']; $State=$myrow['State']; $Zip=$myrow['Zip']; $Phone=$myrow['Phone']; $Miles = $value; } } Hi all, I have the following MySQL insert query: Code: [Select] $insert= mysql_query ("INSERT INTO tablename (column1,`".$EXPfields."`) VALUES ('$something','".$EXPvalues."')"); where $EXPfields is an array of table-field-names and $EXPvalues is an array of table-field-values. Now I want to write an equivalent query, but using UPDATE instead of INSERT INTO, but I don't want to write out all the field names/values separately, but again want to use $EXPfields and $EXPvalues. So something like this: Code: [Select] $update = mysql_query ("UPDATE tablename SET (column1,`".$EXPfields."`) = ('$something','".$EXPvalues."') WHERE .... "); Is this possible? If so, what is the proper syntax? Thanks! 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. 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. 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 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> <? } ?> 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 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; ?> 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 } ?> 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 |