Jump to content

jrws

Members
  • Posts

    124
  • Joined

  • Last visited

    Never

Everything posted by jrws

  1. jrws

    News System

    Alright thanks for that, that helps a little, could you perhaps help me then with figuring out what records it would be for a user table and post id So for example id of user links to the post u_id But I want it so that it counts how many articles the user would of posted, so in that case how many times the same u_id appears. How would I do this? Would this be a join or a normal where clause?
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Central Valley Civic Center</title> </head> <body> <h1>Central Valley Civic Center</h1> <h2>Summer Concert Season</h2> <?php $Concerts = array ("Jimmy Buffet", "Chris Isaak", "Bonnie Raitt", "James Taylor", "Alicia Keys" ); $Concerts [ ] = "Bob Dylan" ; $Concerts [ ] = "Ryan Cabrera" ; $Concerts[2] = "Joe Cocker" ; $Concerts[3] = "Van Morrison" ; echo "<p>The following ", count($Concerts), " concerts are scheduled:</p><p>" ; echo "$Concerts[0] <br />"; echo "$Concerts[1] <br />"; echo "$Concerts[2] <br />"; echo "$Concerts[3] <br />"; echo "$Concerts[4] <br />"; echo "$Concerts[5] <br />"; echo "$Concerts[6] </p>"; ?> </body> </html> Note no space I hope this is what you wanted
  3. jrws

    News System

    I really don't think you quite understand what my delema is. I know what the joins are, but I don't know what the format for this situation would be for what I want, and I can't seem to find any information on it. Thanks again, I guess I will just have to look harder.
  4. jrws

    News System

    Yeah I know SQL joins, but I want someone to help me, for example telling me which would be the best join and why. I know what joins are, I just don't know how to use them. But thanks anyway.
  5. Hi guys I was wondering how I would implement the ability to see what posts a user has made. I would be thinking a join, but don't know which join to use, as they are confusing to me. Basically I want to make it so that when you are on the users page, it will say stuff like: Username: blah Email: blah@blah.com Posts: number of posts, and or links to the posts Mind you I just want to test this thing out, because as soon as I understand how to do it I can perform other functions. So if anyone can explain in an easy way or help me that would be great. I have already looked at many tutorials about left joins and right joins and joins in general. However like I have stated, I don't know how to use them properly.
  6. Thanks mate, thought it might be that
  7. Hey there guys, I was wondering, how would I be able to add the id of a news post AS SOON AS its posted? I know how to retrieve the data after it is posted, but how would I be able to link the stuff, IE give the user two links: View the news (link 1) View your posted news (link 2) In link 2 it would look something like: http://example.com/full_news.php?id= Where the id would be the recently posted. I really hope I have made this clear, if not please tell me and hopefully I will be able to explain.
  8. For some reason there is no edit button. Anyway, I found an answer to my problem although it is not exactly what I desired; Include config and functions separately. This is all I needed to change, however I still don't understand what was wrong, so I would still appreciate an answer. Thanks for you help -James-
  9. I have just tested those three files renaming them and making the in the same directory, and now it works fine. Can someone please explain?
  10. That's because I had made functions in the folder lib along with config.
  11. That is the whole error: The finding of the code.
  12. For some reason there wasn't an edit button I could find for the first post, so instead I will just paste the three files; config.php <?php $host = 'localhost'; $db = 'new_news_system'; $user = 'root'; $pass = ''; $siteURL = 'http://localhost/news_system/'; $connect = mysql_connect($host,$user,$pass)or die(mysql_error()); $db = mysql_select_db($db,$connect)or die(mysql_error()); ?> functions.php <?php session_start(); require_once ('config.php'); //Functions function encrypt($x, $salt = null) { //Simply encrypts a string using md5 and sha1 if ($salt == null) { $x = md5(sha1($x)); return $x; } else { $x = md5(sha1($x . $salt)); return $x; } } function clean($string) { if (get_magic_quotes_gpc()) { $string = stripslashes($string); } elseif (!get_magic_quotes_gpc()) { $string = addslashes(trim($string)); } $string = trim($string); $string = escapeshellcmd($string); $string = mysql_real_escape_string($string); $string = stripslashes(strip_tags(htmlspecialchars($string))); return $string; } function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function usernameExists($user){ $mysql_query = "SELECT * FROM user WHERE username = '$user'"; $mysql_result = mysql_query($mysql_query)or die('Error: '.mysql_error()); if(mysql_num_rows($mysql_result)>0){ return true; }else{ return false; } } function activationEmail($email,$code){ $to = $email; $sub = 'Activation at NewsSystem'; $mes = 'Hello there, welcome to News-System!<br>'; $mes .= 'So the first step is to activate your account, so that you may login.'; $mes .='\n Go to this adress:\n'; $mes .='<a href="'.$siteURL.'/register?activate='.$code.'"'; $send = mail($to,$sub,$mes,$headers); if(!$send){ return false; }else{ return true; } } ?> register.php <?php //Register page Will have ajax eventually include_once 'lib/functions.php'; ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Register</title> <link rel="stylesheet" type="text/css" href="lib/default.css"> </head> <body><div class="holder"><? if ($_SESSION['username'] != '') { echo 'You are already logged in!'; } else{ if (isset($_GET['code'])) { $code = clean($_GET['code']); $query = "SELECT code FROM user WHERE code = '$code'"; echo $query; $resultA= mysql_query($query)or die(mysql_error()); if (mysql_num_rows($resultA)>0) { $query = "UPDATE user SET u_level = 1, code ='' WHERE code = '$code' "; $resultQuery = mysql_query($query) or die(mysql_error()); if ($resultQuery) { echo 'Successfully activated, <a href="' . $siteURL . '/login.php">login</a>'; } else{ echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>'; } } else{ echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>'; } ?> <? } } ?></div> </body></html> Please note this is a testing server, and as such I haven't changed the user name and password information. EDIT: No I am not.
  13. Can someone help me with this error? I am trying to make an activate account page and ever time I attempt to test it I get the error that no database is selected. I have checked all my files, the database exists, I am using XAMPP. Please tell me what files you want, because I don't know what to post. Here are all the files so far that I am using: config.php functions.php register.php
  14. It isn't dying anywhere in the config, so I can't figure it out... I will have to look at my code again, but at the moment I am just a tad busy XD School sometimes takes out the fun of coding.
  15. <?php $host = '*****'; $db = '*****'; $user = '*****'; $pass = '*****'; $siteURL = '*****/news_system/'; $connect = mysql_connect($host,$user,$pass)or die(mysql_error()); $db = mysql_select_db($db)or die(mysql_error()); $send_email = 0; ?>
  16. Database could not be found (And yet if I test the config file everything is A ok in there...)
  17. Thats the exact same page, I am using PHP designer and it automatically makes a temp file for testing on localhost, it hasn't ever interfered before... edit: Found the problem, for some reason the file hadn't saved when I changed some info so what was happening was config was calling functions, and functions was calling config, personally I didn't think that would of been the problem since I said require_once but I guess it must of been. Thanks for your help. However I think I still get the mysql_error, heres the code, and I have only comented out or die() because I wanted to see what was killing it. <?php //Register page Will have ajax eventually require_once ('lib/functions.php'); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Register</title> <link rel="stylesheet" type="text/css" href="lib/default.css"> </head> <body><div class="holder"><? if ($_SESSION['username'] != '') { echo 'You are already logged in!'; } else{ echo safePassword('Test'); if (isset($_GET['activate'])) { $code = clean($_GET['activate']); $query = "SELECT code FROM user WHERE code = '$code'"; $resultA= mysql_query($query);//or die(mysql_error()); if (mysql_num_rows($resultA)>0) { $query = "UPDATE user SET u_level = 1, code ='' WHERE code = '$code' "; $resultQuery = mysql_query($query);// or die(mysql_error()); if ($resultQuery) { echo 'Successfully activated, <a href="' . $siteURL . '/login.php">login</a>'; } else{ echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>'; } } else{ echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>'; } ?> <? } } ?></div> </body></html>
  18. Ok then thanks for that one, I thought there wasn't because it has never spat that error before when I used the same name... Edit: I just changed the name to safePassword and I get the same error
  19. Alright here's the problemo, so I am trying to make a register page, and it keeps giving the error database is not selected, so if I remove or die from the query it says So I see if my function file works (it does) but then when I test to see if there are any errors from the functions I get this error: So here is the functions page: <?php session_start(); require_once ('config.php'); //Functions function encrypt($x, $salt = null) { //Simply encrypts a string using md5 and sha1 if ($salt == null) { $x = md5(sha1($x)); return $x; } else { $x = md5(sha1($x . $salt)); return $x; } } function clean($string) { if (get_magic_quotes_gpc()) { $string = stripslashes($string); } elseif (!get_magic_quotes_gpc()) { $string = addslashes(trim($string)); } $string = trim($string); $string = escapeshellcmd($string); $string = mysql_real_escape_string($string); $string = stripslashes(strip_tags(htmlspecialchars($string))); return $string; } function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function usernameExists($user){ $mysql_query = "SELECT * FROM user WHERE username = '$user'"; $mysql_result = mysql_query($mysql_query)or die('Error: '.mysql_error()); if(mysql_num_rows($mysql_result)>0){ return true; }else{ return false; } } function activationEmail($email,$code){ $to = $email; $sub = 'Activation at NewsSystem'; $mes = 'Hello there, welcome to News-System!<br>'; $mes .= 'So the first step is to activate your account, so that you may login.'; $mes .='\n Go to this adress:\n'; $mes .='<a href="'.$siteURL.'/register?activate='.$code.'"'; $send = mail($to,$sub,$mes,$headers); if(!$send){ return false; }else{ return true; } } ?> Can't figure out what its problem is, this should all be working, but it isn't so any help with this is appreciated, also if you need more code (such as the config) please ask as I did not know what to include.
  20. Alright thanks mate, will take it into consideration. BTW here is the revised code with sessions, now I keep getting the error of the data being empty even when not, however if I remove that line, everything works again. <? session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Install New News System</title> <style type="text/css"> *{ margin: 0; padding: 0; } body{ background: #1f1f1f; font-family: tahoma; font-size: 10px; color: #D6D6D6; text-align: center; } a{ letter-spacing: 1px; text-decoration: none; color: #BBBBBB; } a:hover{ text-decoration: underline; color: #D6D6D6; } ul{ margin:0; padding:0; list-style:none; } #logo{ float: right; height:396px ; width: 200px; margin-right: 25px; padding: 15px; border: solid 2px #575757; background: #3C3C3C; text-align:left ; } .holder{ width: 500px; margin: 0 auto; text-align: left; border: solid 2px #575757; padding: 3px; background: #3C3C3C; margin-top: 5px; max-height:36em; } #header{ height:60px ; width: 500px; margin-bottom: 150px auto; padding-bottom: 2px; border-bottom: solid 2px #575757; background: #3C3C3C; text-align:center ; } #footer{ height:60px ; width: 500px; margin-top: 150px auto; padding-top: 2px; border-top: solid 2px #575757; background: #3C3C3C; text-align:center ; } .error{ color:#C93838; text-align:center; } </style> </head> <body><div class="holder"> <?php //Install Page// //This writes to the configuration file and updates or creates the tables nessessary to function. //Inserts administrator into the fix as well //Creates the index file //Self deleting. (finished version); $x = $_GET['x']; switch ($x) { default: { if (!isset($_POST['submit'])) { ?> <p>Welcome to the installer. This file was created to make your life easier. So please don't abuse it </p><p>Below is a form, it requires your database information. If you don't have a password for you database, perhaps you should get one...</p> <form method="POST" action="<?php echo $PHP_SELF; ?>"> Database Name:<input type = "text" name="db_name" value="news_system" ><br> Database Host:<input type = "text" name="db_host" value="localhost"><br> Database password:<input type = "password" name="db_pass" ><br> Database user:<input type = "text" name="db_user" value="root"><br> <input type = "submit" name = "submit" value ="Submit"> </form> <?php } else { $_SESSION['name'] = $_POST['db_name']; $_SESSION['host'] = $_POST['db_host']; $_SESSION['pass'] = $_POST['db_pass']; $_SESSION['user'] = $_POST['db_user']; //Error check for the post: $name = $_SESSION['name']; $host = $_POST['host']; $pass = $_POST['pass']; $user = $_POST['user']; if (empty($name) || empty($host) || empty($user)) { ?><div class="error"> WARNING: You have not filled in one or more fields, please <a href="/news_system/install.php">go back</a></div> <? } else { echo '<a href="/news_system/install.php?x=1">Proceed to next step...</a>'; //echo '<meta http-equiv="refresh" content="1;url="/news_system/install.php?x=1">'; } } break; } case 1: { echo 'Testing connection now:<br>'; $q1 = mysql_connect($_SESSION['host'], $_SESSION['user'], $_SESSION['pass']) or die('Error: ' . mysql_error() . '<br>Query: ' . $q1 . '<br> <a href="/news_system/install.php">Go back</a>'); $q2 = mysql_select_db($_SESSION['name']) or die('Error: ' . mysql_error() . '<br>Query: ' . $q2 . '<br> <a href="/news_system/install.php">Go back</a>'); break; } } //} ?> </div> </body> </html>
  21. I thought that you didn't actually need sessions when you do it on the same page. So thanks for your help mate, I will try that and see if it works.
  22. To dezit; Yes I do. I will post the full code so you can have a look if you like. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Install New News System</title> <style type="text/css"> *{ margin: 0; padding: 0; } body{ background: #1f1f1f; font-family: tahoma; font-size: 10px; color: #D6D6D6; text-align: center; } a{ letter-spacing: 1px; text-decoration: none; color: #BBBBBB; } a:hover{ text-decoration: underline; color: #D6D6D6; } ul{ margin:0; padding:0; list-style:none; } #logo{ float: right; height:396px ; width: 200px; margin-right: 25px; padding: 15px; border: solid 2px #575757; background: #3C3C3C; text-align:left ; } .holder{ width: 500px; margin: 0 auto; text-align: left; border: solid 2px #575757; padding: 3px; background: #3C3C3C; margin-top: 5px; max-height:36em; } #header{ height:60px ; width: 500px; margin-bottom: 150px auto; padding-bottom: 2px; border-bottom: solid 2px #575757; background: #3C3C3C; text-align:center ; } #footer{ height:60px ; width: 500px; margin-top: 150px auto; padding-top: 2px; border-top: solid 2px #575757; background: #3C3C3C; text-align:center ; } .error{ color:#C93838; text-align:center; } </style> </head> <body><div class="holder"> <?php //Install Page// //This writes to the configuration file and updates or creates the tables nessessary to function. //Inserts administrator into the fix as well //Creates the index file //Self deleting. (finished version); $x = $_GET['x']; switch ($x) { default: { if (!isset($_POST['submit'])) { ?> <p>Welcome to the installer. This file was created to make your life easier. So please don't abuse it </p><p>Below is a form, it requires your database information. If you don't have a password for you database, perhaps you should get one...</p> <form method="POST" action="<?php echo $PHP_SELF; ?>"> Database Name:<input type = "text" name="db_name" value="news_system" ><br> Database Host:<input type = "text" name="db_host" value="localhost"><br> Database password:<input type = "password" name="db_pass" ><br> Database user:<input type = "text" name="db_user" value="root"><br> <input type = "submit" name = "submit" value ="Submit"> </form> <?php } else { $name = $_POST['db_name']; $host = $_POST['db_host']; $pass = $_POST['db_pass']; $user = $_POST['db_user']; if (empty($name) || empty($host) || empty($user)) { ?><div class="error"> WARNING: You have not filled in one or more fields, please <a href="/news_system/install.php">go back</a></div> <? } else { echo '<a href="/news_system/install.php?x=1">Proceed to next step...</a>'; //echo '<meta http-equiv="refresh" content="1;url="/news_system/install.php?x=1">'; } } break; } case 1: { if(isset($name)){ echo 'Testing connection now:<br>'; $q1 = mysql_connect($host, $user, $pass) or die('Error: ' . mysql_error() . '<br>Query: ' . $q1 . '<br> <a href="/news_system/install.php">Go back</a>'); $q2 = mysql_select_db($name) or die('Error: ' . mysql_error() . '<br>Query: ' . $q2 . '<br> <a href="/news_system/install.php">Go back</a>'); }else{ echo 'WTF?!'; } break; } } //} ?> </div> </body> </html>
  23. I don't really know what code to post, so please ask what sections you would like to see. Basically this is an install page. However for some reason none of the variables carry onto the next page. The below code is what I did for error checking: case 1: { if(isset($name)){ echo 'Testing connection now:<br>'; $q1 = mysql_connect($host, $user, $pass) or die('Error: ' . mysql_error() . '<br>Query: ' . $q1 . '<br> <a href="/news_system/install.php">Go back</a>'); $q2 = mysql_select_db($name) or die('Error: ' . mysql_error() . '<br>Query: ' . $q2 . '<br> <a href="/news_system/install.php">Go back</a>'); }else{ echo 'WTF?!'; } break; } You know what it returned? It returned 'WTF?!' Meaning for some reason the variable hasn't been set. If anyone wants me to I can display all the code, since its only like 200 or so lines, all on one page... But would anyone have any idea as to why a variable would not be set? I made sure that all the variable names were correct and that I did the $_POST correct, so I am now lost.
  24. Hey all, But your surprised that its not a problem XD. Well anyway, I have just completed a tutorial about a simple calendar, and I was wondering how would I make it highlight the current day? I was thinking using span tags, and an if, but it didn't work. (Crashed firefox XD) So here's the code, mind you I didn't edit anything 'cept for the center tag in the table. <?php $date = time(); $day = date('d', $date); $month = date('m', $date); $year = date('y', $date); $first_day = mktime(0, 0, 0, $month, 1, $year); $title = date('F', $first_day); $day_of_week = date('D', $first_day); switch ($day_of_week) { case 'Sun': $blank = 0; break; case 'Mon': $blank = 1; break; case 'Tus': $blank = 2; break; case 'Wed': $blank = 3; break; case 'Thu': $blank = 4; break; case 'Fri': $blank = 5; break; case 'Sat': $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year); echo '<table border = "6" width = "394">'; echo '<tr><th colspan ="60">' . $title . ' ' . $year . '</th></tr>'; echo '<tr><td width = "62">Su</td><td width = "62">M</td><td width = "62">Tu</td><td width = "62">W</td><td width = "62">Th</td><td width = "62">F</td><td width = "62">Sa</td></tr>'; $day_count = 1; echo '<tr>'; while ($blank > 0) { echo '<td></td>'; $blank -= 1; $day_count++; } $day_num = 1; while ($day_num <= $days_in_month) { echo '<td style="text-align:center">' . $day_num . '</td>'; $day_num++; $day_count++; if ($day_count > 7) { echo '</tr><tr>'; $day_count = 1; } } while ($day_count > 1 && $day_count <= 7) { echo '<td></td>'; $day_count++; } echo '</tr></table>'; ?> So any help with this is much appreciated! EDIT: Sorry just realized this would be classified as a third party script, so could a mod move it please?
×
×
  • 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.