Jump to content

Seaholme

Members
  • Posts

    81
  • Joined

  • Last visited

Everything posted by Seaholme

  1. Basically I want to include something on all of my pages to check if people are logged in, and if not to throw them an error. The way I see it, I can either stick this on every page individually, or just include a file, and including a file is much more efficient! So I came up with this extremely simple thing: <?php if($loggedin != '1') die("Oops, you're not logged in! <a href=index.php>Log in?</a>"); include('footer.php'); ?> The only problem is that after die() I can't seem to get the footer to appear. All I can think of as an alternative is to go through and put an if()...else() command on every single page individually, which I'd rather not do unless I had to. Does anybody know how I could include the footer on the page somehow, below the die command? I can make it appear above... but then it's not so much a footer xD Thanks!
  2. I think another option might be something like extracting a substring from the string you already have. You can see the command to do it on this page here, in the top table, 6th one down: http://www.redhat.com/docs/manuals/database/RHDB-7.1.3-Manual/sql/functions-string.html
  3. It's quite hard to describe so if it's okay, I took a screenshot of what it looks like on the Cronmanager http://i50.tinypic.com/2mxkbiv.png
  4. Hey, Pretty sure you guys are starting to get a bit sick of me asking questions here, but searching Google for answers to my problem, all I can find are tips for composing a cron yourself, and I'm 99% sure the cron isn't the problem. Basically I've got hosting from GoDaddy.com which also gives you a Cron Manager -- you can enable/disable scripts, set exactly when and how often you want them to run and set which script you want to run directly from a "Browse Scripts" button, so on the basis that this is kinda foolproof, I'm sure that even I haven't got the setting up of the cron wrong xP So all I can think is that my script is wrong. When I go to the script location in my browser, it works absolutely fine -- but my question is, is there anything specific I need to write into it which would make it work with the cron? This is what the script consists of: <?php // Make a MySQL Connection mysql_connect("xxx", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); mysql_query("UPDATE dogs SET age = age + 1"); ?> Should there be something in there to direct the Cron what to do? Thanks for any help!
  5. Fixed! I changed it to backticks and it worked! Thanks a billion, you've been so helpful! :D
  6. Hey -- firstly, thanks for all the help! Secondly, this is the output I get from doing what you suggested... Query: SELECT MAX('a_id') AS Maxa_id FROM forum_answer WHERE question_id='34' Before: a_id After: 1 Should that query read something different? I have the table set up so that a_id has a default value of 0, if that helps at all. I can't work out if that might be relevant or not, but at this stage I'm starting to think everything might be relevant, this has been giving me a headache for ages now!
  7. Okay, so I tried your tactic of echoing things to see whereabouts the problem might be and I did if ($rows) { $Max_id = $rows['Maxa_id']+1; echo $rows['Maxa_id']; } else { $Max_id = 1; } and the echo was "a_id". Pretty sure it should have echoed a number there (number 1, I think)! I'm still trying to figure this out, but any thoughts are welcome
  8. Heya, I did what you said and rather confusingly, it came out with the IF executing, rather than the else! o.O So it's not just defaulting to 1 via the ELSE clause.
  9. Just poking this topic back onto page 1 O:
  10. Hey, I'm working on editing some code for a simple forum, however I'm having difficulty with the script to add a reply to a topic. All of it works fine except for the reply ID -- every reply is listed as no. 1, whereas it's meant to add on another digit for every subsequent reply so the first reply is no. 1, the second reply is no. 2, the third reply is no. 3 and so on. I've enclosed the main body of the php (there's connecting to the database beforehand, and that's pretty much it) , and was wondering if anybody could help me work out why it's not adding on another number for every new reply? :[ // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX('a_id') AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql) or die(mysql_error()); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_answer=$_POST['a_answer']; $datetime=date("d/m/y H:i"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_answer', '$datetime')"; $result2=mysql_query($sql2); if($result2){ echo "Your reply has been posted.<BR>"; echo "<a href='view_topic.php?id=".$id."'>View Topic</a><br><a href=comms.php>Return to Comms</a>"; // If added new answer, add value +1 in reply column $tbl_name2="forum_question"; $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); } Thank-you!
  11. Hey, I tried it with the backwards thingys and it didn't work, so I tried it with ' instead and it DID work... leading me onto another error which revealed where the problem was! I copied & pasted something and managed to get it all inserting into the wrong table. Smart, right? xP Thanks so much for your help!
  12. Heya, I'm also pretty junior in the PHP stakes, but I think I have an idea how you might be able to get this to work. Is there any chance you could post the PHP you're using up here? Or maybe somebody who knows what they're doing better can help you, but I know that I for one would like to see what you're using to generate the email in the first place! Cheers.
  13. Thanks for the reply. I tried echo $result; and it came out with a blank, so you're right, that seems to be where the problem lies. Also did what you said for the other bit and it very handily told me what was missing! Awesome stuff. Unknown column 'a_id' in 'field list' That's its new (well, more specific!) problem. I checked the database to make sure I didn't misname anything and there definitely is an a_id there. Does this mean there's some sort of bit missing from the code where a_id is meant to have been defined? If so, I don't understand how this worked for other people! o.O Any thoughts?
  14. I've been trying to make this script work (to create a Forum) that I found here: http://www.tutorialized.com/view/tutorial/Creating-simple-PHP-forum-tutorial/9962 and all of it works except for the script to add an answer to the topic. Other people's comments on that tutorial page seem to suggest that this script works, so I've been scratching my head to try and get it to function. However, I've been trying for ages to figure out what this error is referring to and can't work out what's wrong! This is the error I keep getting: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/91/6351791/html/add_reply.php on line 18 ERROR I've highlighted line 18 with ***LINE 18. Can anybody help me figure out whereabouts the problems might lie? I'm quite new to php (3 days of trying to work it out, now xD) and so I dunno if it's quite obvious or not. Sorry if it is! I'll be extremely grateful if anybody could tell me what it might be, or at least point me in the direction of what might be wrong. <?php $host="xx"; // Host name $username="xx"; // Mysql username $password="xx"; // Mysql password $db_name="xx"; // Database name $tbl_name="forum_question"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ***LINE 18 // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_answer=$_POST['a_answer']; $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_answer', '$datetime')"; $result2=mysql_query($sql2); if($result2){ echo "Successful<BR>"; echo "<a href='view_topic.php?id=".$id."'>View your answer</a>"; // If added new answer, add value +1 in reply column $tbl_name2="forum_question"; $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); } else { echo "ERROR"; } mysql_close(); ?> Thanks very much!
  15. You guys are absolute lifesavers! It's working now Thanks so much!
  16. Thanks! I changed it as you suggested, but it still throws up an error. This is the edited version... <?php $dbhost = 'xxx'; $dbuser = 'xxx'; $dbpass = 'xxx'; $dbname = 'xxxx'; $tbl_name="players"; // Table name // Connect to server and select database. mysql_connect("$dbhost", "$dbuser", "$dbpass")or die("cannot connect"); mysql_select_db("$dbname")or die("cannot select DB"); $displayname = $_POST['displayname']; $campname = $_POST['campname']; $id = $_POST['id']; // update data in mysql database $sql="UPDATE players SET displayname = '$displayname', campname = '$campname', WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?> EDIT: I also thought I'd add in the php for the previous page, in case that helps <?php $dbhost = 'xxx'; $dbuser = 'xxxx'; $dbpass = 'xxx'; $dbname = 'xxx'; $tbl_name="players"; // Table name // Connect to server and select database. mysql_connect("$dbhost", "$dbuser", "$dbpass")or die("cannot connect"); mysql_select_db("$dbname")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Username</strong></td> <td align="center"><strong>Camp Name</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="displayname" type="text" id="displayname" value="<? echo $rows['displayname']; ?>"></td> <td align="center"><input name="campname" type="text" id="campname" value="<? echo $rows['campname']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?>
  17. Thanks, I managed to get it work via another page, as suggested
  18. Hey all, I've been trying to get a script to run which will allow me to use PHP to update fields in the database. I found http://www.phpeasystep.com/mysql/9.html this website which explains how to do it, and followed all the steps. Every one of them has worked except for my attempt at the final step (Create file update_ac.php) which throws up the message it gives when the whole thing has been unsuccessful (ERROR). Can anybody help me work out what it is about it that is causing the error to be thrown up? Also: could it be in one of the previous pages? <?php $dbhost = 'xxxxx'; $dbuser = 'xxxx $dbpass = 'xxxxx $dbname = 'xxxxx'; $tbl_name="players"; // Table name // Connect to server and select database. mysql_connect("$dbhost", "$dbuser", "$dbpass")or die("cannot connect"); mysql_select_db("$dbname")or die("cannot select DB"); // update data in mysql database $sql="UPDATE players SET displayname='$displayname', campname='$campname', WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?> Thanks!
  19. Basically I'm trying to make it so that a number only increases +2 if the submit button is pressed. At the moment, the number increases by 2 no matter what happens -- even just refreshing the page! This is my original php // Make a MySQL Connection mysql_connect(".....", ".....", ".....") or die(mysql_error()); mysql_select_db("....") or die(mysql_error()); mysql_query("UPDATE players SET onhand = onhand + 2 WHERE id=".$_SESSION['id']); // A simple example of a form. echo '<form action=camp.php method=post> <input type=submit name=submit value=Submit> </form>'; } And then this is my attempt to make it into an if statement, so that it only increases when the button is pressed. However, this totally screws with my page (keeps giving me an error in the final line of php: Parse error: syntax error, unexpected $end in /home/content/91/6351791/html/camp.php on line 88) and even if I could work out what the error is, I'm not sure if I'm approaching it correctly to achieve the outcome I want. // A simple example of a form. echo '<form action=camp.php method=post> <input type=submit name=submit value=Submit> </form>'; if ( value == Submit ) { // Make a MySQL Connection mysql_connect("....", "....", "....") or die(mysql_error()); mysql_select_db("....") or die(mysql_error()); mysql_query("UPDATE players SET onhand = onhand + 2 WHERE id=".$_SESSION['id']); } Can anybody suggest how I could solve it so it only adds on 2 when the submit button is pressed? Thanks in advance. Everybody's been really, really helpful so far, and invaluable in my attempts to get a grip on php!
  20. Firstly, thanks for everybody's help (: Secondly, I did what you suggested and the print command didn't work, however what I have below DOES work to show up the username and id when I put it on the page, but not the onhand. echo 'Logged in as: <a href=profile.php>'.$_SESSION['username'].'</a> (#'.$_SESSION['id'].') Money: $'.$_SESSION['onhand'].''; ... however, when I put exactly the same PHP in the header, it works to show up the username, id AND onhand. So I'm extremely confused. It won't print the $_SESSION['id'] bit, however it WILL recognise it when it's in the form I have above. And when it's in the header, it'll show up the onhand part, however when I put exactly that same code into the main body of the page, it won't show up the onhand bit any more (but the id and username still show up fine :S)! This is a major headache for me! D: I'd really appreciate it if somebody could explain why it'll show it up in some places and not in others. Let me know if you need any more info. about the rest of the code I'm using!
  21. As in $owner = $_SESSION[id]; ? 'Cause that didn't work either!
  22. All of the information below goes into the database, except for $owner = $_SESSION['id']); I'm not sure why it's not also going in. I tried changing it so that it read $owner = '13'); and even just the number 13 didn't go in. Can anybody help? :/ $name = trim($_POST['name']); $gender = trim($_POST['gender']); $breed = trim($_POST['breed']); $date = date("m/d/y"); $owner = $_SESSION['id']); // Finally, create the record. $newDog = @mysql_query("INSERT INTO dogs (name, gender, breed, date, owner) VALUES ('$name', '$gender', '$breed', '$date', '$owner')") or die("Error: ".mysql_error()); echo 'You have made a new dog, yay!'; } else { Thanks!
  23. Wow, okay, I seem to have accidentally solved the second part to this myself! Yay xD
  24. Thanks -- that does solve the error I had before. Only now it says You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2 I have a feeling I'm going about this the wrong way. Does anybody know I can tie a user's details and account session with the things (dogs in this case) belonging to that user, so they only see what belongs to them?
×
×
  • 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.