
Hangwire
Members-
Posts
41 -
Joined
-
Last visited
Everything posted by Hangwire
-
Thank you all for your replies. Your feedback has been very helpful, and I'm going to re-do the entire project.
-
Thank you for your reply! Nah, I'm absolutely sure I didn't add them. This is the code of every php script in the whole project: Add-To-Database script: <?php $cocode = $_POST['cocode']; $coname = $_POST['coname']; mysql_connect ("pdb1.myhostingcompany.com", "countries", "*********") or die ('Error: '. mysql_error()); mysql_select_db ("countries") $query="INSERT INTO countries (cocode, coname) VALUES ('".$cocode."', '".$coname."')"; mysql_query($query) or die ('Error updating database'); echo " <html> <body> <center> Success! Country added. </center> </body> </html> " ; ?> Search-In-Database script: <?php mysql_connect ("pdb1.myhostingcompany.com", "countries","**********") or die (mysql_error()); mysql_select_db ("countries"); $term = $_POST['term']; $sql = mysql_query("select * FROM countries WHERE cocode = '$term'"); $num_rows = mysql_num_rows($sql); if ($num_rows == 0) { echo "No results found."; exit; } while ($row = mysql_fetch_array($sql)){ echo '<br/> Code: '.$row['cocode']; echo '<br/> Country: '.$row['coname']; echo '<br/><br/>'; } ?> I've searched the entire database for those names and couldn't find a thing. I've examined the entries for numbers 380, 401 and 403, everything looks normal. I can extract the database into an .sql, but I think that's a bit redundant. If anyone wants it, I can send it to them. Thank you for your time.
-
Hello everybody, An year ago while learning php I made a basic function to insert rows in a database and then a function to read from that database. Tl;dr I made a barcode reader. You enter the first three or two digits from the barcode of a product and you get what country it's produced in. A month ago I tried it out just by accident because some of my friends were wondering about where a product was made and my tool came to mind. When I enter 380 (Code for Bulgaria), Bulgaria pops up along with a line under it that says Jesus. When I enter 401 (One of the codes for Germany), Germany comes up along with three names - Leah, Nathaniel and Robert. 403 is another code for Germany. When I enter that, along with Germany comes up Destiny. I honestly have no explanation for this except that it's maybe some kind of SQL insert hack and someone tried to be funny. You can all test this out here: http://training.nbrain.net/searchform.html Thanks.
-
Display certain page if no results from query?
Hangwire replied to Hangwire's topic in PHP Coding Help
Thank you, I presume I can insert html code in the area between the comas? -
Hello all. I'm using this code to go through the database and output certain user-defined numbers <?php mysql_connect ("pdb1.awardspace.com", "anastasov_db","moscow1945") or die (mysql_error()); mysql_select_db ("anastasov_db"); $term = $_POST['term']; $sql = mysql_query("select * FROM countries WHERE cocode = '$term'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Code: '.$row['cocode']; echo '<br/> Country: '.$row['coname']; echo '<br/><br/>'; } ?> Now how would I go about making a page that appears if the script can't find any results in the database? Thank you in advance
-
My bad, removed the wildcards at $term, it works fine now. Thanks everyone!
-
$sql = mysql_query("select * FROM countries WHERE cocode = '%$term%'"); This is the change I made, but now it doesn't give any output at all.
-
Hello all. First of all, if this isn't the right place for this topic, please excuse me and may the moderators/admins move it where it should belong. Second, I'm trying to make a mysql search - Everything works, but if say, a user searches for 34 it displays all numbers that have the number 34 in them. I want the results to be exact - if a user searches for 34, to display only 34, not 334, 5034 or 3401 (like it happens now). Here's the code: <?php mysql_connect ("**************", "*******","*****") or die (mysql_error()); mysql_select_db ("********"); $term = $_POST['term']; $sql = mysql_query("select * FROM countries WHERE cocode LIKE '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Code: '.$row['cocode']; echo '<br/> Country: '.$row['coname']; echo '<br/><br/>'; } ?> If you have any questions, you're welcome to ask them in the thread. Thank you in advance
-
Thank you for your time, I fixed it myself. It was a very stupid error on my behalf, in the html input form I put the of it as "password", but $_POST was looking for "pass". Fixed it and everything works like a charm.
-
PHP Function problem - article not found.
Hangwire replied to Hangwire's topic in Apache HTTP Server
1) Wont bump, but there's another rule - All users must be courteous to others. 2) As I said in the first post, it was actually very late so... excuse me, in every post after the first one I presumed I had already mentioned it was concerning apache - didn't do that, but I gave an actual link, so it should have been pretty obvious. Either way, my mistake. Thank you so much for your help, I edited the directory and it's working like a charm! All the best! -
Be a little more specific, what error does it exactly output?
-
I don't want to create a thread about another simple problem, but here it is... <?php $name = $_POST['name']; $pass = $_POST['pass']; // $ip = $_SERVER['ip']; mysql_connect ("localhost", "root", "****") or die ('Error: '. mysql_error()); mysql_select_db ("data"); $query="INSERT INTO data (name, pass) VALUES ('".$name."', '".$pass."')"; mysql_query($query) or die ('Error updating database'); In this case, the script only writes the name in the database, but not the pass. The database fields are identical, both being varchar's. So, what gives?
-
PHP Function problem - article not found.
Hangwire replied to Hangwire's topic in Apache HTTP Server
Not at all what I had in mind. I expect to see a reply in a good tone, just as I always refer to anybody else on this site. But when somebody is condescending... People should know more than just scripting languages. Let's go back on topic, though. Any ideas? -
PHP Function problem - article not found.
Hangwire replied to Hangwire's topic in Apache HTTP Server
It's an apache error! That's the whole point! How can a php script output an "Object not found!" error from apache?! And, to Dan: 1) You know, there is more than 1 timezone on this planet. 2) Have you ever worked with apache, or do I need to be dead specific about everything? 3) Thank you. -
Thank you, worked like a charm
-
Hi everybody, my goal is to get the IP of someone accesing the site, writing the time and date along with his IP into the database. Of course, I would be adding the script to my frontpage when I make it work. But I get this error: I've checked line 8, I dont find anything in it that is out of place. Here is the code: <?php $ip = $_SERVER['REMOTE_ADDR']; $date = date("m.d.y"); $time = time(); mysql_connect ("localhost", "root", "********") or die ('Error: '. mysql_error()); mysql_select_db ("ip"); $query = "INSERT INTO ipdo (time, date, ip) VALUES ('"$time"', '"$date"', '"$ip"')"; mysql_query($query) or die ('Error updating database'); echo "Database updated with: " .$ip. "" ; ?> This is the first script I write entirely on my own, so be gentle Help?
-
PHP Function problem - article not found.
Hangwire replied to Hangwire's topic in Apache HTTP Server
bump? -
PHP Function problem - article not found.
Hangwire replied to Hangwire's topic in Apache HTTP Server
Indeed it was late. This is the function for posting an article <?php // Connect to database include("../settings.php"); $conn = mysql_connect($server, $user, $pass); if (!$conn) die ("Couldn't connect to the database"); mysql_select_db($db, $conn) or die (mysql_error()); // Data from the form $article_id = ($_POST['article_id']); $name = mysql_real_escape_string($_POST['name']); $website = mysql_real_escape_string($_POST['website']); $email = mysql_real_escape_string($_POST['email']); $comment = mysql_real_escape_string($_POST['comment']); $date = date("Y-m-d h:i:s"); $ip = $_SERVER["REMOTE_ADDR"]; // Then we check if everything is filled out if ($name == ""){ echo "<div style='margin:0 auto;width:200px;text-align:center;'> <img src='../images/caution.gif' alt='caution' /><br /> <p>Please fill in your name!</p> <p><a href='javascript: history.go(-1)' style='color:#f7941d;'>Click here</a> to go back..</p> </div>"; } elseif ($comment == ""){ echo "<div style='margin:0 auto;width:200px;text-align:center;'> <img src='../images/caution.gif' alt='caution' /><br /> <p>You <b>have</b> to fill in the comment!</p> <p><a href='javascript: history.go(-1)' style='color:#f7941d;'>Click here</a> to go back..</p> </div>"; } else{ $query = "INSERT INTO comments (article_id,name,website,email,comment,date,ip) VALUES ('$article_id','$name','$website','$email','$comment','$date','$ip')"; $result = mysql_query($query) or die ("Error = ".mysql_error().""); header("location: ../includes/ok2.php"); } mysql_close($conn); And this is what I found for displaying the article. function DisplayLatest(){ // Includes the settings file include("settings.php"); // Connect to database Connect(); // Fetch from database $query = "SELECT * FROM articles ORDER BY id DESC LIMIT ".$limit .""; $result = mysql_query($query); $numrows = mysql_num_rows($result); // If there are results, show them if (!$numrows == ""){ while($row = mysql_fetch_array($result)){ $id = $row['id']; $name = Secure($row['name']); $title = Secure($row['title']); $content = stripslashes($row['content']); $date = $row['date']; $ip = $row['ip']; $on = date('F j, Y', strtotime($row['date'])); $at = date('g:i a', strtotime($row['date'])); echo " <div class='article'> <h2><a href=\"article.php?id=$id\" title=\"Read more about $title\">$title</a></h2> <span class='author'>By: $name on $on @ $at</span><span class='comments'><a href='article.php?id=$id'>"; echo CheckComments($id); echo "</a></span> <div class='post'><p>"; echo $content; echo "</p></div></div>"; } } Again, I'm receiving an "Object not found" error when it's clearly written in the database - thats the whole issue. -
Hi everybody. I'm using a very simple article script that displays news and so on where added. It also has an admin panel of sorts, very simple, from where you actually post the articles. I have this problem - The news show up on the front page just fine, but when I click the link to the article itself the server says that it cannot be found. I checked the database, checked the connections and everything. I also don't see the posting comment button show up, but everything is okay with the script and the database - perhaps a formatting problem? Anyway, you can try THIS for yourself to see what I'm talking about. Here is the code: function DisplayComments(){ // For the database settings include("settings.php"); // Then make the connection Connect(); // To know what article we look at $article = ($_GET['id']); // To make every second row another color $count = 0; // Fetch the results from database $query = "SELECT * FROM comments WHERE article_id LIKE '$article' ORDER BY id DESC"; $result = mysql_query($query); $numrows = mysql_num_rows($result); // If there are any results, show them if (!$numrows == ""){ while($row = mysql_fetch_array($result)){ $name = Secure($row['name']); $website = Secure($row['website']); $email = Secure($row['email']); $comment = htmlentities($row['comment']); $date = $row['date']; $on = date('F j, Y', strtotime($row['date'])); $at = date('g:i a', strtotime($row['date'])); $color = ($count % 2) ? $color1 : $color2; $border = ($count % 2) ? $border1 : $border2; echo "<div class='comm' style='background:$color;border-top:1px solid $border;border-bottom:1px solid $border;'>"; if (!$website == ""){ echo "<span class='by'><a href=\"$website\">$name</a></span>"; } else{ echo "<span class='by'>$name</span>"; } echo"<br /><span class='time'>$on @ $at</span><p>"; echo BBCode($comment); echo "</p></div>"; $count++; } } // If there are no results else{ echo "<p>There are no comments for this article yet.</p>"; } mysql_close(); } function CheckComments ($id){ // First include the settings file include("settings.php"); // Then we make the connection Connect(); // Now we do the counting $result = mysql_query("SELECT COUNT(*) as count FROM comments WHERE article_id LIKE $id") or die("Error fetching number in DB<br>".mysql_error()); $row = mysql_fetch_array($result); $numofrows = $row['count']; $total = ceil($numofrows / $archive); // To display 'comment' if there are more then one // Otherwhise display 'comments' if ($numofrows == 1){ $comm = "Comment"; } else{ $comm = "Comments"; } // If there are any comments, output the number of comments if (!$total == ""){ echo "$numofrows $comm"; } // Otherwhise we output a 'no' else{ echo "<br> No $comm"; } } That gives me an only an "Object not found". Also, as I said, I don't know how to add the comment button to each article as it currently doesn't show. Here is the comment form function: <?php // Runs the function the display only one article DisplayOne(); ?> <h4>Comments:</h4> <?php // Runs the funtion to display the comments that belongs to the article displayed DisplayComments(); ?> <?php echo "<h5>Add Your Comment</h5>"; // Variable to know what article we are commenting on $article_id = intval($_GET['id']); // Includes the comment form include("comments/form.php"); ?> I hope you can understand what I tried to say, as it's 4.40AM here and my brain isn't working very well. Thank you in advance!
-
Alright, well I've decided to let that old script go and try with this: <?php function check_port($port) { $conn = @fsockopen("127.0.0.1", $port, $errno, $errstr, 0.2); if ($conn) { fclose($conn); return true; } } function server_report() { $report = array(); $svcs = array('21'=>'FTP', '22'=>'SSH', '25'=>'SMTP', '80'=>'HTTP', '110'=>'POP3', '143'=>'IMAP', '3306'=>'MySQL'); foreach ($svcs as $port=>$service) { $report[$service] = check_port($port); } return $report; } $report = server_report(); ?> <table> <tr> <td>Service</td> <td>Status</td> </tr> <tr> <td>FTP</td> <td><?php echo $report['FTP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>SSH</td> <td><?php echo $report['SSH'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>SMTP</td> <td><?php echo $report['SMTP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>HTTP</td> <td><?php echo $report['HTTP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>POP3</td> <td><?php echo $report['POP3'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>IMAP</td> <td><?php echo $report['IMAP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>MySQL</td> <td><?php echo $report['MySQL'] ? "Online" : "Offline"; ?></td> </tr> </table> So far so good, it works like a charm on its own but I can't implement it into anything. For example, when I put <?php include("server2.php"); ?> In the right place on my website, it doesn't show anything. The script is in the same folder... Help?
-
bump?
-
Thank you for the quick reply! I took good look at what you gave me, I tried it, but again, to no avail. I added <?php include(server2.php); ?> on the place i needed it, but it doesn't show up, but when I open server2.php from the server I can see it works and displays everything properly. My server2.php (the script) is in the main directory of apache (htdocs). I also tried to put it in the folder of the current index im working on, but again - it doesn't work. Help?
-
Hi all! Yet again I have a problem. I really couldn't find what the heck's wrong with this thing. It's extremely simple and still... I'm trying to put a php script in my website to monitor the status of my FTP and HFS servers. Help? <TITLE>Server Status</TITLE> <?php $data .= " </div> <center> <div style=\"border-bottom:1px #999999 solid;width:480;\"><b> <font size='1' color='#3896CC'>Server Status</font></b> </div> </center> <br>"; //configure script $timeout = "1"; //set service checks $port[1] = "80"; $service[1] = "Apache"; $ip[1] = "localhost"; $icon[1] = "habbo.jpg"; $alt[1] = "Apache"; $port[2] = "8080"; $service[2] = "HFS Server"; $ip[2] = "localhost"; $icon[2] = "web.png"; $alt[2] = "HFS Server"; $port[3] = "21"; $service[3] = "FTP Server"; $ip[3] = "localhost"; $icon[3] = "web.png"; $alt[3] = "FTP Server"; // // NO NEED TO EDIT BEYOND HERE // UNLESS YOU WISH TO CHANGE STYLE OF RESULTS // //count arrays $ports = count($port); $ports = $ports + 1; $count = 1; //beggin table for status $data .= "<table width='480' border='1' cellspacing='0' cellpadding='3' style='border-collapse:none' bordercolor='#CCCCCC' align='center'>"; while($count < $ports){ if($ip[$count]==""){ $ip[$count] = "localhost"; } $fp = @fsockopen("$ip[$count]", $port[$count], $errno, $errstr, $timeout); if (!$fp) { $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/off.png'></td></tr>"; } else { $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/on.png'></td></tr>"; fclose($fp); } $count++; } //close table $data .= "</table><div>"; echo $data; ?> The output of this is... Also, does somebody have a link or something to a tutorial/pre-made script (although I'd like to follow instructions about it) about server statistics? I want to have data on how much a certain partition on the server has free or full. Thank you in advance.
-
Problem is i've got my mind at seperate places, you could say im not that concentrated. Stupid mistake on my behalf, oh well. Thank you.
-
Parse error: syntax error, unexpected T_VARIABLE in D:\Program Files\xampp\xampp\htdocs\search.php on line 34 I'm starting to lose hope about this thing...