trq
Staff Alumni-
Posts
30,999 -
Joined
-
Last visited
-
Days Won
26
Everything posted by trq
-
Using php it would be simple.... <?php echo file_get_contents('http://www.hobbyking.com/hobbyking_api.asp?id=9532&switch=4#switch=3'); ?> This is the HTML help board though.
-
That would be correct.
-
What does doesn't work mean? In the last part you still aren't selecting any field (see my link above). You then never actually check to see if your query returned any results. if ($get_other = mysql_query("SELECT clan_name FROM clans WHERE clan_name='$clan_name'")) { $check = mysql_num_rows($get_other); if ($check) { echo "Yes."; // clan already exists } else { echo "No."; // clan not found } }
-
<?php session_start(); $session = $_SESSION['user']; $mysql_host = "localhost"; $mysql_username = "root"; $mysql_password = ""; $mysql_database = "project11"; mysql_connect($mysql_host, $mysql_username, $mysql_password); mysql_select_db($mysql_database); if(!$session) { echo "Please <a href='login.php'>login</a> first, or <a href='index.php'>go home</a>."; } else { $clan_name = $_POST['clan']; $ip = $_SERVER['REMOTE_ADDR']; $date = date("M-D-Y"); if(!$clan_name) { echo "Enter in a clan name: <form action='register_clan.php' method='POST'><input type='text' name='clan'><input type='submit' value='Register Clan'></form>"; } else { if ($get_other = mysql_query("SELECT FROM clans WHERE clan_name='$clan_name'")) { $check = mysql_num_rows($get_other); echo "Yes."; } else { echo "No."; } } } ?>
-
Well then, considering you only posted 18 lines of code, I can't see any parse error on line 28.
-
See here http://dev.mysql.com/doc/refman/5.1/en/select.html. I'm honestly over repeating myself.
-
PHP running properly on root, but not on subfolders
trq replied to reyjany's topic in PHP Installation and Configuration
That same code could not possibly produce that result. Post the actual code. -
I'm not sure how many times I need to say it, you need to SELECT a field.
-
As I said earlier, the if statement checks to see if the query fails or succeeds. It might be confusing because it also assigns a value to $get_other at the same time. The same thing could be written as.... $get_other = mysql_query('SELECT foo FROM bar'); if ($get_other) { $check = mysql_num_rows($get_other); } else { // query failed } You need to ALWAYS check the value returned by mysql_query isn't false before attempting to use it.
-
Just because your code has worked previously doesn't mean it was at all well written. I'm not getting mad or whatever, just trying to explain the benefits of writing good code. Do you want to write good code?
-
Oh, and the error you are getting in this example is because your query failed (and you didn't check it for success like I said (in my very post) that you always should.eg; $get_other = mysql_query("SELECT FROM clans WHERE clan_name='$clan_name'"); $check = mysql_num_rows($get_other); Should be.... if ($get_other = mysql_query("SELECT somefield FROM clans WHERE clan_name='$clan_name'")) { $check = mysql_num_rows($get_other); } else { // handle error } Notice I also fixed your query to select somefield? This has all been posted before, you need to read the replies.
-
Again same issue. In this example, $get_other is assigned the value returned by mysql_query(). You then, pass it to mysql_query().
-
How to copy dynamically generated web page source
trq replied to darjsuas's topic in PHP Coding Help
Source code that is manipulated by Javascript client-side does not show up within the normal source because it needs to be parsed by the browsers Javascript engine which then manipulates the dom. I'm not sure you could capture this without using some sort of browser plugin. -
How to copy dynamically generated web page source
trq replied to darjsuas's topic in PHP Coding Help
You just need to call the file in question via a url. This will allow the server to process the php and will return any dynamically generated html. $text = file_get_contents('http://domain.com/file.php'); -
One thing in my code I just noticed however is the ELECT statement doesn't actually select anything. It should be.... $sql = "SELECT clan_name FROM clans WHERE clan_name='$clan_name'"; or similar. I simply copied your queries.
-
It does NOT match up. There is no way I would format my code in such a poor manner for one. I am trying to show you best practices. In reply #10 $check is the result of a call to mysql_query(), you then pass it again to mysql_query(). Programing is all about the details, give a computer one incorrect instruction and you will not be forgiven. As for the rest of reply #10. The code is all over the place. Your using loops when you don't likely need them, you have removed all error handling, variables seem to appear from nowhere and the list goes on. I don't want to sound harsh but you need to look at the examples given.
-
Have another look over my code.
-
The first if statement simply checks that the query worked. You should always check a query actually succeeds before trying to use any result from it. The second if statement checks to see if the query returned any results, if it did it displays a message saying the clan already exists. I didn't really read your code too much because its pretty messy, but you will notice there is a fair amount of error trapping in my code, this is what makes finding errors easier.
-
I'll assume $clan_name, $session, $ip and $date have already been validated and sanitized. <?php $sql = "SELECT FROM clans WHERE clan_name='$clan_name'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { echo "A clan with this name already exists! <a href='register_clan.php'>Back</a>"; } else { $sql = "INSERT INTO clans VALUES ('', '$clan_name', '$session', '$ip', '', '$date')"; if (mysql_query($sql)) { if (mysql_affected_rows()) { $clan_id = mysql_insert_id(); $sql = "UPDATE users SET clan='$clan_id' WHERE username='$session'"; if (mysql_query($sql)) { echo "The clan ". $clan_name ." has been registered successfully, as ". $session ." (you) being the leader. <a href='index.php'>Home</a>"; } else { trigger_error(mysql_error() . ' ' . $sql); } } } else { trigger_error(mysql_error() . ' ' . $sql); } } } else { trigger_error(mysql_error() . ' ' . $sql); } ?>
-
Can you indent your code so it is readable?
-
Of course you can make a file full of functions then include it wherever you need it.
-
Its not really much help not seeing actual code but something like this will likely help you. $query ="SELECT * FROM databasetable where userId = " . $_SESSION['userid']; Not that the $_SESSION array is all caps.
-
All user inputted data should be passed through mysql_real_escape_string. You could even put it within your cndstrips function though you need to make sure you have a database connection before using it. function cndstrips($str) { if (get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); }
-
Considering you where asking about installing a server yesterday, why not try out installing a Linux distro like Debian inside of virtualbox. From there you could install and configure the complete amp stack and have yourself a very nice little dev environment. I know its not a programing project but it will be very useful, fun & educational.