PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old June 1st, 2009, 06:00 PM
neex1233 neex1233 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 16 neex1233 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 59 m 26 sec
Reputation Power: 0
php5 - Updating MySQL Through a PHP Form

Hi, I created a script that was supposed to update MySQL through a form. Here is my code:

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

It doesn't work, and no error comes up. What am I doing wrong?
Here is my form:

<form enctype="multipart/form-data" action="adm.php" name="frm1" method="POST">
ID to edit:<br>
<input type="text" name="username"><br />
New Password:<br>
<input type="text" name="password"><br />
Userlevel:<br>
<select id="select1" name="userlevel">
<option name="1" value="1">1</option>
<option name="2" value="2">2</option>
<option name="3" value="3">3</option>
<option name="4" value="4">4</option>
<option name="5" value="5">5</option>
<input type="checkbox" id="chk1" name="userlevel" onchange="javascript:toggleSelect();" value="0" /> Banned
</select>
<br>
<input type="submit" name="edit" value="Update"></form>[/PHP]

I don't think it is a problem with the form, unless it is the button. What do you think is wrong? Thanks!

Reply With Quote
  #2  
Old June 1st, 2009, 08:27 PM
skullzy's Avatar
skullzy skullzy is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: belfast
Posts: 108 skullzy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 10 m
Reputation Power: 3
first of all you have the right idea but you need to tell the scriipt that your submiting the information because if you dont then it will just do nothing you need to do something like this

PHP Code:
 error_reporting(E_ALL);
ini_set("display_errors""on");

$con mysql_connect("localhost","username","password");
mysql_select_db("db_name"$con);

if (isset(
$_POST['edit'])) { //if you hit edit then do the fallowing

$sql "UPDATE users SET username = '{$_POST['username']}', password = '{$_POST['password']}', userlevel = '{$_POST['userlevel']}'
WHERE `id` = '23' LIMIT 1"
;

mysql_query($sql) or die (mysql_error());




there is also no point in having LIMIT 1 in there because you are only updating a table in your SQL your not selecting information to be shown

so you have a choice now with your code you can have it all on one page or have it on seperate pages for example this will work

PHP Code:
<?PHP
error_reporting
(E_ALL);
ini_set("display_errors""on");

$con mysql_connect("localhost","username","password");
mysql_select_db("db_name"$con);
?>

<form name="frm1" method="POST">
ID to edit:<br>
<input type="text" name="username"><br />
New Password:<br>
<input type="text" name="password"><br />
Userlevel:<br>
<select id="select1" name="userlevel">
<option name="1" value="1">1</option>
<option name="2" value="2">2</option>
<option name="3" value="3">3</option>
<option name="4" value="4">4</option>
<option name="5" value="5">5</option>
</select>
<input type="checkbox" id="chk1" name="userlevel" onchange="javascript:toggleSelect();" value="0" /> Banned
<br>
<input type="submit" name="edit" value="Update"></form>

<?PHP
if (isset($_POST['edit'])) {

$sql "UPDATE users SET username = '{$_POST['username']}',password = '{$_POST['password']}',userlevel = '{$_POST['userlevel']}'
WHERE id = 23
LIMIT 1"
;

mysql_query($sql) or die (mysql_error());

}
?>


or you can have them on seperate pages what ever floats ya boat

hope this helps
__________________
the best way to learn
1. check the site because it rules
2. search your functions up on php.net
3. surf the web google.com
4. lookup tutorials tutorialized.com

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php5 - Updating MySQL Through a PHP Form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
Stay green...Green IT