Jump to content

thereaper87

Members
  • Posts

    49
  • Joined

  • Last visited

    Never

Everything posted by thereaper87

  1. Great, thank you for your help! For others that come across this thread, this is what I used, and it works! mysql_query("(SELECT * FROM `schedule` WHERE `date` < NOW() ORDER BY `date` DESC LIMIT 1) UNION ( SELECT * FROM `schedule` WHERE `date` > NOW() ORDER BY `date` ASC LIMIT 1)") or die("error");
  2. Hello there, this is more of a me trying to get my mind around it, more than it is a coding problem. I have a list in a database table that has a data on it in the format: mm/dd/yyyy I am trying to get the closest date from today. So today is the 4th, and the next date in the table is October 12, but when it is the 13th, it should get the next date automatically. I can't seem to figure out what coding structure to use. Any ideas?
  3. Not too sure what it means, but here is the result: array(4) { ["pick1"]=> string(7) "Science" ["pick2"]=> string(7) "General" ["pick3"]=> string(11) "Electronics" ["bio"]=> string(11) "asdfasdfsdf" }
  4. There is no error output. I have die(mysql_error($update_profile)); echo '<br />Your profile has been updated.'; But it does not display an error.
  5. Trying to debug my sql statement. This is what it echo'd out when I ran the query: Everything seems to be in their columns...i'm lost
  6. I posted almost the exact same thing has phpSensei! lol
  7. Hello there, I'm having a bit of trouble getting the UPDATE function to work and I was looking for some guidance. Here is the form: echo '<tr><td width="300">Current Avatar: <br /><img src="avatars/'.$data[avatar].'" width="100" height="100"></td><td width="300"><input type="file" value="Change" name="file"></td></tr>'; echo '<tr><td width="300">News Pick 1</td><td width="300"><select name="pick1"><option value="'.$data[field1].'">'.$data[field1].'</option><option value="Science">Science</option><option value="Politics">Politics</option><option value="Arts">Arts</option><option value="Sports">Sports</option><option value="Religious">Religious</option><option value="General">General</option><option value="Electronics">Electronics</option></select></td></tr>'; echo '<tr><td width="300">News Pick 2</td><td width="300"><select name="pick2"><option value="'.$data[field2].'">'.$data[field2].'</option><option value="Science">Science</option><option value="Politics">Politics</option><option value="Arts">Arts</option><option value="Sports">Sports</option><option value="Religious">Religious</option><option value="General">General</option><option value="Electronics">Electronics</option></select></td></tr>'; echo '<tr><td width="300">News Pick 3</td><td width="300"><select name="pick3"><option value="'.$data[field3].'">'.$data[field3].'</option><option value="Science">Science</option><option value="Politics">Politics</option><option value="Arts">Arts</option><option value="Sports">Sports</option><option value="Religious">Religious</option><option value="General">General</option><option value="Electronics">Electronics</option></select></td></tr>'; echo '<tr><td width="300">Edit Bio</td><td width="300"><textarea name="bio" cols="50" rows="8">'.$data[bio].'</textarea></td></tr>'; echo '<tr><td width="300"><input type="submit" value="Submit Changes"></form></td><td></td></tr>'; Pretty much 3 drop-downs and a textbox. Here is the processing: if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $_POST['pick1'] = stripslashes($_POST['pick1']); $_POST['pick2'] = stripslashes($_POST['pick2']); $_POST['pick3'] = stripslashes($_POST['pick3']); $_POST['bio'] = stripslashes($_POST['bio']); $userid = stripslashes($userid); } $pick1 = mysql_real_escape_string($_POST['pick1']); $pick2 = mysql_real_escape_string($_POST['pick2']); $pick3 = mysql_real_escape_string($_POST['pick3']); $bio = mysql_real_escape_string($_POST['bio']); $userid = mysql_real_escape_string($userid); $update_profile=mysql_query("UPDATE `user` SET `field1`='$pick1',`field2`='$pick2',`field3`='$pick3',`bio`='$bio' WHERE `username`='$userid'") or die(mysql_error($update_profile)); echo '<br />Your profile has been updated.'; echo '<br /><a href="index.php?page=cpanel">Go to profile</a>'; // $userid = $_SESSION['user'] , that is where it is called But when I fill out the form, it says it has been updated, but no change in the row in the database. Any ideas? What am I missing?
  8. Thank you! It now updates the row in phpmyadmin. But it does it twice! So instead have adding 1, it adds 2! Any idea?
  9. Hello there, I have an UPDATE sql state which is giving me some troubles Here is the update code $r_time = date("m/j/Y g:i A"); $u_time = date("U"); $news_id = (int)$news_id; $update_article_rate_up=mysql_query("UPDATE `articles` SET `up_rating`=(`up_rating`+1) AND `avg_rating`=(`avg_rating`+1) WHERE `id`=$news_id") or die("Error updating up rating"); $news_id is pulled from the URL. That's it. Nothing else. It is set as an integer. Here is the debugging verision: $r_time = date("m/j/Y g:i A"); $u_time = date("U"); $news_id = (int)$news_id; $update_article_rate_up=("UPDATE `articles` SET `up_rating`=(`up_rating`+1) AND `avg_rating`=(`avg_rating`+1) WHERE `id`=$news_id") or die("Error updating up rating"); echo $update_article_rate_up; This is what it says: Which I think is right! What is going on here?
  10. Awesome! Just to be sure, I wrap that in script tags correct?
  11. Hello there, I have a problem, that I am trying to find some literature about, or maybe an example, or a demo; or just plain help. What I am trying to do, is to have a query ran every 2 seconds, to display a number. Here is what I am trying to implement. //index.php <script> function updateShouts(){ // Assuming we have #shoutbox $('#shoutbox').load('latestShouts.php'); } setInterval( "updateShouts()", 2000 ); </script> // to merge that with // latestShouts.php $total = mysql_query("SELECT COUNT(*) FROM $table_and_query"); $total = mysql_fetch_array($total); return $total[0]; I know that will not work, because I really don't know much about ajax. I read all of the tutorials on w3, but they didn't really have an example I was looking for. Any help is appreciated.
  12. $sql=mysql_query("SELECT * FROM `buds` WHERE `level`<='$user_level' UNION SELECT * FROM `buds`, `unlocked_buds` WHERE buds.`id` = unlocked_buds.`bud_id` ORDER BY buds.`id` ASC") or die("A MySQL error has occurred.<br />Your Query: " . $sql . "<br /> Error: (" . mysql_errno() . ") " . mysql_error()); I have been trying to learn about UNION select statements. I ran the query above and got this response: I think I know what the problem is, but not sure how to fix it. There is two columns, one is "buds" which holds the flowers seeds info. The seconds is "unlocked_buds" which just links the "id" from buds to "user_id" to the user table. Both buds and unlocked_buds are both 8 columns. What do I need to learn?
  13. Hello there, decided to try to have a joined table query, running into a couple of problems. Here is the query: $sql=mysql_query("SELECT * FROM `buds`, `unlocked_buds` WHERE `id`.buds = `bud_id`.unlocked_buds ORDER BY `id`.buds ASC") or die("A MySQL error has occurred.<br />Your Query: " . $sql . "<br /> Error: (" . mysql_errno() . ") " . mysql_error()); Which gives the error: The two tables are 'buds' and 'unlocked_buds' Not really sure what to change, I have been following this tutorial http://www.sqltraining.org/selecting+data+from+multiple+tables/, but really is not helping that much. What exactly does that mean? What really is happening?
  14. Thank you for your input, but since I am the only one that is clicking on the form, I am not double clicking. I clicked the slowest possible and still it double submits. Could it be a server configuration problem?
  15. Hello there, I have made a ban form on my website. It is all going good until I open phpmyadmin. There is two records from one submission. Usually the second record has some missing information. There should not be a duplicate and I do not understand why it is happening. If anybody could explain what is causing this would be great. Here is the page. <?php session_start(); require_once 'database.php'; if(isset($_SESSION['mod'])) { $userid = $_SESSION['user']; if(isset($_GET['action']) && strcasecmp($_GET['action'], "file") == 0) // checks to see if form is submitted { $username = $_POST['user']; $time = $_POST['time']; $reason = $_POST['reason']; $u_time = date("U"); $r_time = date("m-j-Y g:i A"); if($time == "00") { // if the time is a permaban $sql=mysql_query("SELECT * FROM user WHERE username='$username'") or die("Error 1"); $data=mysql_query($sql); $user_ip = $data['last_ip']; if ($user_ip != 127.0.01) { // admin stuff $p_ban=mysql_query("INSERT INTO ip_ban (ip,real_time,unix_time,days_left,reason) VALUES ('$user_ip','$r_time','$u_time','99999999999','$reason')") or die("Error 2"); echo 'The user '.$username.' has been banned.'; }else{ // if it is an admin echo 'You cannot ban that user.'; } }else{ // not a perma ban if($username != "admin") // admin stuff { $temp_ban=mysql_query("INSERT INTO blacklist (email,reason,end_date,appeal,unixtime) VALUES ('$username','$reason','$time','No','$u_time')") or die("Error 3"); echo 'The user '.$username.' has been banned.'; }else{ echo 'You cannot ban that user.'; } } }else{ $user_ban = $_GET['user']; if(isset($user_ban)) { ?> <form name="file_ban" method="post" action="?action=file"> Username: <input type="text" name="user" value="<?php echo $user_ban; ?>"><br /> Length of Ban: <select name="time"> <option value="1">1 Day</option> <option value="3">3 Days</option> <option value="5">5 Day</option> <option value="7">1 Week</option> <option value="15">15 Days</option> <option value="30">1 Month</option> <option value="90">3 Months</option> <option value="99999999999">∞ Infinity (Permaban)</option> <option value="00">IP Ban (Does not expire)</option> </select><br /> Reason: <br /> <textarea name="reason" cols="50" row="4"></textarea><br /> <input type="submit" value="Ban"> <?php }else{ } } }else{ // If session is not set header("Location: index.php"); } ?> If you need any explanation of what anything does, just please ask. Thank you!
  16. I added the echo like you asked and it echo'ed out what I put into the form. UPDATE global SET status='asdsadsad' WHERE id='1'
  17. Hello there. I have a small form the inputs a new message into the column 'status'. But when I insert the new text, it deletes whatever is already in the column and leaves it blank. It will never add the new text to the column. Here is the form: $status_sql=mysql_query("SELECT status FROM global"); $status_data=mysql_fetch_assoc($status_sql); echo '<br /><br />Current Status Message: '.$status_data['status'].'<br />'; echo '<form name="status" method="post" action="?page=panel&action=sdo"><input type="text" class="console" name="status"> <input type="submit" class="cbutton" value="Enter"></form>'; $status = mysql_real_escape_string($_POST['status']); $update=mysql_query("UPDATE global SET status='$status' WHERE id='1'") or die('Query: ' . $update . '<br />Failed with: ' . mysql_error()); echo '<br />Status changed to: '.$status.''; If you need more info, just let me know. Thank you a million!
  18. Hello there, I have run into a problem. I have a search box, which searches through my database and gets results hopefully. But I need to be able to print the list. There is the problem. If I just print the page, it does not print the results. Here is the search.php with the php and the current print javascript. -Search By Address or Postcode-<br> <form name="search" method="post" action="search.php" id="searchform"> Query: <input type="text" name="name"> <input type="submit" name="submit" value="Search"></form> <br><br> -Search By REFID-<br> <form name="search2" method="post" action="search.php" id="searchform2"> Query: <input type="text" name="name2"> <input type="submit" name="submit2" value="Search"></form> <br><br> <?php if(isset($_POST['submit'])){ if($_POST['name'] > NULL){ $name=$_POST['name']; $sql="SELECT * FROM propertyaddress WHERE `address 1` LIKE '%" . $name . "%' OR `postcode` LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set ?> <SCRIPT LANGUAGE="JavaScript"> if (window.print) { document.write('<form>' + '<br><input type=button name=print value="Print Results" ' + 'onClick="javascript:window.print()"></form>'); }</script> <script language="javascript" type="text/javascript"> <?php while($row=mysql_fetch_array($result)){ echo "<ul>\n"; echo '<a href="display.php?id='.$row['id'].'">'.$row['address 1'].', '.$row['address 2'].' at '.$row['postcode'].'</a><br>'; echo "</ul>"; } } else{ echo "<p>Please enter a search query</p>"; } } I'm at a lost. I'm not sure what to do, I don't think the code as anything to do with printing, but I put it there just in case. I thought about writing it to a temp html page in a popup, but I don't really no how to do that really well. I appreciate any help or suggestions you give.
  19. Yep it makes perfect sense, thank you very much.
  20. Well, the main purpose I would want this if there is an error that only occurs under certain conditions that I never seen. So that if there is an error, and I'm not that one that views it, it sends it to the error's table to be view easily and I can record what happened without actually it occurring to me.
  21. Hello there, I am trying to build my site more efficient by sending me error messages that occur. I have decided that most of my errors are mysql errors. Thinking about what to do, I tried to put an insert query in the die message. Here is my line of code below. $globalsql=mysql_query("SELECT * FROM global") or die(' $error=mysql_query("INSERT INTO errors (name, identity, user,) VALUES ('"'Error 1'"', '"'global_functions.php'"', '"'System'"')") '); However, I get this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in global_functions.php on line 4 Which is that line. Any ideas? Thanks!
  22. Awesome! I will try to fit it into my code and get it working, thanks a mil!
  23. thank you for that link and I have bookmarked it! It may end up being useful, but how could I reword this 'GROUP BY type' to fit my query? There really isn't another column that would work the same way.
  24. Hello, I am trying to add all rows in the same column together. So here is the basic scheme: id l column1 1 l 1 2 l 2 3 l 3 Second table id l variable1 1 l 3 2 l 5 3 l 6 I basically want to add 5+3+6 and set it to a variable named '$total'. Would this be done using while loops? Here is the code I have been messing with. $sql="SELECT column1 from table1 where id='$userid'"; // userid would be set near the top of the page $sql2=mysql_query($sql,$conn); while($rows=mysql_fetch_array($sql2)){ $getid = $rows['column1']; $sql3="SELECT variable1 FROM table2 where id='$getid'"; $sql4=mysql_query($sql3,$conn); while($items=mysql_fetch_array($sql4)){ // Then I'm getting lost... } } Can you at least see what I am trying to do? I'm not even sure if this is the right approach, any help would be appreciated!
  25. oh wow, I didn't even realize that, thanks a bunch!
×
×
  • 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.