Jump to content

bschultz

Members
  • Posts

    486
  • Joined

  • Last visited

Everything posted by bschultz

  1. I have a text file with this content: So, item1 is in the list 3 times, item2 just once and item3 is in twice...as is item4. The list is 36 items long. I need to create a random order list for these items. Ideally, I'd like to have this format: item1|3 item2|1 item3|2 item4|2 which is item|times appearing in the list I know that this code $filename="words.txt"; $words=file($filename); shuffle($words); $word=$words[0]; echo $word; will give me a random list, but not for the repeated stuff...and I'd like to limit it so that item1 can't repeat in proximity to another item1 in the list. I have no idea how to pull this off. Any ideas? Thanks. Brian
  2. there are four radio buttons (all named q1). Answer 1 will insert a "1" in the db. Answer 2 will insert a "2" in the db. Three inserts 3 and four inserts 4. So the numbers 1-4 are inserted into the db
  3. I wrote a viewer poll in php (not sure if this should go in the php section of here...) that on occasion is being hit by spammers. Here's the code: mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $ip=$_SERVER['REMOTE_ADDR']; $sqlquery = "INSERT INTO $db VALUES('$ip', '$_POST[q1]')"; $results = mysql_query($sqlquery); if (empty($_POST[q1])) { Print "You must make a selection. Please us your back button and select an answer"; } else { if ($results){ echo '<meta http-equiv=Refresh content=1;url="page.php?page=poll_results">'; } else{ echo '<meta http-equiv=Refresh content=1;url="page.php?page=poll_oops">'; } } mysql_close (); In essence, the code writes the users ip and the vote into the db. It's supposed to keep the user from not selecting an answer (this part: if (empty($_POST[q1])) { Print "You must make a selection. Please us your back button and select an answer"; } ) but it doesn't keep the spammers from hitting the page (I'm assuming looking for a bad email form to use for spam...). How can I re-write this to ensure that a vote needs to be made? Thanks. Brian
  4. Update... no errors with this code...but no insert into the db either! The only good thing is that I appear to be connecting to the DB with SSL! $link = mysqli_connect("localhost", "xxx", "xxx", "paypal"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "insert IGNORE into purchases values ('$pdate', '$first_name', '$last_name', '$payer_status', '$payer_email', '$payer_id', '$payment_status', '$amount', '$txn_id', '$txn_type', '$payment_type', '$custom', '$mc_fee', '$pending_reason', '$verify_sign', '$pass', '$cell', '$provider')"; mysqli_query($link, $query); echo "<p>Thank You, you need to set your password to listen.</p><meta http-equiv=Refresh content=3;url='page.php?page=setpassword'>"; /* close connection */ mysqli_close($link); ?> All of the inserts are defined properly before the code quoted above. Thanks for any help!
  5. I'm using options because that's all I could find online for code...and I'm using the default mysql config file (/etc/mysql/my.cnf) Brian
  6. I'm having a hard time getting this to work. I've followed the step from the MySQL manual on how to generate and save the certs and also how to change the my.conf to use those certs. I've also checked the DB that "use_ssl" is active...so now I need to write the code to connect. Here's what I've tried: $host = "localhost"; //change this to whatever your host is, usually localhost $username = "xxx"; //change this to your mysql username $password = "xxx"; //change this to whatever your password is $DBName = "paypal"; //DO NOT CHANGE THIS FIELD $port = "3306"; $socket = "/var/run/mysqld/mysqld.sock"; $mysqli = new mysqli( ); $mysqli->init( ); $mysqli->options(mysqlI_READ_DEFAULT_FILE, '/etc/mysql/my.cnf'); $mysqli->options(mysqlI_OPT_LOCAL_INFILE, false); $mysqli->options(mysqlI_OPT_connect_TIMEOUT, 600); $mysqli->real_connect($host,$username,$password,$DBname,$port,$socket,mysqlI_CLIENT_ssl); $usql = "insert IGNORE into purchases values ('$pdate', '$first_name', '$last_name', '$payer_status', '$payer_email', '$payer_id', '$payment_status', '$amount', '$txn_id', '$txn_type', '$payment_type', '$custom', '$mc_fee', '$pending_reason', '$verify_sign', '$pass', '$cell', '$provider')"; and I get errors. Which is the load my.cnf line Which is the line ---$mysqli->options(mysqlI_OPT_LOCAL_INFILE, false); Which is the line ---$mysqli->options(mysqlI_OPT_connect_TIMEOUT, 600); Which is the line ---$mysqli->real_connect($host,$username,$password,$DBname,$port,$socket,mysqlI_CLIENT_ssl); and this last one...which obviously means it didn't connect right Can someone point me in the right direction here? I hate to say it, but the documentation (php side, not the mysql side) is pretty scarce on how to connect. Thanks.
  7. This was a Postfix config issue...not the php code. Thanks!
  8. Still doesn't work... $subject = "Subject: Score Updates"; $headers .= "Reply-To: me@mydomain.com\n"; $headers .= "From: my name <me@mydomain.com>\n"; //send the sms email foreach ($rec as $r) { mail ($r,$subject,$message,$headers); } echo $r, $subject, $message, $headers; echo '<meta http-equiv=Refresh content=10;url="http://mydomain.com/sendatext.php">'; I still get the message...but it still says it's coming from www_data@mydomain.com Thanks for the help...any other other ideas?
  9. I'm trying to use PHP mail to send a text message to a phone...not very hard, and it's "somewhat" working. The only issue that I'm having is the headers aren't right. The text message is saying that it's from "www_data@myserver.com" instead of "myemail@myserver.com" Here's the code: <? $message = $_POST["text"]; //build peices of the email message $subject = "Subject: My Subject"; $to = $_POST["number"]; //replace 'phone-x' with a working cell phone number $rec = array("$phone-1@vtext.com", "$phone-2@utext.com" , "$phone-3@txt.att.net" , "$phone-4@messaging.sprintpcs.com"); $headers = 'From: me@myserver.com . "\r\n" . "Reply-To: my_cell_phone_number" . "\r\n\n" '; //send the sms email foreach ($rec as $r) { mail ($r,$subject,$message,$headers); //close foreach } echo '$r,$subject,$message,$headers <meta http-equiv=Refresh content=10;url="sendtxt.php">'; ?> Can someone please tell me what I'm doing wrong here? Thanks.
  10. My God do I feel dumb! In working on this last night (way too late) I had a typo in my html form to login...every works now! Thanks, and I'm sorry!
  11. If I take out the AND password='$final_password' it still comes up with a No Matches
  12. Still not working...and I've added some further debugging <?php $final_email = $_POST[email]; $final_password = md5($_POST[password]); $dbc = mysql_pconnect('localhost','user','password'); mysql_select_db('mix',$dbc); $sql = "SELECT * FROM vip WHERE email='$final_email' AND password='$final_password'"; $dbq = mysql_query($sql,$dbc); while ($row = mysql_fetch_array($dbq)) { echo ".$row[email]."; echo ".$row[password]."; } if (!$dbq) { echo "Could not successfully run query from DB: " . mysql_error(); exit; } if (mysql_num_rows($dbq) == 0) { echo "No Matches"; } ?>
  13. I'm doing some debugging on a script to authenticate an md5 password. Here's the code to write the md5 password to the db: $md5_pass = md5($_POST[password]); mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sqlquery = "INSERT INTO vip VALUES('$_POST[email]', '$md5_pass', '$_POST[name]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[phone]', '$_POST[age]')"; and here's the authentication part: $final_email = $_POST[email]; $final_password = md5($_POST[password]); $dbc = mysql_pconnect('localhost','user','password'); mysql_select_db('mix',$dbc); $sql = "SELECT * FROM vip WHERE email=$final_email AND password=$final_password"; $dbq = mysql_query($sql,$dbc); while ($row = mysql_fetch_array($dbq)) { echo ".$row[email]."; echo ".$row[password]."; } I'm getting a mysql_fetch_array(): supplied argument is not a valid MySQL result resource error. Any ideas what's wrong here? Thanks!
  14. this code works $sql = "SELECT date_col, title, text FROM brian WHERE date_col BETWEEN '2008-04-01' AND '2008-05-01' order by date_col desc";
  15. I'm trying to select only records from the month of March. I've tried... $sql = "SELECT date, title, text FROM table ORDER by date DESC WHERE `date` = DATE_SUB(CURDATE(),INTERVAL -2 month)"; and this... $sql = "SELECT date, title, text FROM brian ORDER by date DESC WHERE `date` BETWEEN DATE_SUB(CURDATE( ) ,INTERVAL -2 MONTH) AND CURDATE( )"; Neither are working. Can anyone help, please?
  16. That did it. Thanks so much! I'm not sure how it did it, but it did it. So is this <?php echo $i; ?> just getting the correct value to the array? Thanks again.
  17. sasa, I tried that code, and it still didn't work. Here's the code for the form: <?php require "config.php"; //do your normal mysql setup and connection calls $dbc = mysql_connect($host,$username,$password); mysql_select_db('testing',$dbc); //now get stuff from a table $sql = "SELECT row_number, date, type, event, action, comments FROM cancellations ORDER BY event"; ?> other non-php page layout stuff <?php $dbq = mysql_query($sql,$dbc); //now spit out the table and rows for the table $rs = mysql_query($sql,$dbc); $matches = 0; ?> more non-php layout stuff <form method="POST" action="edit_db.php"> table layout <?php while ($row = mysql_fetch_assoc($rs)) { $matches++; ?> <td> <input name="row_number[]" type="text" id="row_number" value="<?php echo"$row[row_number]" ?>" /> </td> <td><div align="center"><font color="#000000"> <input name="cmd[]" type="checkbox" id="cmd" value="delete" /> </font></div></td> <td><div align="center"><font color="#000000"> <input name="date[]" type="text" id="date" size="10" maxlength="10" value="<?php echo"$row[date]" ?>" /> </font></div></td> <td><div align="center"> <input name="type[]" type="text" id="type" size="10" maxlength="15" value="<?php echo"$row[type]" ?>" /> </div></td> <td><div align="center"> <input name="event[]" type="text" id="event" size="50" maxlength="250" value="<?php echo"$row[event]" ?>" /> </div></td> <td><div align="center"><font color="#000000"> <input name="action[]" type="text" id="action" size="20" maxlength="25" value="<?php echo"$row[action]" ?>" /> </font></div></td> <td><div align="center"><font color="#000000"> <input name="comments[]" type="text" id="comments" size="50" maxlength="300" value="<?php echo"$row[comments]" ?>" /> </font></div></td> </TR> <?php } if (! $matches) { echo ("</table>There are no weather related announcements today"); } echo "</TABLE>"; ?> <input name="submit" type="submit" value="Submit" /> <input type="reset" name="Reset" value="Reset" /> </form> If I try to delete row 3, row 1 is deleted...if I try to delete row 5, row 3 is deleted. So, I'm off by 2. The row numbers echoed in the form are correct, by the way, so the problem appears to be in the original script getting the wrong row number.
  18. I'm trying to write a script to edit and delete numerous records in a mysql table. The mysql is fine, but I'm getting the wrong row number. Here's the code: <?php require "config.php"; $conn1 = $connect; @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $date = $_POST[date]; $type = $_POST[type]; $event = $_POST[event]; $action = $_POST[action]; $comments = $_POST[comments]; $row_number = $_POST[row_number]; $cmd = $_POST[cmd]; for ($i=0;$i<count($_POST[event]);$i++){ if($cmd[$i] =="delete") { $sqldelete = "DELETE FROM cancellations WHERE row_number='$_POST[row_number]'"; $resultdelete = mysql_query($sqldelete) or die ("Error in Delete Query" . mysql_error()); echo "<meta http-equiv=Refresh content=1;url='/weather/edit.php'>" ; } else $usql = "UPDATE cancellations SET date='$date[$i]', type='$type[$i]', event='$event[$i]', action='$action[$i]', comments='$comments[$i]' WHERE row_number='$row_number[$i]'"; // above compiles query $dosql = mysql_query($usql); // executes query } if ($dosql){ echo "<p>Thank You, your entry has been submitted!</p> <meta http-equiv=Refresh content=1;url='/weather/edit.php'>"; } else{ echo mysql_errno().": ".mysql_error()."<BR>"; } mysql_close (); ?> I've also tried this: WHERE row_number='".$_POST[row_number]."'"; But that doesn't work either. With the second piece of code, I can edit, but can't delete. Any ideas where I've gone wrong? Thanks.
  19. you're right...as always! Thanks for the help. I'll repost in the php thread.
  20. I found out that I've got the wrong row number when deleting....even with this code "DELETE FROM cancellations WHERE row_number='".$_POST[row_number]."'" Also, with that code, I can't edit...with this code "DELETE FROM cancellations WHERE row_number='$row_number[$i]'"; however, I can edit, but it deletes the wrong record.
  21. neither one worked to delete...but I can now edit.
  22. I tried "DELETE FROM cancellations WHERE row_number='$row_number[$i]'"; and it seemed to work (I"m still testing)...what would the difference between the two statements be?
  23. That obviously isn't right!
  24. I'm trying to write a form script to edit or delete certain records in the DB. Here's what I have: <?php require "config.php"; $conn1 = $connect; @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $date = $_POST[date]; $type = $_POST[type]; $event = $_POST[event]; $action = $_POST[action]; $comments = $_POST[comments]; $row_number = $_POST[row_number]; $cmd = $_POST[cmd]; for ($i=0;$i<count($_POST[event]);$i++){ if($cmd[$i] =="delete") { $sqldelete = "DELETE FROM cancellations WHERE row_number='$_POST[row_number]'"; $resultdelete = mysql_query($sqldelete) or die ("Error in Delete Query" . mysql_error()); echo "<meta http-equiv=Refresh content=1;url='/weather/edit.php'>" ; } else $usql = "UPDATE cancellations SET date='$date[$i]', type='$type[$i]', event='$event[$i]', action='$action[$i]', comments='$comments[$i]' WHERE row_number='$row_number[$i]'"; // above compiles query $dosql = mysql_query($usql); // executes query } if ($dosql){ echo "<p>Thank You, your entry has been submitted!</p> <meta http-equiv=Refresh content=1;url='/weather/edit.php'>"; } else{ echo mysql_errno().": ".mysql_error()."<BR>"; } mysql_close (); ?> It's not editing or deleting the record, and I'm not getting an error. Any idea what I'm doing wrong?
  25. Thanks, gluck and fenway... ."ORDER BY DATE_FORMAT(starttime, '%T')"; did the trick.
×
×
  • 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.