Current location: Hot Scripts Forums » Programming Languages » PHP » Updating MySQL Through a PHP Form


Updating MySQL Through a PHP Form

Reply
  #1 (permalink)  
Old 06-01-09, 03:45 PM
neex1233 neex1233 is offline
New Member
 
Join Date: Jun 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Updating MySQL Through a PHP Form

This script that I made updates MySQL through a form. Here's my code:

PHP Code:

    <?php
    error_reporting
(E_ALL);
    
ini_set("display_errors""on");
    
$con mysql_connect("localhost","My_Username","Password");
    
mysql_select_db("My_Database"$con);
    
$sql "UPDATE users SET username = '{$_POST['username']}',password = '{$_POST['password']}',userlevel = '{$_POST['userlevel']}'
    WHERE id = 23
    LIMIT 0"
;
    
mysql_query($sql) or die (mysql_error());
    
?>

It's supposed to update the userlevel and password values in the table 'users', but it never works! Here's the form:

HTML Code:
    <form enctype="multipart/form-data" action="adm.php" method="POST">
    Username to edit:<br> <input type="text" name="username"><br />
    New Password:<br> <input type="text" name="password"><br />
    Userlevel:<br> <input type="radio" name="userlevel" value="1" /> 1
    <input type="radio" name="userlevel" value="2" /> 2
    <input type="radio" name="userlevel" value="3" /> 3
    <input type="radio" name="userlevel" value="4" /> 4
    <input type="radio" name="userlevel" value="5" /> 5
    <br>
    <input type="submit" name="edit" value="Update"></form>

I think it might be the button, but I doubt it. Please help! I've tried so many different things! Thanks!

Last edited by Nico; 06-01-09 at 04:00 PM.
Reply With Quote
  #2 (permalink)  
Old 06-01-09, 04:03 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Not sure how this actually behaves, but:
PHP Code:

" ... LIMIT 0"
... would limit the number of rows to update to 0. Try LIMIT 1.
Reply With Quote
  #3 (permalink)  
Old 06-01-09, 04:22 PM
neex1233 neex1233 is offline
New Member
 
Join Date: Jun 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
No

It still doesn't work.
Reply With Quote
  #4 (permalink)  
Old 06-01-09, 04:48 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
PHP Code:

$sql "UPDATE users SET username = '($_POST['username'])',password = '($_POST['password'])',userlevel = '($_POST['userlevel'])'
    WHERE id = '23'"

You can also remove the enctype from your form, not sure you need it for the form fields you're using.
Reply With Quote
  #5 (permalink)  
Old 06-01-09, 05:15 PM
neex1233 neex1233 is offline
New Member
 
Join Date: Jun 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
The sql variable you made just gave me a syntax error. Is the button right, because I think there might be a problem with it.
Reply With Quote
  #6 (permalink)  
Old 06-01-09, 05:48 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Try this ....

PHP Code:


    <?php
    $username 
$_POST['username'];
    
$password $_POST['password'];
    
$userlevel $_POST['userlevel'];
    
error_reporting(E_ALL);
    
ini_set("display_errors""on");
    
$con mysql_connect("localhost","My_Username","Password");
    
mysql_select_db("My_Database"$con);
    
$sql "UPDATE users SET username = '$username', password = '$password', userlevel = '$userlevel'
    WHERE id = '23'"
;
    
mysql_query($sql) or die (mysql_error());
    
?>
Reply With Quote
  #7 (permalink)  
Old 06-01-09, 08:36 PM
neex1233 neex1233 is offline
New Member
 
Join Date: Jun 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
No, doesn't work. Is there some kind of service that I have to turn on?
Reply With Quote
  #8 (permalink)  
Old 06-02-09, 03:29 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Do you get any errors? Or just a blank page?

Is there actually a row in the database with the ID = 23
Reply With Quote
Reply

Bookmarks

Tags
mysql, not working, php, update


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP or PHP which is better? nepala The Lounge 9 07-14-10 05:48 AM
PHP not recognizing admin in MySQL gizelle Database 3 04-15-07 08:39 PM
PHP Programmer - Form Metic Job Offers & Assistance 13 06-29-06 07:03 AM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 03:06 AM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 10:56 AM


All times are GMT -5. The time now is 08:36 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.