PHP - Problem With Simple Commenting Script
Hello, I'm trying to create a simple php blog thing, and I can't get the commenting to work..
blog.php?id=2 On that page, there is a form what is used to comment, it goes to send.php That php has this query in it: $yhteys = mysql_connect('10.5.49.32', '09A_user', 'pass'); mysql_select_db('09A_Jere', $yhteys); mysql_query("INSERT INTO `Blog_kommentit` (`kayttajat` , `kommentti` , `kirjid` ) VALUES ('$kayttajat', '$kommentti', '$id')") or die(mysql_error())$sql = "SELECT * FROM Blog_kommentit WHERE kirjid='$id' ORDER BY id";; mysql_close($yhteys); header('Location: ' . $_SERVER['HTTP_REFERER']); How can I make the $id to be previous pages id (2)? This shouldn't be anything hard and I'm kinda amazed why I am stuck in this, any help will be appreciated. If I just put $id I get this error: Code: [Select] Cannot add or update a child row: a foreign key constraint fails (`09A_Jere/Blog_kommentit`, CONSTRAINT `kommentti_kirjoitus` FOREIGN KEY (`kirjid`) REFERENCES `Blog_kirjoitukset` (`id`))Here is how my database works: (Kayttajat = username, kommentti = comment) Similar TutorialsI have spent almost 2 days looking for solution to the strangest error I have ever meet. Whenever I do commenting and my php script, the sricpt falls running. Code: [Select] <?php error_reporting(E_ALL | E_STRICT); echo 'test1'; //echo 'testi2'; echo 'test3'; flush(); ?> trigger_error("Here we are!", E_USER_ERROR); This will output: test1. I have tried lot of things to find out the problem but I can't get any error message and whenever I remove the comments, the script works absolute fine. The script works also with comments in my local server, but whenever I download it on the other server, the problem appears. The file encoding is a UTF-8 format without BOM, and the file is one part of my Yii application. I haven't relasized similar behaving in other scripts. I wonder if someone has some idea what could cause this kind of behaving? I'm very thankful to man who can give me ideas... Hi all, Im coding a simple script for my website which just changes the users rank. Code: [Select] <?php session_start(); include "../includes/db_connect.php"; include "../includes/functions.php"; logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username=$_SESSION['username']; $get = mysql_query ("SELECT * FROM users WHERE username = '$username'"); $fetch = mysql_fetch_object($get); if ($fetch->userlevel >= "2"){ $newrank = $_POST['newrank']; $user1 = $_POST['user']; if (strip_tags($_POST['update'])){ mysql_query("UPDATE users SET `rank` = '$newrank' WHERE username='$user1'") or die (mysql_error()); echo ("You have updated $user1's rank to $newrank !"); } } else{ echo ("Your userlevel isnt high enouth to be here!"); } ?> <html> <head> <title>Change Rank</title> <link rel="stylesheet" href="../includes/in.css" type="text/css"> <style type="text/css"> .infobg { font-family: Arial; font-weight:normal; font-size:12px; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; background: URL(textbg1.png); font-weight:300; } .button { font-size: 12px; background:url(button.png); vertical-align: middle; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; color: #FFFFCC; height:23px; font-weight:300; border-radius: 10px; padding-bottom:2px; } </style> </head> <body> <form action='' method='post' name='form1'> <table width='30%' cellpadding='0' align='center' cellspacing='0' border='1' bordercolor='#000000' bgcolor='#808080' style='border-collapse: collapse'> <tr> <td background='../header.jpg' colspan='2' align='center'>Change Rank</td> <tr> <td>Username:</td><td><input type='text' name='user'></td> </tr> <tr> <td>Rank:</td><td><input type='text' name='newrank'></td> </tr> <tr> <td> </td><td><input type="submit" name="update" value="Update Rank"></td> </tr> </form> </table> </body> </html> But there seems to be something wrong with that code, which I carnt see or work out. When I click Update submit button it does nothing, but can anyone see why it does nothing? Thanks. Hi there, I have a simple login script written but I get an error with it. It does work but shows an error on some pages. Let me explain. Three Files: Admin.php Login.html checklogin.php When the user has logged in they go to checklogin.php. If the username and password match 1 row in the database then it forwards the user to admin.php fine. Except I keep getting mysql warning messages: Warning: Cannot modify header information - headers already sent by (output started at /home/wormste1/public_html/tilburywebdesign/shop/templates/template1/admin/updatescompanyinformation.php:3) in /home/wormste1/public_html/tilburywebdesign/shop/templates/template1/admin/companyinfoupdated.php on line 3 At the start of each page I want password protected I put the following code: <? session_start(); if(!session_is_registered(myusername)){ header("location:login.html"); } ?> I can't work out why I am getting this error. Many Thanks, Ian Hello, I am relatively new to PHP/MySQL (two months) and this is my first post in the forum. I am trying to implement an 'add to cart' script from http://v3.thewatchmakerproject.com/journal/276/. The demo works fine but when i implement it on my site i get this warning: "Assigning the return value of new by reference is deprecated" from what i assume is this Function below: Can anyone help me? Also, i'm aware that using global is not the done thing anymore, so could somebody explain to me what i should do instead of global. Thanks in advance, Code: [Select] function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM collection WHERE dress_id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.' by '.$author.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi, I'm trying to code a very basic commenting system, my only worries is how I'm going on about disabling the user from putting any html php etc.. in the comment so it gets displayed on the page.. I have on idea of what to look for, any help is much appreciated I considdered this: strip_tags() but what i want is to display the comment just without actually executing the code if you get me? Hello, Basically i am following this tutorial -: http://tutorialzine.com/2010/06/simple-ajax-commenting-system/ for a website I am creating. But in that tutorial when you write a comment you add a name, I was wondering is it possible instead for my website to use the users username as I have a login system that I created from folowing a tutorial on the same site. I am new to PHP and web creation so please keep the comments simple. Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 Short of deleting, how do I comment out code like this : <!-- IF not S_DISPLAY_RECENT --> <!-- INCLUDE portal/block/recent.html --> <!-- ENDIF --> Nesting <!-- --> /*...*/ // do not work. Thanks And I'm talking as basic as you can go! I'm trying to implement a commenting system on my website for news articles I post, and I've only gotten as far as creating the script to connect to my database (I use mysql). I've tried every open source script online for this app and I've not been able to get any one to work within my website. They'll work on separate blank html pages, but I can't figure out how to put the code into my existing pages, which is a huge problem. As a result, I've resorted to creating my own script, which shouldn't be too difficult to make. If anyone could possibly describe a step by step process on how this can be done I would be incredibly grateful! Just note that I don't want to use ajax, jscript or any other languages like that, just PHP. Another question I have, is how would I organize my database to include all news articles, and comments with a news article "id"? Would I need to put both in separate tables and just assign each comment with the uniqe id associated with whatever news article? And the last thing, I want pagination for my news. I have it to where if I insert a news article column into my table "mynews", it'll show up on the home page, but how and where would I insert a pagination code to make the articles "paginate"? Hi im pretty new to php but I was following a tutorial for a commenting system and implemented it onto my blog page. Anyway the problem I have is that as you go down the page each blog post displays its own comments + the comments for the posts above it. I have checked the database and the data seems to link the correct comments to the correct posts so I am confused to why this is happening. I have looked over my code and cant seem to find a problem (probably because I suck!). Here is the code for the blog page... Code: [Select] <?php include_once ("scripts/checkuserlog.php"); include_once ("scripts/connectToMysql.php"); include_once ("functions/agoTime.php"); $myObject = new convertToAgo; $username = ''; $errorMsg = ''; $successMsg = ''; $date = date("m.d.y"); if (isset($_GET['id'])) { $id = preg_replace('#[^0-9]#i', '', $_GET['id']); } else if (isset($_SESSION['idx'])) { $id = $logOptions_id; } else { header("location: index.php"); exit(); } $id = preg_replace('#[^0-9]#i', '', $id); $sql = mysql_query("SELECT * FROM members WHERE id='$id' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 0) { header("location: index.php?msg=user_does_not_exist"); exit(); } while($row = mysql_fetch_array($sql)){ $username = $row["username"]; } if(isset($_POST['workoutName'])){ $workoutName = $_POST['workoutName']; $workoutDescription = $_POST['workoutDescription']; if ((!$workoutName) || (!$workoutDescription)) { $errorMsg = 'Please fill in both fields'; } else { $insertBlog = mysql_query("INSERT INTO blog (userid, workoutName, workoutDescription, datetime) VALUES ('$id', '$workoutName', '$workoutDescription', now())") or die(mysql_error()); if ($insertBlog){ $successMsg = '<span class="errorMsg">Workout blogged successfully</span>'; } else { $errorMsg = '<span class="errorMsg">Problems arose during the information exchange, please try again later.</span>'; } } } $getBlog = mysql_query("SELECT * FROM blog WHERE userid='$id' ORDER BY id DESC"); $blogEntries = mysql_num_rows($getBlog); if($blogEntries < 1){ $blogDisplay = '<span class="blogName">' .$username. ' has not blogged a workout yet</span>'; } else { while($row = mysql_fetch_array($getBlog)){ $blogEntryId = $row["id"]; $sql_comment = mysql_query("SELECT * FROM blog_comments WHERE post_id='$blogEntryId' ORDER BY id ASC"); $countComment = mysql_num_rows($sql_comment); if($countComment > 0){ while($row2 = mysql_fetch_array($sql_comment)){ $comment_user_id = $row2["comment_user_id"]; $sql_comment_username = mysql_query("SELECT username FROM members WHERE id='$comment_user_id' LIMIT 1"); while($row3 = mysql_fetch_array($sql_comment_username)){ $comment_username = $row3["username"];} $post_id = $row2["post_id"]; $commentBody = $row2["comment_body"]; $commentDate = $row2["comment_date"]; $displayCommentList .= '<div>' .$comment_username. ' - ' .$commentBody. ' - ' .$commentDate. '</div>'; } } else { $displayCommentList = ''; } $workoutName = $row["workoutName"]; $workoutDescription = $row["workoutDescription"]; $blogDate = $row["datetime"]; $convertedTime = ($myObject -> convert_datetime($blogDate)); $blogDate = ($myObject -> makeAgo($convertedTime)); $blogDisplay .= '<table width="950px"><tr bgcolor="#DBE4FD"><td><span class="blogName">' .$workoutName. '</span> » <span class="blogDate">' .$blogDate. '</span></td></tr> <tr bgcolor="#F1F4FE"><td><span class="blackText">' .$workoutDescription. '</span></td></tr> <tr bgcolor="#DBE4FD" valign="top"><td>' .$displayCommentList. '</td></tr> <div id="new_comment' .$blogEntryId. '" style="display:none"></div> <tr><td><textarea id="comment' .$blogEntryId. '"></textarea><input type="submit" value="Comment" onclick="javascript:SendComment(\''.$blogEntryId.'\');" /></td></tr>'; if(isset($_SESSION['id'])&&$_SESSION['id']==$id){ $blogDisplay .= '<tr bgcolor="#DBE4FD"><td><a href="editBlogPost.php?id=' .$blogEntryId. '"><span class="blackText">Edit Post</span></a> &#8211; <span class="blackText">Delete Post</span></td></tr></table><br /><br />'; } } } if(isset($_POST['deleteButton'])){ $deleteBlog = mysql_query("DELETE FROM blog WHERE id='$blogEntryId'"); if($deleteBlog){ $successMsg = 'Blog entry deleted successfully'; } else { $errorMsg = 'Could not process your request, please try again later'; } } ?> <?php if (isset($_SESSION['id'])&&$_SESSION['id']==$id) { $blogForm = '<table bgcolor="#DBE4FD" width="950px"> <form action="member_blog.php" method="post" enctype="multipart/form-data"> <tr> <td width="200px"><span class="blackText">Workout Name:</span></td><td width="650px"><input name="workoutName" type="text" id="workoutName" /> <span class="blackText">Date: ' .$date. '</span></td></tr> <tr> <td><span class="blackText">Workout Description:</span></td><td><textarea name="workoutDescription" cols="75" rows="10" id="workoutDescription" /></textarea></td></tr> <tr><td><input name="submitBlog" id="submit" type="submit" value="Blog!" /></td><td><span class="errorMsg">' .$errorMsg. '' .$successMsg. '</span></td> </tr> </form> </table>'; } else { $blogForm = ''; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo ("$username"); ?>'s Blog</title> <link href="style/layout.css" rel="stylesheet" type="text/css" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> function SendComment(blogEntryId){ var comment_txt = $("#comment"+blogEntryId).val(); if(comment_txt == ""){ alert("Please enter a comment"); } else { $.post("scripts/blogComment.php", {comment: comment_txt, blogId: blogEntryId} ,function(data){ $("#new_comment"+blogEntryId).html(data); $("#new_comment"+blogEntryId).slideDown(300); }); } } </script> </head> <body> <div id="container"> <?php include_once ("bannerFiles/bannerTemplate.php"); ?> <?php include_once ("bannerFiles/bannerMenu.php"); ?><br /> <div id="content"> <span class="profileUsername"><?php echo ("$username"); ?>'s Workout Blog</span><br /><br /> <?php echo ("$blogDisplay"); ?><br /><br /> <?php echo ("$blogForm"); ?> </div><br /><br /> <?php include_once ("footerFiles/footerTemplate.php"); ?> </div> </body> </html> ...and here is the code for the blogComment.php page Code: [Select] <?php session_start(); include_once ("connectToMysql.php"); if(isset($_POST['comment'])){ $comment = $_POST['comment']; $blogId = $_POST['blogId']; $comment_user_id = $_SESSION['id']; $username = $_SESSION['username']; $sql = mysql_query("INSERT INTO blog_comments (comment_body, post_id, comment_user_id, comment_date) VALUES ('$comment', '$blogId', '$comment_user_id', now())"); echo '<div>' .$username. ' - ' .$comment. ' - Just Now</div>'; } else { echo "Failure"; } ?> Thanks in advance for any help Hey everyone! Thanks for taking the time to help. I have two files..a membership area and a commenting section. I am fairly new at these subjects but I am a quick learner. First off, I need help figuring out why my "register.php" in the members area file isn't working properly, everything looks to be ok but maybe I have been working on this too long. Quite frankly I can't check and see if all of the other scripts are correct because I can't get past the "register.php". So if you all wouldn't mind helping me out on this part, I would greatly appreciate it Secondly, I have a commenting section and in the "demo.php", there is a warning that appears as follows: "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\comments\demo.php on line 17 " If someone could tell me what is missing or help me figure out what to do in simple terms, I would greatly appreciate that as well. Thanks! Gene [attachment deleted by admin] I need some help with my commenting system. at the moment the code is like this: <div id="pagepannel"> <div id="ptop_small">Comments</div> <div id="pbottom_small"> <p> <?php // if ($allow_comments == "no") { ?> </p> <p>No Posting comments here!!!</p> <p> </p> <p> </p> <p> <?php } else ?> </p> <p> <?php $sql = "SELECT comment_id, blog_id, posted_by, comment, stamp, email, type FROM jscrgaming_newscomments WHERE blog_id='$blog_id' ORDER BY comment_id DESC"; $result = mysql_query($sql) or die('Error : ' . mysql_error()); while(list($comment_id, $blog_id_co, $username, $comment, $stamp, $email, $type) = mysql_fetch_array($result, MYSQL_NUM)) { if ($type == 'user'){ ?> </p> <table width="95%" border="0" cellpadding="0" cellspacing="0" class="full_border"> <tr> <td width="75" id="avatar"></td> <td><span class="capitalize"><a href="userinfo.php?user=<? echo $username ?>"><strong><? echo $username ?></strong></a></span><strong> posted</strong>: <? echo stripslashes($comment) ?></td> </tr> <tr> <td colspan="2" bgcolor="#CAE4FF" class="date"><? echo $stamp ?> </td> </tr> </table> <p> </p> <p> <? } else{ ?> </p> <table width="95%" border="0" cellpadding="0" cellspacing="0" class="full_border"> <tr> <td><strong> <? echo $username ?>posted</strong>: <? echo stripslashes($comment) ?></td> </tr> <tr> <td bgcolor="#CAE4FF" class="smalltext"><? echo $stamp ?>:: User Was Guest</td> </tr> </table> <p> </p> <p> <? } }?> </p> <p> <?php // if ($allow_comments == "restricted") { /** * User has already logged in, so display relavent links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){?> </p> <form id="form3" name="form3" method="post" action="user/admin/blog/comment_system/user.php"> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td colspan="2">You are commenting as <?php echo $session->username;?></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="co_comment" cols="30" id="textfield10"></textarea></td> </tr> <tr> <td width="75"><span class="header"> <input name="co_username" type="hidden" id="co_username" value="<?php echo $session->username;?>" /> <input name="co_blog_id" type="hidden" id="co_blog_id" value="<?php echo $blog_id ?>" /> </span></td> <td><label> <input type="submit" class="blog_button" value=" Post " /> </label></td> </tr> <tr> <td> </td> <td class="smalltext">only 200 charaters can be used</td> </tr> </table> </form> <p> </p> <p> <? } else {?> </p> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td width="75"><span class="capitalize">Name</span></td> <td><label> <input name="textfield5" type="text" disabled="disabled" id="textfield5" size="35" /> </label></td> </tr> <tr> <td width="75">Email</td> <td><input name="textfield5" type="text" disabled="disabled" id="textfield6" size="35" /></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="textfield5" cols="30" disabled="disabled" id="textfield7">You need to be logged in to comment.</textarea></td> </tr> <tr> <td width="75"> </td> <td><label> <input type="button" class="blog_button" value=" Post " /> </label></td> </tr> </table> <p> </p> <p> <?php } } else { if($session->logged_in){?> </p> <form id="form2" name="form2" method="post" action="user/admin/blog/comment_system/user.php"> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td colspan="2">You are commenting as <?php echo $session->username;?></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="co_comment" cols="30" id="textfield8"></textarea></td> </tr> <tr> <td width="75"><input name="co_username" type="hidden" id="co_username" value="<?php echo $session->username;?>" /> <input name="co_blog_id" type="hidden" id="co_blog_id" value="<?php echo $blog_id ?>" /></td> <td><label> <input type="submit" class="blog_button" value=" Post " /> </label></td> </tr> <tr> <td> </td> <td><span class="smalltext">only 200 charaters can be used</span></td> </tr> </table> </form> <p> </p> <p> <? } else { ?> </p> <form id="form1" name="form1" method="post" action="user/admin/blog/comment_system/guest.php"> <p> </p> <table width="95%" border="0" align="center" cellspacing="2" class="full_border"> <tr> <td width="75"><span class="capitalize">Name</span></td> <td><label> <input name="co_username" type="text" id="co_username" size="35" /> </label></td> </tr> <tr> <td width="75">Email</td> <td><input name="guest_email" type="text" id="guest_email" size="35" /></td> </tr> <tr> <td width="75">Message</td> <td><textarea name="co_comment" cols="30" id="co_comment"></textarea></td> </tr> <tr> <td width="75">Spam</td> <td> </td> </tr> <tr> <td colspan="2" align="center"><? require_once('user/captcha/recaptchalib.php'); $publickey = "6Ld_W7sSAAAAAPNTLWrUJLEClFpSSPu1d1Ry5zNR"; // you got this from the signup page echo recaptcha_get_html($publickey); ?></td> </tr> <tr> <td colspan="2" align="right"><span class="smalltext">only 200 charaters can be used</span> <input name="co_blog_id" type="hidden" id="co_blog_id" value="<?php echo $blog_id ?>" /> <input type="submit" class="blog_button" value=" Post " /></td> </tr> </table> </form> <p> </p> <p> <? } } ?> </p> <p> </p> <div></div> </div> </div> I, know its a bit messy but lets me see it and design it in Dreamweaver Any way, for the comment system for users, I want it to show their avatar as well, which is stored in the users table. How would one do this. I did think of it submitting the avatar along with the post but then it wouldnt update if the user would to change their avatars :\ Any helps??? <html> <head></head> <body> My favourite bands a <ul> <?php // define arrays $morebands = array('Desturbed', 'Anthrax'); $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands"); // loop over it // print array elements foreach ($artists as $a) { if ($a != 'Array'){ echo '<li>'.$a; } Else { foreach ("${$a}" as $b){ echo '<li>'.$b; } } } ?> </ul> </body> </html> I can not figure out why this will not work:( I would like the foreach to run through the array as normal, but if it encounters a nested array, loop it as well. I know this likely is not the right, or best way to do this, but I am just learning PHP through a tutorial and I learn best by doing... So I take the lessons, make them more complicated, then figure out how to make it happen (like so). right now I am working on http://devzone.zend.com/node/view/id/635 anyhow thanks for any help! Good evening guys and gals, for some reason I cant get my head around something quite simple, basically I am trying to work out a way of simply recording referrals to my site when the potential user registers. This worded example is basically what I want: registered user a with a username of smithy invites his friend western to become a member of a site he has joined: I guess here I would basically use something like mysite.com?refid=smithy as the link he gives he's friend Now this is where my brain refuses to work, what if western decides to have a look around the site before he decides to register and clicks on a few internal pages? Obviously the referral id will no longer be in the address bar. So my 1st question is, how can I check to see if a referral is used when accessing the site? I could then store the username in a session or cookie. If I had something like this: <?php $refid = $_GET('refid') setcookie("user", $refid, time()+3600); ?> But how would I check that a refid exists in the url so it doesnt throw up a parse error? I have more questions but 1 thing at a time! Many Thanks I'm very new to PhP and one of my asignments in class is to create a simple login using php and mysql. I made a simple page using html, php, and mysql and i keep getting errors. Here is my code so far: This is my index.php page: <html> <form action = 'login.php' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input type='submit' value='Log in'> </form> </html> This is my login.php page: <?php $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { &connect = mysql_connect("localhost", "root", " ") or die ("Couldnt connect"); mysql_selct_db("phplogin") or die("Couldn't find db"); } else die ("Please enter a username and password"); ?> mySql file is very basic: 3 columns, id, username, password I dont think my problem is with the mySQL page that was the easiest to make but everytime I hit login in the index.php, the entire script for login.php gets outputted on screen. I would appreciate all the help. i already have the front page that calls the script, but its not letting me login, i don't see the problem i know its returning the rows from the database but i don't understand why its not letting me login and when i do get it to login messing around with the code everybody logs in as an admin, my database has, user, pass, and role inside admin, poweruser, and reg user but when i get it to log in everybody logs in as an admin, can someone please help me ? i even tried the error thing but that doesn't seem to work either ini_set('display_errors', 1); error_reporting(E_ALL); //echo ini_set('display_errors'); session_start(); $username = $_POST['username']; $password = $_POST['password']; if (mysql_connect("localhost", "root", "")) { //echo 'connect'; } else { echo 'failure'; } if (mysql_select_db("athentication")) { //echo 'connect'; } else { echo 'no connect'; } $result = mysql_query("SELECT * FROM login WHERE user = '$username'"); $rows = mysql_num_rows($result); $role = $rows['role']; if ($rows != 0) { if ($role == 'admin') { header('Location: admin.php'); $_SESSION['username'] = $username; } elseif ($role == 'poweruser') { header('Location: poweruser.php'); $_SESSION['username'] = $username; } /*elseif ($role ==' reg') { echo "WHAT UP"; $_SESSION['username'] = $username; }*/ } else echo "enter a valid user name"; The attached script does everything I want it to do, but it's not very elegant. I could use some help cleaning it up. Any and all help is greatly appreciated. Thanks!!! I was told that you guys could probably help me with this, so heres my situation. I use this program called Activeworlds, and me and my buddies are makeing a "tv show" if you will within the program. To do so, you take screenshots, save the screenshots, and add the image files into a directory on your domain. You need a .php script to present them as a slideshow. Now the problem is, ive searched for scripts already made from other sites, but the thing is, they are all fancy slideshow viewers, meaning they come with control buttons to cycle through the pictures and all kinds of other banners and flashy looking things. The only script im needing, is a simple script that will display and cycle through the raw images, and nothing else, within the web browser, in a slideshow format. Id also like to have a value I can edit that will change how fast the pictures cycle through, 15 seconds or so would be perfect however. If someone could refer me to this code or even make it for me, it would be soo appreciated. I know im probably asking for alot, but it would help me soo much. I wish I knew a little more about .php files to do it myself, or else I would. If you do link me to a script, please give me simple instructions on what to do with it lol because like I said, I dont know anything about the world of .php yet. Thank you all for your time. |