TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-14-2009, 04:07 PM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default Can you find the mistake in this code

<?php

$username = $_POST['username'];
$password = md5($_POST['password']);

$connect = mysql_connect("localhost","prashant_shankar","shan kar") or die ("Couldn't connect");
mysql_select_db("prashant_inspirations") or die("Couldn't find db");

$query1 = mysql_query("INSERT INTO `prashant_inspirations`.`user_acc` (`uid` ,`username` ,`password`) VALUES(NULL , `$username`,`$password`)") or die ("Couldn't update in user");

mysql_query($query1);

?>

The DBname is perfect, it shows that it cant update user table, anything wrong in the syntax , can u correct me.Thanks in advance.
__________________
--
Regards
Shankar
shankar is offline  
Reply With Quote
Old 04-14-2009, 04:44 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

The following or die will help you to ascertain what the problem is specifically. Run this code and please tell us what the problem is according to MySQL, if you can't figure it out.

php Code:
$query1 = mysql_query("INSERT INTO `prashant_inspirations`.`user_acc` (`uid` ,`username` ,`password`) VALUES(NULL , `$username`,`$password`)") or die (mysql_error());
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
shankar (04-14-2009)
Old 04-14-2009, 04:52 PM   #3 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default

This is to insert a new row so that people can register to login to diff pages.i complied the page and i got this error when i entered new username to be added.

Unknown column 'shankar' in 'field list'

where shankar was the new username to be added.Given as an input thru textbox.
__________________
--
Regards
Shankar
shankar is offline  
Reply With Quote
Old 04-14-2009, 04:55 PM   #4 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

It's an SQL error, you should take a look at this:

http://www.w3schools.com/sql/sql_insert.asp
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
The Following User Says Thank You to ETbyrne For This Useful Post:
shankar (04-14-2009)
Old 04-14-2009, 06:01 PM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You're using backticks (`) to wrap the username/password strings in the VALUES portion of the query: use quotes instead.

Also, if your uid column is an auto-incrementing primary key, there is no need to include it in the query at all.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
shankar (04-14-2009)
Old 04-14-2009, 06:12 PM   #6 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default

but still its not working....i made the following changes

<?php

$username = $_POST['username'];
$password = md5($_POST['password']);
$type= "Guest";


$connect = mysql_connect("localhost","root","") or die ("Couldn't connect");
mysql_select_db("inspirations") or die("Couldn't find db");


$query1 = mysql_query("INSERT INTO `school_inspirations`.`user_acc` (`username` ,`password`,'type') VALUES ( '$username','$password','$type')") or die ("Couldn't update in user");

mysql_query($query1);

?>

error
Couldn't update in user

<?php

$username = $_POST['username'];
$password = md5($_POST['password']);
$type= "Guest";


$connect = mysql_connect("localhost","root","") or die ("Couldn't connect");
mysql_select_db("inspirations") or die("Couldn't find db");


$query1 = mysql_query("INSERT INTO `school_inspirations`.`user_acc` (`username` ,`password`,'type') VALUES ( '$username','$password','$type')") or die (mysql_error());

mysql_query($query1);

?>

error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''type') VALUES ( 'adsfa','912ec803b2ce49e4a541068d495ab570','Guest' )' at line 1
__________________
--
Regards
Shankar
shankar is offline  
Reply With Quote
Old 04-14-2009, 06:18 PM   #7 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default

Thank you everyone.. i found it..thank you
__________________
--
Regards
Shankar
shankar is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tips to Improve Your Coding and Projects Village Idiot Tips & Tricks 45 12-03-2012 07:46 AM
Writing Clean Code Village Idiot Tips & Tricks 10 06-25-2012 12:35 PM
I love maintaining legacy code (priceless snippet of ASP code) Village Idiot The Lounge 10 04-03-2009 09:20 PM
help with object code planepixel Absolute Beginners 12 02-03-2009 01:38 PM
Snipply.com - Code snippet website codyodell Show Off 27 04-13-2008 02:09 PM


All times are GMT. The time now is 07:31 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design