-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
If you search for that error message, you will find that it generally means that the query failed due to an error of some kind (the 2nd most common reason is using the wrong variable name or overwriting a variable.) A query that executes but matches no rows in your table does not produce an error like this one. The quickest way of finding why the query is failing is to add some error checking/reporting logic to the code. Change your query to the following to see what query error is occurring - $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1") or die("Query failed:" . mysql_error());
-
How to send multiple information of the same name?
PFMaBiSmAd replied to dwex's topic in PHP Coding Help
$_POST['name'] and $_POST['dob'] will both be arrays and you can iterate over them using php's array functions, such as foreach -
He's also got an INSERT query where the table name and the column prefixes are from a form field (apparently selected from a drop down menu.) Before you spend any more time on this, you need to fix your database design. Your design is not efficient and is resulting in more complicated code than you need. You need to make your design general purpose. You don't create another table just because you add a new category or type and your column names should only indicate the purpose of the data (id, name, price, image), not what the data in them references.
-
You would need to query the database table to find out if the newly generated key is already present or not and loop until you generate a key that is not already in the table. You would also probably want to use a counter to limit the number of attempts to a reasonable number in case your code contains an error or you use up all the available key values for the key length you have picked.
-
Question on how to check if a user is on a certain page
PFMaBiSmAd replied to NathanDrake's topic in PHP Coding Help
If the value of $_SERVER['PHP_SELF'] was /signup.php, you would need to test for '/signup.php'. If the actual path can be different, you might want to consider just using the filename portion of the value. See the basename function. -
I've got to ask why you want a numerically indexed array? I suspect is it because you want to iterate over the data, in which case you would just iterate over the associative array. Given that the number of data elements could vary, the meaning of each element looks like it can be anything, and even the order of the elements could change, attempting to access a specific numerical element wouldn't necessarily give you the result you expect.
-
You are escaping the single-quotes in your query string. They are part of the sql syntax and I am pretty sure that you would be getting an sql error. Did you put the or die(mysql_error()); on the version of your code with mysql_query() statement in it?
-
PHP MySQL Query - Display all items within the same order
PFMaBiSmAd replied to oddball25's topic in MySQL Help
See this link - http://www.phpfreaks.com/forums/mysql-help/need-some-array-help-bigtime!!!/msg1513324/#msg1513324 Obviously, you would need to change any usage of 'date' to 'order_code' to match what you are doing. The code will output the 'heading' information only once, but output each piece of data under that heading. -
What exact problem are you trying to solve? Unless you do some unusual session id handling yourself, when you have multiple-tabs and/or multiple-instances of ONE browser open at the same time, there will be one single session id for any one URL and there will only be one set of corresponding session variables on the server. If you have multiple copies of the same form open, the last form submitted would replace any data previously submitted in one of the other tabs/instances of that browser unless you do something in your code to detect and ignore the multiple submissions.
-
I would use SimpleXMLElement::count to get a count of the number of child elements, then use rand() to get a random number from zero to the count -1, then use that random number to access the corresponding child element. If you want to access more than one element randomly, you would make an array of the numbers, zero to count -1, shuffle that array, and then use that array of randomized numbers to access the corresponding child elements.
-
See this link - http://www.phpfreaks.com/forums/mysql-help/need-some-array-help-bigtime!!!/msg1513324/#msg1513324 Obviously, you would need to change any usage of 'date' to 'year' to match what you are doing.
-
See this link - http://www.phpfreaks.com/forums/mysql-help/need-some-array-help-bigtime!!!/msg1513324/#msg1513324 Obviously, you would need to change any usage of 'date' to 'title' to match what you are doing.
-
Php is a parsed, tokenized, interpreted language. If the code never reaches the interpreted stage due to a fatal parse error, how could the lines of code setting the error_reporting/display_errors have an effect? If you set the error_reporting and display_errors settings in your php.ini, php will display all the errors it detects, even fatal parse errors in the main file (it turns out that putting the two settings into your main code will display parse errors in included files.) You also won't need to remember to put those settings into your code or remember to remove them when you put your code onto a live server. As to your current problem, you are apparently asking that your validation logic test if both are empty or if both are set (assuming that you don't want both to be set at the same time.) This would detect if only one is set and produce error messages if both are not set or if both are set - // if both are empty, error // if both are set, error if($name == '' && $email == ''){ // both are empty $errmsg_arr[] = 'Both name and email are missing. You must enter one or the other.'; $errflag = true; } elseif($name != '' && $email != '' ){ // both are set $errmsg_arr[] = 'Both name and email are set. You must only enter one or the other.'; $errflag = true; } Also, why did you switch to using the alternate if:/elseif:/endif; syntax? You shouldn't mix regular and the alternate syntax in your code.
-
The code and the URL to your site that you posted doesn't match the code and the filename mentioned in the error message. It will be a little hard to actually help you without the actual code/file that the error message indicates the problem is occurring in.
-
Then that's the variable name you need to put into the code (don't just use code without reading it because it may not have anything to do with what you are doing.)
-
Isn't your value in $product->title ?
-
Not able to call out any values from database using PHP codes
PFMaBiSmAd replied to genzedu777's topic in PHP Coding Help
The php manual contains a description of all the php functions - http://www.php.net/manual/en/mysqli-result.num-rows.php There's no reason why you need to guess what any function does. -
Problem with casting from strings to integer
PFMaBiSmAd replied to machelix's topic in PHP Coding Help
^^^ You don't have a defined constant named temp, so php assumed that you meant - $temp = (int)'temp'; And, well, the (int) of the string 'temp' is zero. If you meant to use $temp, please proof read your code when it doesn't work. -
You would want to put the $lastcomp = 0; statement inside the if($lastdate != $row_all_games['date']) { code so that you initialize $lastcomp every time there is a change in the date.
-
^^^ You buggered up that line by changing the original != comparison operator to an = assignment operator. You are assigning $row_all_games['date'] to the variable $lastdate, not comparing the two.
-
Basic MySQL database connection using OOP
PFMaBiSmAd replied to j.smith1981's topic in PHP Coding Help
^^^ Your method should return the error, not echo it. What if you want to style it a particular way in one application and style it a different way in another application and/or you want to log it to a file instead of outputting it to the browser? Your application code that calls the method should decide what to do with the error message. Your method should just return the string. -
Basic MySQL database connection using OOP
PFMaBiSmAd replied to j.smith1981's topic in PHP Coding Help
Methods can return values, but the constructor only returns the instance of the object that was created. There are two common ways that you could make the connection error information available - 1) Don't make the connection in the constructor. Make a separate method (connect() as an example) and then call that method as a separate step and have that method return a TRUE or FALSE value. You would store the actual error information in your $_error property. This would allow you to test the value returned by the connect() method. 2) Make the connection in the constructor and set a connect_error property with a TRUE or FALSE value and store the actual error information in your $_error property. You would then get and test the connect_error properly. -
Not able to call out any values from database using PHP codes
PFMaBiSmAd replied to genzedu777's topic in PHP Coding Help
Start by echoing or use var_dump() on mysqli_num_rows($data3) so that you know exactly what it is. If it is zero, find out exactly what value is in $_GET['tutor_id'] (use var_dump()) and find out why that doesn't match an entry in your table. If it is greater-than 1, find out why you have duplicate data in your table. -
The answer looks like it would be - No. If you posted an actual example of what your data is and what you are trying to produce, I'm sure someone could probably help you.
-
How come this query returns ages that are 19 and 20 and not 20?
PFMaBiSmAd replied to kevinkhan's topic in MySQL Help
There aren't exactly 365 days in each year. See this link for how you can calculate a person's age - http://dev.mysql.com/doc/refman/5.0/en/date-calculations.html