Jump to content

scrap0346

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Everything posted by scrap0346

  1. [quote author=kenrbnsn link=topic=120240.msg493019#msg493019 date=1167367581] In this echo statement: [code]<?php             echo 'You aren't logged in. Please <a href="register.php">register[/url] or <a href="login.php">log in.[/url]'; ?>[/code] you have a single quote inside a string that is delimited by a single quote which effectively ends the string so PHP doesn't know what to make of the rest of the string. I would write it like this: [code]<?php             echo "You aren't" . ' logged in. Please <a href="register.php">register[/url] or <a href="login.php">log in.[/url]'; ?>[/code] Other people would probably code it differently. Ken [/quote] hey thanks man. i can't believe i spent all that time on a stupid single quotation mark. now i'm feeling kinda stupid. thanks again!
  2. I'm new to PHP and I'm trying to understand the basics of user authentication.  I have a book on PHP and they give the example: [code]<?php   $name = $_POST['name'];   $password = $_POST['password'];   if(!isset($_POST['name'])&&!isset($_POST['password']))   {     //Visitor needs to enter a name and password ?>   <h1>Please Log In</h1>   This page is secret   <form method="post" action="secretdb.php">   <table border="1">   <tr>     <th> Username </th>     <td> <input type="text" name="name"> </td>   </tr>     <th> Password </th>     <td> <input type="password" name="password"> </td>   </tr>   <tr>     <td colspan="2" align="center">       <input type="submit" value="Log In">     </td>   </tr>   </table>   </form> <?php   }   else   {   // connect to mysql   $mysql = mysqli_connect( 'localhost', 'mikemeye_webauth', 'webauth' );   if(!$mysql)   {     echo 'Cannot connect to database.';     exit;   }   // select the appropriate database   $selected = mysqli_select_db( $mysql, 'auth' );   if(!$selected)   {     echo 'Cannot select database.';     exit;   }   // query the database to see if there is a record which matches   $query = "select count(*) from authorized_users where             name = '$name' and             password = '$password'";   $result = mysqli_query( $mysql, $query );   if(!$result)   {     echo 'Cannot run query.';     exit;   }   $row = mysqli_fetch_row( $result );   $count = $row[0];   if ( $count > 0 )   {     // visitor's name and password combination are correct     echo '<h1>Here it is!</h1>';     echo 'I bet you are glad you can see this secret page.';   }   else   {     // visitor's name and password combination are not correct     echo '<h1>Go Away!</h1>';     echo 'You are not autorized to view this resource.';   } } ?>[/code] but when I run this, I get the error: Fatal error: Call to undefined function: mysqli_connect() in /home/mikemeye/public_html/test/secretdb.php on line 32 I did have to manually add the database ("auth"), the username ("mikemeye_webauth"), and password ("webauth") because the script the book gave me didn't work.  Any help would be appreciated.  Thanks!
  3. I'm trying to setup a simple authentication for users but I keep getting this error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/mikemeye/public_html/test/index.php on line 32 I'll admit I copied and pasted this code from a PHP forum, but I do understand HTML and the fuctions that are in the code, I'm just still working on the syntax of the functions.  Any help would be appreciated.  Thanks! here's the code: <?php session_start(); require_once('connect.php'); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Index</title> <style type="text/css"> .container {   text-align: center;   border: 1px solid #000000;   width: 300px; } td {   text-align: left; } </style> </head> <body> <table class="container" align="center" cellspacing="0" cellpadding="0">   <tr>       <td colspan="2" style="text-align:center;"><h1>Index</h1></td>   </tr>   <tr>       <td colspan="2" style="text-align:center;">         <?php         if(isset($_SESSION['username'])) {             $data = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `username`="'.$_SESSION['username'].'"'));             echo 'You are logged in, '.$_SESSION['username'].'. <br /><br />Your last log in was '.date('l, F j, Y', $data['last_seen']).' <br /><br />You registered '.date('l, F j, Y', $data['date_registered']).'<br /><br /><a href="logout.php">Click here to logout</a>';         }else{             echo 'You aren't logged in.<br /><br />Please <a href="register.php">register</a> or <a href="login.php">log in.</a>';         }         ?>       </td>   </tr> </table> </body> </html> (connect.php just connects to the mysql database, it was just easier to put it in a separate .php file than have to rewrite it each time)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.