SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
-
Jun 9, 2007, 11:43 #1
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No Errors(?) + Not working; //Register script
Okay I have tested that all the values are working from form on another page. The thing just isn't updating db.. why is this?
PHP Code:<?php
require 'config.php';
$result = mysql_query('SELECT * FROM users') or die('Could not gather info: ' . mysql_error());
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$password = sha1($_POST['password']);
$ip = $_SERVER['REMOTE_ADDR'];
$registered = date("F j, Y, g:i a");
//print_r($_POST);
//echo $ip, $registered;
$query = 'INSERT INTO users (username, password, registration_date, user_ip) VALUES('.$username.', '.$password.', '.$registered.', '.$ip.')';
$result = mysql_query($query);
/*else
{
echo 'This email adress has already been registered.';
}*/
}
else
{
echo 'Die Hacking Attempt!';
}
//echo $username, $password, $ip, $registered;
?><3php && SitePoint ?>
-
Jun 9, 2007, 12:17 #2
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Have you done a or die(mysql_error()) on the $result query and what does the sql look like when you print it?
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jun 9, 2007, 12:20 #3
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
When I print the array info... it looks like
Array ( [username] => name [password] => pass [password2] => pass [submit] => submit ) 127.0.0.1June 9, 2007, 3:19 pm
and thats using the lines
print_r($_POST);
echo $ip, $registered;<3php && SitePoint ?>
-
Jun 9, 2007, 12:25 #4
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
sorry, I meant on the query line:
PHP Code:$result = mysql_query($query) or die(mysql_error());
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jun 9, 2007, 12:25 #5
- Join Date
- Aug 2005
- Posts
- 453
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Where did you connect to the database?
Where did you select the database?Computers and Fire ...
In the hands of the inexperienced or uneducated,
the results can be disastrous.
While the professional can tame, master even conquer.
-
Jun 9, 2007, 12:28 #6
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<3php && SitePoint ?>
-
Jun 9, 2007, 12:29 #7
- Join Date
- Aug 2005
- Posts
- 453
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Did you make those variables global?
Ever heard of scope?Computers and Fire ...
In the hands of the inexperienced or uneducated,
the results can be disastrous.
While the professional can tame, master even conquer.
-
Jun 9, 2007, 12:34 #8
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No please explain? I have been wondering because I'm going to need ppl to stay logged in while they visit various parts of a website.
spikeZ look at the problem with query
Problem with query: 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 '9, 2007, 3:36 pm, 127.0.0.1)' at line 1
field: registration_date type: datetime; no other special attributes.<3php && SitePoint ?>
-
Jun 9, 2007, 12:55 #9
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Datetime expects the date format YYYY-MM-DD not a humanised form.
You can manipulate the date as you get it from the database.
You can simply use NOW() in your query to put the date time into the correct formatMike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jun 9, 2007, 13:04 #10
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks again spikeZ!
I can't find now() in the php manual.
What would I put inside of the brackets?
I should mention that it needs to work for php 4.4.4<3php && SitePoint ?>
-
Jun 9, 2007, 13:10 #11
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Your query would look like:
PHP Code:$query = "INSERT INTO users (username, password, registration_date, user_ip) VALUES('".$username."', '".$password."', NOW(), '".$ip."')";
$result = mysql_query($query);
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jun 9, 2007, 13:12 #12
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OH, okay, I didn't realize it was a specific thing to mysql.
<3php && SitePoint ?>
-
Jun 9, 2007, 13:14 #13
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jun 9, 2007, 13:22 #14
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here is how information is being put into db
user_id: 1 username: name password: 9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684 date&time: 2007-06-09 16:18:52 ip adress: 127
For 127.0.0.1 will it always show ip as 127?
It seems to be working.. except when I access the script not using the form it gives me an unexpected $end, even though all brackets are closed.
Here is the new code:
PHP Code:<?php
require 'config.php';
$result = mysql_query('SELECT * FROM users') or die('Could not gather info: ' . mysql_error());
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$password = sha1($_POST['password']);
$password2 = sha1($_POST['password2']);
$ip = $_SERVER['REMOTE_ADDR'];
$registered = date("F j, Y, g:i a");
if ($password == $password2)
{
$query = $query = "INSERT INTO users (username, password, registration_date, user_ip) VALUES('".$username."', '".$password."', NOW(), '".$ip."')";
$result = mysql_query($query) or die('Problem with query: ' . mysql_error());
}
}
else
{
echo 'Die Hacking Attempt!';
}
?><3php && SitePoint ?>
-
Jun 9, 2007, 13:46 #15
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
The IP address it is picking up is your Localhost address which is always 127.0.0.1. Once the script is on a server it should be ok and pick up the users IP addy.
As for the brackets it must be something other than the snippet you posted as they do indeed all balance.Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jun 9, 2007, 14:28 #16
- Join Date
- Mar 2007
- Location
- Ottawa, Ontario!
- Posts
- 149
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That is the entire code of the file. I am assuming it is something to do with WAMP or my comp where it is caching or something.
<3php && SitePoint ?>
Bookmarks