473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cannot update the database table using php?

Here is my part of php code.In this code when a user clicks the edit EditProfile.php is opened.And when the user change his or her info and type the button update the info is coming from the form.However I cannot see the updated info in phpmyadmin.Also the birthday is return as 0000-00-00.I coulndn't understand.Please help me.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     session_start();
  3.  
  4.     include "validate.php";
  5.     include "src/header.php";
  6.     include "src/mainmenu.php";
  7.  
  8. ?>
  9. <?php
  10. if(isset($_POST['update']))
  11. {
  12.  
  13. include("db.php");
  14.  
  15.     $name = $_POST['name'];
  16.  
  17.     $password1 = md5($_POST['password1']);
  18.     $password2 = md5($_POST['password2']);
  19.     $date_of_birth = $_POST['date_of_birth'];
  20.     $place_of_birth = $_POST['place_of_birth'];
  21.     $info = $_POST['info'];
  22.     $nationality = $_POST['nationality'];
  23.  
  24.     echo $_POST['name'];
  25.     echo $name;
  26.     echo $date_of_birth;
  27.     echo $info;
  28.     echo $place_of_birth;
  29.     echo $nationality;
  30.  
  31.     if ($password1 != $password2) {
  32.         include "src/header.php";
  33.         include "src/mainmenu.php";
  34.         echo '<p>Error: password does not match. Try again</a>';
  35.         echo '<p><a href="EditProfile.php">Try again</p>';
  36.         include "src/footer.php";
  37.         exit;
  38.     }
  39.     //If the name and the other fields are empty
  40.     if($name=='' || $email='' || $password1='' || $password2='' || $date_of_birth= ''|| $place_of_birth= ''|| $info='' || $nationality='' ){
  41.         include "src/header.php";
  42.         include "src/mainmenu.php";
  43.         echo '<p>Error:You didn\'t fill the fields.Try again</a>';
  44.         echo '<p><a href="EditProfile.php">Try again</p>';
  45.         include "src/footer.php";
  46.         exit;
  47.     }
  48.  
  49.  
  50. $email=$_SESSION['email'];
  51.  
  52. $sql = "UPDATE users SET name='".mysql_real_escape_string($name)."',
  53.                          info= '".mysql_real_escape_string($info)."',
  54.                          password=".mysql_real_escape_string($password2)."'
  55.                          place_of_birth='".mysql_real_escape_string($place_of_birth)."',
  56.                          date_of_birth='".mysql_real_escape_string($date_of_birth)."', 
  57.                          nationality='".mysql_real_escape_string($nationality)."'
  58.                             WHERE email ='$email'";
  59.  
  60.  
  61. $retval = mysql_query($sql,$link);
  62.  
  63.  
  64.  
  65. if (!$retval|| $retval==false) {
  66.         include "src/header.php";
  67.         include "src/mainmenu.php";
  68.         die('Could not update data: ' . mysql_error());
  69.         echo '<p><a href="EditProfile.php">Try again</a></p>';
  70.         include "src/footer.php";
  71.         mysql_close($link);
  72.         exit;
  73.     }
  74.     else {
  75.         echo "Updated data successfully\n";
  76.  
  77.         //header('Location: private.php');
  78.     }
  79.  
  80. mysql_close($link);
  81. }
  82. else
  83. {
  84.  include("db.php"); 
  85.  
  86. $email=$_SESSION['email'];
  87. $run = mysql_query("select * from users where email='$email'") or die("Error!");
  88. $read = mysql_fetch_assoc($run);
  89.  
  90. ?>
  91. <form method="post" action="<?php $_PHP_SELF ?>">
  92.     <fieldset>
  93.     <legend>Update Profile</legend>
  94.     <p>
  95.         <label for="name">Full name:</label> <input type="text" name="name" id="name" value="<?PHP echo $read['name']; ?>"/> 
  96.     <br>
  97.         <label for="email">Email:</label> <input type="email" name="email" id="email" value="<?PHP echo $read['email']; ?>"/> 
  98.     <br>
  99.         <label for="password1">Password:</label> <input type="password" name="password1" id="password1" />
  100.     <br>
  101.         <label for="password2">Confirm password:</label> <input type="password" name="password2" id="password2" />
  102.     <br>
  103.         <label for="date_of_birth">Date of birth (yyyy-mm-dd):</label> <input type="date" name="date_of_birth" id="date_of_birth"  value="<?PHP echo $read['date_of_birth']; ?>"/>
  104.     <br>
  105.         <label for="place_of_birth">Place of birth:</label> <input type="text" name="place_of_birth" id="place_of_birth" value="<?PHP echo $read['place_of_birth']; ?>"/>
  106.     <br>
  107.         <label for="info">Information:</label> <textarea name="info" id="info" rows="5" cols="50" ></textarea>
  108.     <br>
  109.         <label for="nationality">Nationality:</label> <input type="text" name="nationality" id="nationality" value="<?PHP echo $read['nationality']; ?>"/>
  110.     </p>
  111.  
  112.     <p class="center"><input value="Update" type="submit" name="update" id="update"/></p>
  113.     </fieldset>
  114.     </form>
  115. <?php
  116.  
  117. }
  118. ?>
Attached Files
File Type: txt EditProfile.txt (3.6 KB, 758 views)
May 17 '13 #1

✓ answered by Rabbit

In your SQL you're missing a quote around your password.

5 2107
Rabbit
12,516 Expert Mod 8TB
As far as I can tell. None of your variables are populated.
May 17 '13 #2
@Rabbit how can i change it to populate?Could you look at the attached file?
May 17 '13 #3
Rabbit
12,516 Expert Mod 8TB
Sorry, I don't download attachment's from strangers. Please post all relevant code in the thread itself.
May 17 '13 #4
@Rabbit Ok I have edited my question.
May 18 '13 #5
Rabbit
12,516 Expert Mod 8TB
In your SQL you're missing a quote around your password.
May 18 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: tamimi | last post by:
I have a guestbook form that inserts the fields into an Access Database. The database is residing in the "fpdb" folder that was created by FrontPage. The ASP page that writes the data into the...
1
by: Fie Fie Niles | last post by:
I have IIS installed on XP Professional workstation machine. I have an ASP page that open connection to an Access database, then when trying to update the database, it gave me the error "cannot...
0
by: mr_wizard | last post by:
I posted a message yesterday on my difficulty in updating an Access table. Yesterday the error response was permission related. I've gotten past that, but still cannot update the table. XP Pro...
0
by: PaulB | last post by:
Hi there, Allthough I searched for previous posts, I was unable to solve my problem. I try to link my front-mdb with an Excel file using the next line DoCmd.TransferSpreadsheet acLink, 8,...
0
by: mvdkwong | last post by:
I am trying to run a macro that will export a table into a fixed length file (see below). However, when I run it, I get the following error: "Cannot update. Database or object is read-only." I've...
0
by: tom | last post by:
When I try to read in a csv file it gives me this error message. 'Cannot update. Database or object is read-only.' If I change the extension to txt it processes just fine. I have googled all...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
1
by: sweetjos | last post by:
Thank you sir, I have another question.... Recently I got this error. Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80004005) Cannot update. Database or object is read-only....
5
by: asmi | last post by:
I am new in C# programming. Can anyone plz help me in the following problem. I am changing values in different columns in access database table using c# but these changes are only visible at run...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.