Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Updating SQL through form
Old 12-14-2010, 07:26 AM Updating SQL through form
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
Hi,

I'm learning PHP. I was trying to update SQL Database through PHP form.

PHP Code:
<?php

/* Opens Connection to mysql server */

$dbc mysql_connect('localhost''root''admin');
 if (!
$dbc){
           die (
"Not Connected : "  mysql_error());
           }
         
/* Selecting a database */

$db_selected mysql_select_db ("local"$dbc);

 if (!
$db_selected) {
                    die (
"Cant Connect :" mysql_error());  
                    }

/* Updating Data in table */

$new_username $_POST["name"];

$query="UPDATE profile SET username='$new_username' WHERE id='1'";
$result=mysql_query($query);

echo 
'<form method="post" action="'.$SERVER['PHP_SELF'];'">';

echo 
'<input type="text" name="name" value="" />';

echo 
'<input type="submit" value="Update" /></form>';

?>
Also what is the use of $Server. I guess it is for same page submission...

Teach me PHP
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
 
Register now for full access!
Old 12-14-2010, 11:23 AM Re: Updating SQL through form
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
$_SERVER (note the underscore) is a superglobal. See http://www.php.net/manual/en/reserve...les.server.php for details. On your form you have a field with name="name" -- don't use a reserved word for a name eg put name="my_name" or whatever. You have no control logic in your form -- check on entry if this is a submission and then conect to the db etc, else display the for,
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-15-2010, 04:39 AM Re: Updating SQL through form
Banned

Posts: 2
Trades: 0
An informative thread it is
Its really an admirable post, keep it up
bra12vo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Updating SQL through form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.57039 seconds with 12 queries