peter_anderson
Members-
Posts
150 -
Joined
-
Last visited
Never
Everything posted by peter_anderson
-
I'd like to request testing of my forum script. http://www.calicosoft.com/community (Validation: http://www.calicosoft.com/phpfreaks.txt) Thanks in advance.
-
Here's a decent auto suggest tutorial: http://woork.blogspot.com/2008/03/php-components-autosuggest.html
-
I have a database called "mp_users" with the following setup: CREATE TABLE IF NOT EXISTS `mp_users` ( `id` int(10) unsigned default NULL auto_increment, `uid` int(10) unsigned NOT NULL, `username` varchar(100) NOT NULL, `email` varchar(50) NOT NULL, `points` int(10) unsigned NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; When I try to run the following query, I get an error: Error: Fatal error: Call to a member function query() on a non-object in /home/user/public_html/marketplace-functions.php on line 52 Here is the code: <?php require_once "config.php"; $sql = new mysqli($db1['host'], $db1['user'], $db1['pass'], $db1['db']); function checkUserExists($uid){ // Query $q = "SELECT COUNT(id) AS user_exists FROM `mp_users` WHERE uid=$uid LIMIT 1;"; echo $q; $q = $sql->query($q); $r = $q->fetch_assoc(); // Any results? if($r['user_exists'] == 0){ // redirect to runonce... header('Location: marketplace.php?do=runonce&return='.urlencode($_SERVER['QUERY_STRING'])); exit(); } } ?> Line 52 is the $q query. I really cannot see what the problem is. The database exists, I've tried it in phpMyAdmin and it runs without trouble, but this wont! Can anyone help? Thanks in advance
-
Thank you, that's fixed it. I know there was something small
-
I need to find <<!--{rep_[A NUMBER]}-->> and replace it with a function. I am currently using: <?php $rep['find'] = '<<!--{rep_(.*?)}-->>'; $rep['replace'] = ''.$reputation->postRating('$1').''; $html = preg_replace($rep['find'],$rep['replace'],$html); ?> But when I check the value in reputation->postRating, it doesn't match. Eg, <<!--{rep_4}-->> in the function is passed as 0 (after being passed through intval()). Can anybody help? It's probably something silly but I can't work it out.
-
Hi, There is an if statement, depending on which the Get variable 'offer' is set as. The variable for the number of points is $remove_points. Thanks for the proper way to do the sum
-
I have a file sharing script, where each file has a certain number of points. I need to subtract a set number of points from the total. I'm unsure about the logic of it. This is how I total the number of points: <?php $fq = "SELECT * FROM `files` WHERE owner='$username' AND active=1"; $fw = $sql->query($fq); $reward = 0; while($fr = $fw->fetch_assoc()){ $reward = $fr['points'] + $reward; }?> I'm thinking I should use a loop, while a the number to subtract is greater than or equal than 0. Can anyone help?
-
Form Error Checking - Showing the error?
peter_anderson replied to peter_anderson's topic in PHP Coding Help
@radar, it prints: Array ( ) When no fields or some fields are filled in. $e = array(); if(isset($_POST['submit'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email_a']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(!isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($fullname)){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.'); $continue = 0; } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.'); $continue = 0; } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.'); $continue = 0; } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.'); $continue = 0; } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.'); $continue = 0; } echo "<pre>"; print_r($e); echo "</pre>"; } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; -
Form Error Checking - Showing the error?
peter_anderson replied to peter_anderson's topic in PHP Coding Help
@radar, no that doesn't fix it. Thanks anyway I'm struggling to see the problem. -
prevent mail() email from showing up as phishing in outlook?
peter_anderson replied to toephu's topic in PHP Coding Help
Do your headers have "From" set? Is your internal site an IP address? -
Form Error Checking - Showing the error?
peter_anderson replied to peter_anderson's topic in PHP Coding Help
If I change the code so that the error shows if it is filled out, it shows the error: $e = array(); if(isset($_POST['submit'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email_a']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($fullname)){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.'); $continue = 0; } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.'); $continue = 0; } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.'); $continue = 0; } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.'); $continue = 0; } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.'); $continue = 0; } } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; -
I've decided to rewrite one a couple of my forms, to make them more user friendly. But I am having problems returning the error. I've created an array ($e) which has the field name ($e['field_name']) for the error, but it isn't displaying any errors. Here's the code: case "contact": $e = array(); if(isset($_POST['sb'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error,$evar){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(!isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name',$e['fullname']); } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.',$e['email_a']); } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.',$e['email_r']); } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.',$e['subject']); } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.',$e['problem']); } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.',$e['email_r']); } } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; Can anyone see what the problem is? Thanks
-
Hi, I want to list the latest topics in the category, but order them by the one with the latest posts. Here is the queries I use currently (which orders them by ID) $query = 'SELECT * from `topics` WHERE `category` = ' . $catid . ' AND `sticky` = 0 ORDER by `id` DESC '.$limit.''; // this one is within a loop for the results of the above $query = 'SELECT * from `posts` WHERE `topic` = ' . $row['id']; Is there any way I can join these queries, so it sorts DESC by the id in the posts column?
-
$sql = mysql_query("SELECT * FROM forum_groups") or die (mysql_error()); while ($row = mysql_fetch_object($sql)) { $groupid = $row->groupid; $forumid2 = $row->forumid; $groupname = $row->groupname; echo ' <td class="forum-left">'.$groupname.'</td> <td class="forum-middle">Topics</td> <td class="forum-middle">Posts</td> <td class="forum-right">Last Post</td></tr>'; $sql2 = mysql_query("SELECT * FROM forums WHERE groupid = $groupid") or die (mysql_error()); while ($row2 = mysql_fetch_object($sql2)) { echo '<tr><td class="forum2"> <a href="index.php?f='.$row2->id.'">' . $row2->name . '</a><br /> <h4 style="font-size:10px;">'.$row2->description.'</h4> </td><td class="forum">'; $id = $row2->id; $sql3 = mysql_query("SELECT * FROM threads WHERE forumid = '$id'") or die (mysql_error()); $num = mysql_num_rows($sql3); echo $num . '</td><td class="forum">'; $sql4 = mysql_query("SELECT * FROM forum_posts WHERE forumid = '$id'") or die (mysql_error()); $num2 = mysql_num_rows($sql4); echo $num2 . '</td><td class="forum">'; echo 'By '.$row2->lastpost.' <h5 style="font-size: 10px;">On '; echo date("F j, Y, g:i a", strtotime($row->date)); echo '</h5></td></tr><tr>'; } } Try this (I cleaned up some of the code, to the way I can read it better )
-
Sessions not storing? For login page.
peter_anderson replied to xxbrighidxx's topic in PHP Coding Help
Have you tried adding session_start() to the very top of ALL files? -
You could save the data to a database.
-
I think you want to post data from a form, mail it to your autoresponder with the headers set as "from: $_POST['email']", which the autoresponder would then respond to? Yes, it's possible.
-
Are you connected to the database? Not tested, but: <?php if(isset($_POST['box'])){ foreach($_POST['box'] AS $id) { mysql_query("UPDATE chair_appointments SET `allow_participation` = '1' WHERE `resid` = '$id'"); } } ?>
-
Sessions not storing? For login page.
peter_anderson replied to xxbrighidxx's topic in PHP Coding Help
I'm not very good with procedural PHP, but $_SESSION = mysql_fetch_array ($r, mysql_ASSOC); looks like it should be: <?php // ... $rows = mysql_fetch_array ($r, mysql_ASSOC); $_SESSION['userid'] = $rows['userid']; $_SESSION['userlevel'] = $rows['userlevel']; // ... ?> -
<?php $q = "SELECT * FROM `groups`"; $result = $sql->query($q); while($row = $result->fetch_assoc()){ // display header information $id = $row['id']; $q2 = "SELECT * FROM `forums` WHERE group = '$id'"; $result2 = $sql->query($q2); while($row2 = $result2->fetch_assoc()){ //display forum information //etc...
-
Just noticed that the month is not working. 24/Mar/2010 is changing to 2010-01-24 using SELECT STR_TO_DATE(date, '%j/%M/%Y')... It's the same for all months. What could be the problem?
-
Just found it, that $order_date should be: <?php $order_date = $r['STR_TO_DATE(date, \'%j/%M/%Y\')']; ?>
-
Thanks, How do I get the results from the MySql date time function query? Heres what I've got so far. <?php //some was stripped // date $today_date = date("Y-m-d"); // query $q = "SELECT STR_TO_DATE(date, '%j/%M/%Y') FROM `orders` WHERE id='$orderid' AND customer='$email'"; $rs = $sql->query($q); $r = $rs->fetch_assoc(); $order_date = $r['date']; // compare dates function date_diff($date1, $date2){ $current = $date1; $datetime2 = date_create($date2); $count = 0; while(date_create($current) < $datetime2){ $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current))); $count++; } return $count; } echo(date_diff('2010-01-01', $order_date)." days <br \>"); exit(); ?> How do I get the result of $q? Thanks
-
Hi there, I need to perform a check against the orders database to see if 30 days since the order has passed or not. The date is stored as "11/Apr/2010" (j/M/Y), but I am unsure of how to do so. Can anyone point me in the right place? Thanks