
White_Lily
Members-
Posts
531 -
Joined
-
Last visited
-
Days Won
1
Everything posted by White_Lily
-
Okay... well how do i define the variable? I was under the impression that by including the varible in the function i would only have to do mysql_num_rows($result); etc...
-
Hi, i have just tried writing a function that when the needed variables are filled it will select that data from the database. Problem is is that the php.ini file is coming up with errors saying that the "$result" varible is undefined. Here's the code: <?php /*************************** *Connect to a database ***************************/ function connect(){ $host = $GLOBALS["host"]; $user = $GLOBALS["user"]; $pass = $GLOBALS["pass"]; $database = $GLOBALS["dbase"]; $con = mysql_connect($host, $user, $pass) or die("Could not connect."); $db = mysql_select_db($database) or die("Could not select database."); } /*************************** *Select data from database ***************************/ function select($amount = "*", $table, $where = NULL, $order = NULL, $limit = NULL){ $query = "SELECT ".$amount." FROM ".$table; if($where != NULL){ $query .= " WHERE ".$where; } if($order != NULL){ $query .= " ORDER BY ".$order; } if($limit != NULL){ $query .= " LIMIT ".$limit; } $result = mysql_query($query); } /*function bannerImage($imgLink, $image, $alt){ }*/ ?> and the code in the page i want data to show on: <?php select("*", "pages"); $num = mysql_num_rows($result); $fetch = mysql_fetch_assoc($result); if($num != 0){ $heading = $fetch["name"]; $content = $fetch["pageContent"]; $active = $fetch["active"]; if($active == 1){ echo "<h1>".$heading."</h1>"; echo "<p>".$content."</p>"; } }else{ echo "You need to enter page data into the database before extracting."; } ?> Any help is gladly appreciated.
-
Hmm, ive never had to use that o.o
-
How Do I Create A Link From Part Of The Text In A Database?
White_Lily replied to FoxRocks's topic in PHP Coding Help
Ah my mistake ive always used my method when doing this sort of thing lol. PS: Mispelled "fetch" in both Cristian's and my on post(s). -
Hmm... you've got "%s" in your code where i believe it updates the 'id'? Is it supposed to be like that?
-
Okay thank you, is there a "solved" button on this new design? O.o
-
How Do I Create A Link From Part Of The Text In A Database?
White_Lily replied to FoxRocks's topic in PHP Coding Help
Try this: <?php $query = mysql_query("SELECT * FROM table_name"); if(mysql_num_rows($query) != 0){ $row = mysql_fethc_assoc($query); $contactUs = $row["pageContent"]; $convertContact = str_replace("Contact Us", "<a href='contactus.php'>Contact Us</a>", $contactUs); $convertContact = $contactUs; echo $contactUs; }else{ echo "Nothing in database"; } ?> -
Hi i have a slight problem, in my if and else statement that checks whether or not there is an image in the database when there is an image, there is a href tag that wraps around image the image so that once the image is clicked it then does a lightbox effect. the problem im having is that when there IS an image, the href tag is NOT wrapping around the image. <?php if(!$res["image"]){ echo 'No Image'; }else{ echo '<a href="'.$res["image"].'" rel="lightbox">'.displayImage($res["image"], $res["name"], NULL, 150, 150).'</a>'; } ?>
-
Sending data in plain from database to view page problem
White_Lily replied to karubum's topic in PHP Coding Help
Ah I've googled what CKEditor is, I can't help here I use TinyMCE Editors as they work better with my CMS. Sorry. -
Sending data in plain from database to view page problem
White_Lily replied to karubum's topic in PHP Coding Help
Im slightly confused... is the OP trying to get data from a database, or get data and update it? -
I also know that "checklogin.php" is from a tutorial site as the code is also exactly the same, i also found unsolved problems with this tutorial code.
-
He is saying he tried what you mentioned and used superglobal to no success >_>
-
Also, looking at that tutorial they cant even style their own code sections properly making it extremely hard to read. and they cant even connect to their databases correctly either. (right click their supposed "Demo" of a failed connection script.) MY SUGGESTION: Make things easy and get books.
-
Here is the "In Easy Steps" website i was talking about: http://www.ineasysteps.com/books-by-category/web-development/
-
It's better to build your own. This is because they are: - Highly Customisable to the clients needs - No real learning of the CMS functionality (you built it - you should know your way around) - You can make it as simple as you please. - It's FREE (if you deduct the cost of the programming software used such as dreamweaver or other editors). - If you make a template all you have to do is copy the files to all the websites that need a cms, and just change settings so that it works properly. Buying a Pre-Built CMS: - Complete waste of time as most have functions you'll probably never use! - Can cost a lot of money (again you may be paying most of it for things you won't use) - Some don't allow you to control what functions your CMS has. - Most are sometimes difficult to implement on websites.
-
Then in such case try ordering books online from book companies such as: "In easy steps" i believe its called. they have a range of books from HTML to AJAX/jQuery, etc.
-
If you have a local library/book store, try finding a "Computing" section - it's more than likely that they will have books on; HTML, CSS and PHP - maybe even MySQL. If they do, try seeing if they are at beginners/novice level. These books should give you a general understanding of what basic commands/tags do (some books also tell you what best practices are and how to properly layout your code ). Most HTML books come with a section dedicated to basic forms that do... well... nothing. but at least you get an idea of how to layout your form, and how to hide passwords on password fields, and implement textareas (usually for contact forms or online applications for jobs etc). The php books should also have a form section where it should tell you how to get the information into a database. (some also add a little validation but skip the validation if you can for now). Once you have read & done any activities that these books consist of, then try implementing what you've learnt into a basic static site with very little functionality (no login/registration forms) once you understand all of that THEN try and go about making a registration form (with no validation) that will enter information into a database under the correct columns, then create a login form that just checks to make sure the username and password(s) are in the database, and sets a session to indicate that the user is logged in. You can then also add validation to your script(s) once you understand that. This method will take a lot of time - but you more than likely won't regret it once you have what your looking for.
-
What my code does is display the form which requires the user to enter the username and password that they registered in the registration page, once they click "submit" the form then submits to itself whereby the information then goes through a series of validations, and should the username and password be correct, it then takes them straight to their profile page and dispalys "Login successful you are logged in as 'username'". Have you managed to create the registration page which allows the user information to be entered into the database which the login script can then check against?
-
To check if a user is logged in and providing you are using sessions, it would look something similar to this: <?php if(!$ses_user && !$ses_pass){ echo "You need to be logged in to view this page."; } ?> This code gets placed ABOVE the doctype. That way the first thing it checks for, is whether the sessions are set or not.
-
Just to give you an example of a login script, heres mine: <?php if(!$ses_user && !$ses_pass){ if($_POST["submit"]){ $u = $_POST["username"]; $p = $_POST["password"]; if(!$u && !$p){ $msg = "<p>The login form is empty. Try again.</p>"; } else{ if(!$u){ $msg .= "<p>The username is empty. Try again.</p>"; } else{ if(!$p){ $msg .= "<p>The password is empty. Try again.</p>"; } else{ $log = mysql_query("SELECT * FROM users WHERE username = '$u' AND password = '$p'"); $check = mysql_fetch_assoc($log); $u_check = $check["username"]; $p_check = $check["password"]; if($u != $u_check && $p != $p_check){ $msg .= "<p>The username or password was incorrect.</p>"; } if($u === $u_check && $p === $p_check){ session_start(); $_SESSION['log_user'] = $u; $_SESSION['log_pass'] = $p; header("Location: profile.php"); } } } } echo "<div class='bad'>".$msg."</div>"; } echo '<form action="" method="POST">'; echo '<label>Username:</label><input type="text" name="username" class="fields" />'; echo '<label>Password:</label><input type="password" name="password" class="fields" />'; echo '<input type="submit" name="submit" class="send" value="Login" />'; echo '</form>'; echo '<a href="register.php">Register</a> <div class="clear"></div>'; } else { echo '<div class="good">Login was successful.<br>You are logged in as: '.$ses_user.'</div>'; $join = mysql_query("SELECT * FROM users WHERE username = '$ses_user'"); if($joined = mysql_fetch_assoc($join)) { $join_num = $joined["joined"]; if($join_num < 1) { echo '<a href="join.php">Join the Team</a>'; } } } ?> It works fine. The process? -> You fill in the form -> Submits to itself -> Gets the information from the form and puts them inside variables -> The variables are then checked to make sure none are empty -> If not empty it then compares them to the database entries -> If successful, logs you in and creates sessions around your username and password.
-
Also, considering you seem to know very little maybe starting off with simple things will give you some head start? Look into echoing and getting different messages to show with if/else statements. This will give you a genernal starting point . Echoing: <?php echo "Hello World"; ?> If / Else <?php $date= date("D"); if($date == "Fri"){ echo "Almost the weekend."; } else{ echo "Not quite the weekend."; }
-
Im guessing you are trying to get the script to submit to itself, then check the login details, compare the details to the database, then if successful start sessions? For an example go here: http://tutorials.janedealsart.co.uk (register, then use the login box)
-
Login Script failing with Internal Server Error 500.
White_Lily replied to White_Lily's topic in PHP Coding Help
Right - thank you, PFM, that worked perfectly -
Login Script failing with Internal Server Error 500.
White_Lily replied to White_Lily's topic in PHP Coding Help
If i wanted the password to be hashed i would of asked how to, but thats not what im asking - im asking why is it only letting the first user login and no other user? >_> -
Login Script failing with Internal Server Error 500.
White_Lily replied to White_Lily's topic in PHP Coding Help
New problem found with logging in. With the code I have, it only only allows the first user in the database to login, when ever a different user tries to login it days for them to go back and enter a valid username. The username & password I entered were valid because I copied and pasted them from the database.