| | |
Update database issue
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 2
Reputation:
Solved Threads: 0
Hi! First of all to say that I am a newbie in PHP world. I have a table in a database and I am trying to update a row's content based on its id that I get inside the page's link.
But the update never occurs. Please help. I can't see what's wrong.
Thanks.
But the update never occurs. Please help. I can't see what's wrong.
Thanks.
php Syntax (Toggle Plain Text)
<?php // Connects to your Database mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("bestcv") or die(mysql_error()); $pno=$_GET['pno']; if(isset($_COOKIE['bestupt'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['bestupt']; $pass = $_COOKIE['bestupt_pass']; $check = mysql_query("SELECT * FROM bestupt_login WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password'] || $info['auth'] != 0) { header("Location: login.php"); } //otherwise they are shown the admin area else if($info['auth']==0) { //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['name'] | !$_POST['surname'] | !$_POST['position'] ) { die('You did not complete all of the required fields'); } // now we insert it into the database $pos = $_POST['position']; $board = 0; if($pos == 'Voting Member') { $board = 1; } else if($pos == 'Secretary') { $board = 2; } else if($pos == 'Treasurer') { $board = 3; } else if($pos == 'MK Vicepresident') { $board = 4; } else if($pos == 'HR Vicepresident') { $board = 5; } else if($pos == 'President') { $board = 6; } $add=mysql_query("UPDATE people SET name='".$_POST['name']."', surname='".$_POST['surname']."', position='".$_POST['position']."', photo='".$_POST['photo']."', board='".$board."' WHERE pno='".$pno."' ")or die(mysql_error()); ?> <h1>Member added</h1> <a href="admin.php">Back</a> <? } else { $usertoedit = mysql_query("SELECT * FROM people WHERE pno = '".$pno."'")or die(mysql_error()); $info = mysql_fetch_array($usertoedit); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Name:</td><td> <input type="text" name="name" value="<?php echo $info['name']; ?>" maxlength="60"> </td></tr> <tr><td>Surname:</td><td> <input type="text" name="surname" value="<?php echo $info['surname']; ?>" maxlength="60"> </td></tr> <tr><td>Position:</td></tr> <tr><td> <input type="radio" name="position" value="Alumnus">Alumnus<br> <input type="radio" name="position" value="Member">Member<br> <input type="radio" name="position" value="Former Member">Former Member<br> <input type="radio" name="position" value="Voting Member">Voting Member<br> <input type="radio" name="position" value="HR Vicepresident">HR Vicepresident<br> <input type="radio" name="position" value="MK Vicepresident">MK Vicepresident<br> <input type="radio" name="position" value="PR Responsible">PR Responsible<br> <input type="radio" name="position" value="President">President<br> <input type="radio" name="position" value="Secretary">Secretary<br> <input type="radio" name="position" value="Treasurer">Treasurer<br> </td></tr> <tr><td>Photo:</td><td> <input type="text" name="photo" value="<?php echo $info['photo']; ?>" maxlength="10"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="OK"></th></tr> </table> </form> <? } } } } ?>
•
•
Join Date: Apr 2008
Posts: 10
Reputation:
Solved Threads: 1
Not sure if it will work for you, but I usually add something like this before the submit button:
I am assuming that "pno" is the id of the content that should be updated.
PHP Syntax (Toggle Plain Text)
<input type="hidden" name="pno" value="<?php echo $pno; ?>" />
I am assuming that "pno" is the id of the content that should be updated.
Last edited by joshmac; Dec 27th, 2008 at 6:21 pm.
•
•
Join Date: Dec 2008
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Not sure if it will work for you, but I usually add something like this before the submit button:
PHP Syntax (Toggle Plain Text)
<input type="hidden" name="pno" value="<?php echo $pno; ?>" />
I am assuming that "pno" is the id of the content that should be updated.
Thanks very much. It works now
Last edited by pupsaa; Dec 27th, 2008 at 6:49 pm.
•
•
Join Date: Feb 2008
Posts: 30
Reputation:
Solved Threads: 4
•
•
•
•
<input type="radio" name="position" value="Alumnus">Alumnus<br>
<input type="radio" name="position" value="Member">Member<br>
<input type="radio" name="position" value="Former Member">Former Member<br>
<input type="radio" name="position" value="Voting Member">Voting Member<br>
<input type="radio" name="position" value="HR Vicepresident">HR Vicepresident<br>
<input type="radio" name="position" value="MK Vicepresident">MK Vicepresident<br>
<input type="radio" name="position" value="PR Responsible">PR Responsible<br>
<input type="radio" name="position" value="President">President<br>
<input type="radio" name="position" value="Secretary">Secretary<br>
<input type="radio" name="position" value="Treasurer">Treasurer<br>
[/code]
<input type="hidden" name="pno" value="<?php echo $pno; ?>" />
and also you have difficult programming structure in above quote.
<input type="radio" name="position" value="1">Voting Member<br>
At value property of each radio button insert its corresponding value like you have checked for 0,1,2,3,4,5,6.
Which will ease your task.
•
•
•
•
$add=mysql_query("UPDATE people SET name='".$_POST['name']."', surname='".$_POST['surname']."', position='".$_POST['position']."', photo='".$_POST['photo']."', board='".$board."' WHERE pno='".$_POST['pno']."' ")or die(mysql_error());
[/code]
Thanks & Regards
Dilip Kumar Vishwakarma
Dilip Kumar Vishwakarma
Programmer
.Net Consulting
If this post is answer for your query then don't forget to mark as an answer.
Programmer
.Net Consulting
If this post is answer for your query then don't forget to mark as an answer.
![]() |
Similar Threads
- insert and update data in two different database (JSP)
- Can't view browser emails(hotmail) or update windows (Troubleshooting Dead Machines)
- FlexGrid issue and error "Invalid Row value".... (Visual Basic 4 / 5 / 6)
- list box --php issue (PHP)
- Issue with phpBB & MySQL (Social Media and Online Communities)
- I need to trace or view that the stored proc is saving the data. (VB.NET)
- windows update can't download (Windows NT / 2000 / XP)
- How to call a ServerSide Script through Javascript (ASP.NET)
- need to update each records after record deleted (PHP)
- RDS Issue in Internet Explorer (ASP)
Other Threads in the PHP Forum
- Previous Thread: phpadmin v3.1
- Next Thread: date problem
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop open parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update upload url validation validator variable video web xml youtube





