-
Posts
476 -
Joined
-
Last visited
Everything posted by xProteuSx
-
Thanks again. I do understand the importance of arrays. Through my little website project I am hoping to get a decent understanding of most of the common functions. I have not come up against any arrays as of yet, but I have just gotten to that part. I think I will be working on arrays for the next few days, so I will better understand all the functions soon. I guess the part that really stumped me is the fact that you transformed the array into a single string, then output it as such. I don't understand the benefits of this, but it sure is one way to go about getting this done. As for now, I did implement your code, and have modified it to suit my script. It is working as needed. Thanks.
-
Ken, thanks for the reply. I am quite unfamiliar with arrays. I understand the basic principles, but I don't work with them often, hence I do not know many of the commands and operations specific to them. I do not understand any of the following code: Why do you have to set this variable? what does it do? $tmp = array(); What does this foreach(? as ?) do? I have never seen this. foreach ($vars as $var) Why implode the $tmp variable? Maybe this has to do with the first question in the post ... echo implode("\n",$tmp)."\n"; Anyway, I'm looking this up to see if I can understand and learn something here. If you an post a reply that would be great.
-
Say I have 4 variables: $_1; $_2; $_3; $_4; I want to display them as a list, so, for example: echo '<ol>'; echo '<li>' . $_1; . '</li>'; echo '<li>' . $_2; . '</li>'; echo '<li>' . $_3; . '</li>'; echo '<li>' . $_4; . '</li>'; echo '</ol>'; Now, what would I have to do to display the list in a random order?? For example: echo '<ol>'; echo '<li>' . $_3; . '</li>'; echo '<li>' . $_1; . '</li>'; echo '<li>' . $_4; . '</li>'; echo '<li>' . $_2; . '</li>'; echo '</ol>'; And next time maybe: echo '<ol>'; echo '<li>' . $_4; . '</li>'; echo '<li>' . $_3; . '</li>'; echo '<li>' . $_1; . '</li>'; echo '<li>' . $_2; . '</li>'; echo '</ol>'; My brain can't figure this one out. I can do this if I re-enter the values into a DB, then extrapolate them, but I know that I am complicating this way too much. There must be a boolean style of logic that can get this done, I just don't know what it is.
-
[SOLVED] Form Input Limited to Numbers Only
xProteuSx replied to xProteuSx's topic in PHP Coding Help
Thanks. I've got is_numeric() working now. -
How would I go about limiting a value to a numerical string? Is there a predefined function for this?
-
sKunKbaddy, you're the man. I didn't even think to do that using MySQL functions. I guess I should stop trying to think between midnight and 5 am. I seem to resort to these forums mostly during those hours ...
-
I am trying to write a script where only the first 'x' number of rows of data are displayed. I have been fooling around with this for quite a while, trying for loops, while loops, and do loops. I have gotten some comical results, but things are starting to become more frustrating than funny. I could use a hand ... (and a brain) ... Here's the idea: $result = mysql_query("SELECT * FROM table1 ORDER BY somedate DESC")or die(mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)) { for ($x=1; $x<=5; $x++) { echo $row[0]; } } } This prints all the rows/entries in the table five times each. What do I do?
-
You have to send the register session command at the VERY START of your file: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> ...
-
Booya - Kasha! Thanks 'cooldude832'! Just had to change the order of things. Solved it by doing this; $loginhandle = $_POST['username']; $loginpassword = $_POST['password']; include ("include/db.php"); $loginhandle = mysql_real_escape_string($loginhandle); $loginpassword = mysql_real_escape_string($loginpassword); Just had to do the mysql_real_escape_string() nonsense following the inclusion of db.php.
-
I am looking to prevent MySQL injection attacks on my site. I was wondering if this is the correct way of doing things. I cannot get this to work ... Here is the original code: -------------------------------------------------------------------------------------------------------------------------- $loginhandle = $_POST['username']; $loginpassword = $_POST['password']; include ("include/db.php"); $query = "SELECT * FROM users WHERE users_handle = '$loginhandle' AND users_password = '$loginpassword'"; $userstatsresult = mysql_query($query) or die ('Error in query 0: ' . mysql_error()); -------------------------------------------------------------------------------------------------------------------------- My understanding is that I have to do the following: -------------------------------------------------------------------------------------------------------------------------- $loginhandle = mysql_real_escape_string($_POST['username']); $loginpassword = mysql_real_escape_string($_POST['password']); include ("include/db.php"); $query = "SELECT * FROM users WHERE users_handle = '$loginhandle' AND users_password = '$loginpassword'"; $userstatsresult = mysql_query($query) or die ('Error in query 0: ' . mysql_error()); -------------------------------------------------------------------------------------------------------------------------- However, this does not work. The original code executes correctly, and I can log in. However, after I add the mysql_real_escape_string() functions I get a series of errors: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'username@'server' (using password: NO) in /loginconf.php on line 25 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in loginconf.php on line 25 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'username@'server' (using password: NO) in /loginconf.php on line 26 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /loginconf.php on line 26 Any reason why this would bugger up the connection code?
-
[SOLVED] 'include' function not working amidst script
xProteuSx replied to xProteuSx's topic in PHP Coding Help
Got it figured out ... Just had to change this: mysql_connect('$server','$db_user','$db_pass') or die ('Unable to connect to MySQL Server'); mysql_select_db('$database') or die ('Unable to select DB'); To this: mysql_connect($server,$db_user,$db_pass) or die ('Unable to connect to MySQL Server'); mysql_select_db($database) or die ('Unable to select DB'); -
[SOLVED] 'include' function not working amidst script
xProteuSx replied to xProteuSx's topic in PHP Coding Help
include_once("file_name"); no worky!! -
[SOLVED] 'include' function not working amidst script
xProteuSx replied to xProteuSx's topic in PHP Coding Help
This is the version with the include function commented out. It works perfectly. { echo '<center>'; echo '<table width=\"400\">'; echo '<tr>'; echo '<tr height=3>'; echo '<td></td>'; echo '<tr>'; echo '<tr border=1>'; echo '<td bgcolor=#d0d0d0 width=120><font size=+2><center><b>Members List</b></center></font></td>'; echo '<tr>'; echo '<tr height=8>'; echo '<td></td>'; echo '<tr>'; echo '</table>'; echo '</center>'; //include "include/db.php"; mysql_connect('server','user','pass') or die ('Unable to connect to MySQL Server'); mysql_select_db('database') or die ('Unable to select DB'); $query = 'SELECT users_handle FROM users'; $result = mysql_query($query) or die ('Error in query: ' . mysql_error()); etc. } This is the version with the include function called up. It does not work. { echo '<center>'; echo '<table width=\"400\">'; echo '<tr>'; echo '<tr height=3>'; echo '<td></td>'; echo '<tr>'; echo '<tr border=1>'; echo '<td bgcolor=#d0d0d0 width=120><font size=+2><center><b>Members List</b></center></font></td>'; echo '<tr>'; echo '<tr height=8>'; echo '<td></td>'; echo '<tr>'; echo '</table>'; echo '</center>'; include "include/db.php"; $query = 'SELECT users_handle FROM users'; $result = mysql_query($query) or die ('Error in query: ' . mysql_error()); etc. } Contents of db.php: ------------------------------------------------------------------------------------------------------ $server = "server";// Your MySQL Server (usually "localhost") $db_user = "username";// Your MySQL Username $db_pass = "password";// Your MySQL Password $database = "database";// Database Name mysql_connect('$server','$db_user','$db_pass') or die ('Unable to connect to MySQL Server'); mysql_select_db('$database') or die ('Unable to select DB'); ------------------------------------------------------------------------------------------------------ That's all ... -
[SOLVED] 'include' function not working amidst script
xProteuSx replied to xProteuSx's topic in PHP Coding Help
Sorry. I meant include "whatever.php"; This doesn't work, even without the equal sign. -
Here is the problem: If I use this, the script works: <?php some miscellaneous code; ?><?php include="whatever.php";?><?php some miscellaneous code; ?> However, if I do this it does not: <?php some miscellaneous code; include="whatever.php"; some miscellaneous code; ?> What the haps??
-
I finally figured it out! This doesn't work: <input type="text" name="edit_school" size="40" maxlength="40" value=' . $row[0] . '> This does: <input type="text" name="edit_school" size="40" maxlength="40" value="' . $row[0] . '"> It was just the extra set of quotation marks that did it.
-
I have no code for stripping any characters, or anything of the sort. I'm thinking that between the retrieval of a value from a DB and displaying it as a default value in a form either PHP or HTML clips the value by default.
-
I have a bunch of values in a MySQL DB and I am trying to access them and make them default values in a form using the following format: <input type="text" name="edit_school" size="40" maxlength="40" value=' . $row[0] . '> Now, if the value of $row[0] is, say, 'Michigan Tech' and I display it using echo $row[0]; I get the value 'Michigan Tech'. However, when I try to display the value of $row[0] in the form using <input type="text" name="edit_school" size="40" maxlength="40" value=' . $row[0] . '> the value shown as the default value is 'Michigan'. It seems the displayed value is always cut short following a space. Please help. I had this working, then it didn't, then it did again, and now it is not working anymore. Its close to crazy time. :'(
-
I have a form that follows this format: <input type="text" name="edit_school" size="20" maxlength="35" value="Michigan Tech"> When I submit the info to another page, I do the following to display the value of 'edit_school' via php: $editschool = $_POST['edit_school']; echo $editschool; If the input value is a string with a space in it, the output is cut short. So, for example, if the default value stays the same (Michigan Tech) the output is simply 'Michigan'. If I enter University of Chicago the output becomes 'University'. What can I do to display the entire string?
-
I am writing a small script that consists of two pages: page one displays a bunch of values from a DB (ie. First Name, Last Name, Phone Number). On this page you will find a form that follows this format: <input type="text" name="edit_firstname" size="20" maxlength="35" value='Bob'> <input type="text" name="edit_lastname" size="20" maxlength="35" value='Smith'> <input type="text" name="edit_phone" size="20" maxlength="35" value='5552222'> So when you see the page there will already be a 'default' value in each line (which is information extracted from a DB). This works perfectly and has been tested thoroughly. On the second page I have the following code: $editfirstname = $_POST['edit_firstname']; $editlastname = $_POST['edit_lastname']; $editphone = $_POST['edit_phone']; What I am trying to do is this: the default value for edit_firstname from the form is 'Bob' by default, but the user can change this in the input field on the first page. This value, whether changed or unchanged, should then be stored as edit_firstname and by calling up the function $_POST[''] on the second page I want to transfer the value to the variable $editfirstname. However, it seems that $_POST['edit_firstname'] and the other fields do not return a value at all, hence $editfirstname = '' or $editfirstname = 'NULL'. I have never tried to do things this way before. I have spent too many hours trying to figure this out on my own. Help!?!?! TIA.
-
Check all your ' , (), and ". It seems that you have complicated the entire process. You can eliminate a lot of these characters, and thereby solve your problem.
-
Thank you. I didn't know that it was a JavaScript thing.
-
A while back I remember some sort of script or snippet that kept an object, such as a menu, stationary on a page, even when the users scrolls up and down. What is this called, and where can I find an example? I am very interested in implementing this.
-
[SOLVED] Trouble with MySQL Data Field and Spaces
xProteuSx replied to xProteuSx's topic in PHP Coding Help
I don't know what I did, but everything is working now. Curious. But its already 3 am, so I won't pry or complain. Thanks for replying. -
[SOLVED] Trouble with MySQL Data Field and Spaces
xProteuSx replied to xProteuSx's topic in PHP Coding Help
When creating the table the column is defined as follows: users_school varchar (30) default NULL Now, I am looking at the entries via myPhpAdmin and I have, for example, the value 'University of Florida' in this column. When I go to output this string, I do the following: $result = mysql_query("SELECT users_school FROM users WHERE users_handle='bob")or die(mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)) { echo $row[0]; } } This will give me the output: 'University'