Jump to content

Need small script checked please


beennn

Recommended Posts

I cant find what iv done wrong, every time i attempt to login with the correct details, im returned its incorrect

<?php$host="localhost";$username="username";$password="password";$db_name="dbname";$tbl_name="tblname"; mysql_connect("$host", "$username", "$password");mysql_select_db("$db_name");$myusername=mysql_real_escape_string($_POST['username']);$mypassword=mysql_real_escape_string($_POST['password']); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";$result=mysql_query($sql);$count=mysql_num_rows($result);if($count==1){  session_register("username");  session_register("password");  header("location:link.php");} else {  echo "Wrong Username or Password";}?>

Link to comment
Share on other sites

definitely there, i get errors when it comes to: session_register("username"); session_register("password");these are the errors:Warning: session_register() [function.session-register]: Cannot send session cookieWarning: session_register() [function.session-register]: Cannot send session cache limiterWarning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0not a clue what that means >.<

Link to comment
Share on other sites

Yeah. You should have mentioned you were getting errors first.You must call session_start() at the beginning of the page where you're using sessions.session_register() is deprecated. Just use the $_SESSION[] array. Here's an example of how to use it:

$_SESSION['username'] = "John Smith";

This won't affect anything but slight performance, but it's still something you need to know because if you don't then it may cause trouble some day. You don't need quotation marks when using variables:

// Quotation marksmysql_connect("$host", "$username", "$password");mysql_select_db("$db_name");// Better practise: no quotation marksmysql_connect($host, $username, $password);mysql_select_db($db_name);

Link to comment
Share on other sites

aaaah >.< thank you. and will do in future thanks.one more error after that >.<:Warning: Cannot modify header information - headers pointing to:header("location:link.php");
Make sure that there are no line breaks, spaces or tabs before the PHP code starts. The session_start() has to be the first thing on the page before any printable content.
Link to comment
Share on other sites

thank you for helping me >.<im, pretty confused now, on the same page as the code above; i need to have this at the very top of the page before anything else? <? session_start(); ?>is that all i need? if so its not making a difference >.<

Link to comment
Share on other sites

Yes, but make sure there's nothing before it, not even a space.You can put it in the same <?php ?> block as the rest of the code, but be sure that the <?php ?> block is the absolute first thing on the page.If it's not working, tell me what the error messages say.

Link to comment
Share on other sites

ok ill try that; but its ok to have them separated so long as the session_start is at the top of the page with nothing before it?
Yes. Anything between <?php ?> tags is OK.Actually, put the session_start() in the same block as the rest of your code. Any printable content before any of your code will cause an error because you have a header() function call, which also must be called before content is printed.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...