TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Can you find the mistake in this code (http://www.talkphp.com/absolute-beginners/4135-can-you-find-mistake-code.html)

shankar 04-14-2009 04:07 PM

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.

Wildhoney 04-14-2009 04:44 PM

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());

shankar 04-14-2009 04:52 PM

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.

ETbyrne 04-14-2009 04:55 PM

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

http://www.w3schools.com/sql/sql_insert.asp

Salathe 04-14-2009 06:01 PM

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.

shankar 04-14-2009 06:12 PM

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

shankar 04-14-2009 06:18 PM

Thank you everyone.. i found it..thank you


All times are GMT. The time now is 12:41 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0