-3

Am hi guys currently am having problem updating my myqsl database I have a popup window the updates it there is no error but its not updating what the problem.

here is the popup window php code:

   <?php
session_start();
include("selectDB.php");
myconnection();



            if(isset($_POST['submit']))
            {
                        $myquery="update member set contactno='".$_POST['contactno']."',email='".$_POST['email']."',religion='".$_POST['religion']."',deptid='".$_POST['deptid']."',where memberid='".$_POST['mid']."'";
                        mysql_query($myquery);  


                        echo "Record has been saved.";


            }else{
                        $myquery="select * from member where memberid='".$_SESSION['memberid']."'";
                        $results=mysql_query($myquery);
                        $rs=mysql_fetch_array($results);
                    ?>
                        <form action="editacct.php"  method="post" align="left">
                        <input type="text" name="mid" size="30" value="<?php echo $rs['memberid'];?>" hidden /><br />
                        Contact Number:<br /> <input type="text" name="contactno" size="30" value="<?php echo $rs['contactno'];?>" /><br />
                        E-mail Adress:<br /> <input type="text" name="email" size="30" value="<?php echo $rs['email'];?>"/><br />
                        Religion:<br /> <input type="text" name="religion" size="30" value="<?php echo $rs['religion'];?>"/><br />
                        Address:<br /> <input type="text" name="address" size="30" value="<?php echo $rs['address'];?>"/><br />
                        Department:<br /><select name="deptid" value="<?php echo $rs['deptid'];?>"><br />
                                <option value="">Select</option>
                                <option value="CAH001">Development Communication</option>
                                <option value="CAH002">English</option>
                                <option value="CAH003">Filipino</option>
                                <option value="CAH004">Fine Arts</option>
                                <option value="CAH005">History and Social Sciences</option>
                                <option value="CAH006">Music</option>
                                <option value="CAH007">P.E</option>
                                <option value="CAH008">Psychology</option>
                                <option value="CAH006">Music</option>
                                <option value="CAH007">P.E</option>
                                <option value="CAH008">Psychology</option>
                                <option value="COB001">Accountancy</option>
                                <option value="COB002">Commerce</option>
                                <option value="COB003">Office Administration</option>
                                <option value="COD001">Dentistry</option>
                                <option value="COE001">Elementary Education</option>
                                <option value="COE002">Secondary Education</option>
                                <option value="COH001">Medical Laboratory</option>
                                <option value="COH002">Nutrition and Dietetics</option>
                                <option value="CON001">Nursing</option>
                                <option value="COT001">Theology</option>
                                <option value="CST001">Biology</option>
                                <option value="CST002">Chemistry</option>
                                <option value="CST003">Computer Science</option>
                                <option value="CST004">Computer Technology</option>
                                <option value="CST005">Library Science</option>
                                <option value="CST006">Math and Physics</option>
                                <input type="submit" name="submit" value="Update" />
                        </select>
                        <br />


                        </form>
                        <?php
            }
            ?>

this is the javascript of the popup:

    <script type="text/javascript">

function popup(){
  cuteLittleWindow = window.open("editacct.php", "", "width=700,height=500"); 
}

</script>

This is the link to show the popup

 <div class="clearfix grpelem" id="pu325-3"><!-- group -->
       <a class="nonblock nontext anim_swing clearfix grpelem" id="u325-3" href="javascript:popup()"><!-- content --><p>&nbsp;</p></a>


       <a class="nonblock nontext anim_swing clearfix grpelem" id="u333-6" href="javascript:popup()"><!-- content --><p>ACCOUNT</p><p>INFO</p></a>
 </div>
Kyle
  • 5
  • 5

1 Answers1

1

Remove the trailing comma just before you start the where clause:

deptid='".$_POST['deptid']."',where
                             ^ right there

Having used mysql_query($myquery) or die(mysql_error());

would have signaled the error.

I would like to note that your present code is open to SQL injection. Use mysqli with prepared statements, or PDO with prepared statements, they're much safer.



Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production.


Edit: (conversion from mysql_ to mysqli_, a basic method.

Change your present DB connection to the following.

This is an example taken from http://php.net/manual/en/function.mysqli-connect.php

<?php
$link = mysqli_connect("myhost","myuser","mypassw","mybd") 
        or die("Error " . mysqli_error($link));


// rest of your code

Then change mysql_query($myquery); to mysqli_query($link, $myquery);

$results=mysql_query($myquery); to $results=mysqli_query($link, $myquery);

$rs=mysql_fetch_array($results); to $rs=mysqli_fetch_array($results);

If you have any other functions that start with mysql_, they must be changed to mysqli_.

All mysqli_ functions require DB connection be passed as the first parameter.

This I did to help you out. If this still doesn't work, then I will simply delete this answer.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • i did that still it doesn't update it :( is it possible its not refreshing the window that why its not updating? – Kyle Jan 29 '15 at 01:52
  • @Kyle what's inside `selectDB.php` are you using `mysqli_` or PDO to connect with? Plus, add error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Jan 29 '15 at 01:53
  • @Kyle It seems you may also have spaces before your ` – Funk Forty Niner Jan 29 '15 at 01:54
  • @Kyle Another thing is where is `$_SESSION['memberid']` being assigned. If it's coming from another page, make sure that session variable isn't empty and that you've started the session in the other page it's coming from. Your update relies on it. – Funk Forty Niner Jan 29 '15 at 01:57
  • This is the Error : Deprecated:mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Applications/XAMPP/xamppfiles/htdocs/afsslatest/selectDB.php on line 6 what does that mean? – Kyle Jan 29 '15 at 01:59
  • That means that you have to convert your entire `mysql_` codes to `mysqli_` or PDO. Plus, that doesn't mean that you can simply change it to just adding an `i`. It means that all `mysqli_` functions require DB connection be passed as the first parameter. You can read up on it here http://php.net/manual/en/book.mysqli.php the entire manual is in the links on that page. My answer also contains links to those two APIs. – Funk Forty Niner Jan 29 '15 at 02:11
  • but i didn't convert it the code in my selectDB.php is `` and i use this code to connect to the database all the pages i didn't use `mysqli_` – Kyle Jan 29 '15 at 02:19
  • Re-read my previous comment carefully. @Kyle – Funk Forty Niner Jan 29 '15 at 02:23
  • @Kyle Reload my answer and look near the bottom under **Edit**. I've shown you what to do to convert it to `mysqli_`. The rest is up to you. Good luck. – Funk Forty Niner Jan 29 '15 at 03:17