premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
Not really, take a closer look. He is concatenating and using the single quotes as the string specifier in PHP. The LIMIT is fine, the rest of the query is not.
-
What is the goal of the query? Where do you want to pull data from? How do you want to pull it (like where restuarant id = x or what). Really that query is not a query at all, so please provide me with the information above so we can get you properly formed query. @mrMarcus: Gotcha
-
Where is shirtID coming from? I see you have it defined after the query. Is that suppose to be before so the variable is defined and the query will actually pull the contents from shirts where shirtid = 4? Also your "IS" statement should be an = "SELECT shirtID, shirtDescLadies, shirtDescMen FROM shirts WHERE shirtID = '$shirtID'"
-
I gave it a few tries and then looked that the manual more closely: You can do into a variable name, but you cannot do with the export options, that is the major difference. So I do not believe it is possible to put this into a variable using those commands. So the answer to the other threads question is, no you cannot get it into a variable. As for the file, you just have to define the path using DOCUMENT_ROOT server variable to set the absolute path to save the file. Hope that helps.
-
Why are you looping through each field doing this update? You do not need to do that, as $field is always going to be cnum, since that is the only column you are pulling out of the database (not sure why you are assigning username to that). Is cnum considered a "username" I do doubt that, where is username suppose to come from for the update? If from the table, add it to your original SQL SELECT statement to pull it out. Now for your logic / what you are trying to do I am so confused. Can you elaborate, perhaps with an example of what you want accomplished (meaning this is what is in the database this is what it should be after running and only show 4-5 rows for the example)? To clean up your code: $result3 = mysql_query("select username from payroll") or trigger_error("SQL Failed: " . mysql_error()); while ($row = mysql_fetch_assoc($result3)){ mysql_query("update payroll set cnum = cnum+1 where username ='{$row['username']}'") or trigger_error("SQL Failed: " . mysql_error()); } However, for a query this simple you do not really need to pull it out into PHP. UPDATE payroll SET cnum = cnum+1 Will do it, as that is essentially all you are doing in the php code. As stated, please elaborate more on what the end goal is and please provide a small example data of what it currently is and what you want to have happen.
-
Search the sidemenu for the same mistake. You can probably do a ctrl+f for php?> and find it. Either that or post the code where the error is happening around and we will help you. Without the code you will not get much more help.
-
I doubt it will be sloppy, I bet it is an array ($arr). So what is going on is he is not populating a string with the array data to form a statement for the SELECT clause. He is also not properly specifying a table name. My bet is he wants to use the $arrRest as the WHERE condition. Post the structure of your $arrRest array (do a print_r on the data and post it here within tags and perhaps we can get you a step further to understanding where you went wrong. A proper query structure: SELECT columns FROM table_name WHERE somecondition = another condition LIMIT 0, 10 Look at that and see where you are going wrong on your query. We do not know what is contained in $arrRest, so yea. Given that you have 450 lines+ in your script I bet it is an array and you are just confused on its usage.
-
The code you posted above does not have an error in it. The error is else where, perhaps in the config.php or the header_top function.
-
Mind posting how you figured it out to help someone else who has a similar question?
-
I do not think you can do this with PHP alone, as neil stated you can use Javascript to do this, as it can make a call back when the user presses the submit button, which is what you need. But as far as doing this with just PHP, I do not think it is possible without hacking the core PHP code.
-
You may have to use stristr to check the file: <?php if (stristr($page, '/index.php')) { ?> <li><a href="/index.php" class="selected">Home</a></li> <li><a href="/contact.php">Contact Us</a></li> <li><a href="/agents.php">Meet our Agents</a></li> <li><a href="/claims.php">Submit a Claim</a></li> <?php } I would also convert your <? to <?php for compatibility reasons, as short_tags have been defaulted to off in php 4.x I believe. But see if that works for you.
-
I am sure it has to do with the output buffer not compressing till after the data is sent to the browser. Here is a test script I created which shows the difference, which seemed to work: <?php function output() { echo "<div style=display:none>"; for ($i=0;$i<100;$i++) { echo str_repeat("One jumped over the coocoo nest!<br />", 100); } echo "</div>"; } ob_start(); output(); $output = gzcompress(ob_get_contents()); ob_end_clean(); ob_start(); output(); $output2 = ob_get_contents(); ob_end_clean(); echo "Length is after compression: " . strlen($output) . "<Br />"; echo "Length is before compression: " . strlen($output2) . "<Br />"; ?> Seems to work, how are you setting up the compression? In .htaccess or using ob_start('ob_gzhandler'); ? If so that is why, because the output does not get compressed until the script ends essentially (or at least that is all I could come up with).
-
$HTTP_GET_VARS has long been depreciated. Use $_GET instead. (Not that it will fix it, just a side note.)
-
It has been a few years since I coded in PERL, but in order to help you I need examples of what you have / want. IE: I have this text file: text.txt 1 2 3 4 And want to replace 2 with two. Without a guide like that it is very difficult to help you.
-
You have no column called "team_id" in your standings table, instead you have the team name. You should have the team_id in there instead of the name however. The way you are trying to pull this information is correct, unfortunately your database is not setup that way. You can either modify your table and start inserting the team_id instead of the team name, or you will have to do a separate query to pull the team_id using the team name (I would suggest modifying your database tables to be correct). But here is how you can get the team_id. Given that you have a table called team, the team name column is also called team and the id field is called id. SELECT games_played, wins, losses, ties, points, (SELECT t.id FROM team t WHERE t.team = st.team) AS team_id FROM stats st ORDER BY team_id That is an example query, unsure if it will work but yea. Hopefully it helps you out.
-
I would go Java, I took those classes and loved it. It definitely helps in the understanding of OOP and you can do some fun stuff with Java, no matter what anyone else says. I never regretted learning Java. VB, well I never regretted it but I use VB way less then I use Java, that and VB syntax is just retarded and it pisses me off.
-
Couldnot access the xml data from webservice query ?
premiso replied to ram.mahaseth's topic in PHP Coding Help
Are you on shared hosting? If so chances are you are not allowed to pull data from remote sites using file_get_contents as most shared hosts have that turned off for security reasons. If this is the case they also tend to have cURL enabled, and you can use that to retrieve the data instead (see the php manual by click on cURL for more information on how to do that). -
Need to count how many rows does an array variable has.. help
premiso replied to co.ador's topic in PHP Coding Help
count should be what you are looking for. -
The syntax should be correct, I modified the code quite a bit, first up I am using a for loop to loop through the data. Second up, I am actually checking if POST data is there, this will avoid any notice errors (That you probably were not seeing due to error_reporting level). Third I am defining the values so if one is missing it does not break the script. Finally I am escaping the data as it goes into the database, this will help prevent SQL injection from happening. A short tidbit the ? : seen in the code where I set $question = etc is called the Ternary Operator which acts like a short If / else statement. The code is untested as I do not have a pg database, but should work pending any minor syntax issues that may come up. You will also notice I used trigger_error instead of die if the query fails, this is preferred as the error will be logged to the log where as die does not log errors. You will also notice I moved all the PHP stuff above the HTML output and put the output from the script in a string called "output". This is to avoid header errors later on and it is often better practice to output your stuff at the end of processing and not during. If you have questions regarding the code let me know. <?php pg_connect("host=database.*******.uk port=5432 dbname=***** user=***** password=******"); $output = ""; if (isset($_POST['questionno']) && (isset($_POST['answerno']) && is_array($_POST['answerno']))) { // make sure that we have both sections, just in case. // first lets insert the question data: $questionno = isset($_POST['questionno'][$i]) ? pg_escape_string($_POST['questionno']) : ''; // ternary operator (? : ) acts as a short if/else. If isset set the variable to it after escaping it, else set it to '' $question = isset($_POST['question'][$i]) ? pg_escape_string($_POST['question']) : ''; $quizref = isset($_POST['quizref'][$i]) ? pg_escape_string($_POST['quizref']) : ''; $query="INSERT INTO questions (questionno, question, quizref) VALUES ('".$questionno."', '".$question."', '".$quizref."')"; pg_query($query) or trigger_error ('Error adding new question: ' . pg_last_error()); $output .= "Question has been added succesfully to the quiz reference {$quizref}<br />"; $cnt = count($_POST['answerno']); for ($i=0; $i < $cnt; $i++) { // first define variables to avoid notice errors and escape the data: $answerno = isset($_POST['answerno'][$i]) ? pg_escape_string($_POST['answerno'][$i]) : null; $answer = isset($_POST['answer'][$i]) ? pg_escape_string($_POST['answer'][$i]) : null; $answervalue = isset($_POST['answervalue'][$i]) ? pg_escape_string($_POST['answervalue'][$i]) : null; // check if all values are null, if they are skip the insert. if (is_null($answer) && is_null($answerno) && is_null($answervalue)) continue; // continue the loop as there was no data entered there to insert. $queryanswers="INSERT INTO answers (answerno, answer, answervalue, questionno, quizref)VALUES ('".$answerno."', '".$answer."','".$answervalue."', '".$questionno."', '".$quizref."')"; pg_query($queryanswers) or trigger_error ('Error adding new answers: ' . pg_last_error()); } $output .= "The answers have been succesfully added to the quiz reference {$quizref}.<br />"; } ?> <html> <head> <title>Add </title> </head> <body> <?php echo $output; ?> <form method="post" action=""> quizref: <br/> <input type="text" name ="quizref" size="5" /><br/> Question Number: <br/> <input type="text" name="questionno" size="5" /><br/> Question: <br/> <input type="text" name="question" size="60" /><br/> Answers<br/><br/> Answer number:<br/> <input type="text" name ="answerno[]" size="5" /><br/> Answer<br/> <input type="text" name ="answer[]" size="60" /><br/> Answer value<br/> <input type="text" name ="answervalue[]" size="5" /><br/> <br/><br/> Answer number:<br/> <input type="text" name ="answerno[]" size="5" /><br/> Answer<br/> <input type="text" name ="answer[]" size="60" /><br/> Answer value<br/> <input type="text" name ="answervalue[]" size="5" /><br/> <br/><br/> Answer number:<br/> <input type="text" name ="answerno[]" size="5" /><br/> Answer<br/> <input type="text" name ="answer[]" size="60" /><br/> Answer value<br/> <input type="text" name ="answervalue[]" size="5" /><br/> <br/><br/> Answer number:<br/> <input type="text" name ="answerno[]" size="5" /><br/> Answer<br/> <input type="text" name ="answer[]" size="60" /><br/> Answer value<br/> <input type="text" name ="answervalue[]" size="5" /><br/> <br/><br/> <input type="submit" value="Send and Add another Add Questions" /> <a href="addfinish.php"><input type="submit" value="Add and finish" /></a> </form> </body> </html> EDIT: Fixed a syntax issue in the if, also removed the question array element as the questions are not arrays.
-
I am not 100% how PHP does handle file uploads and why you cannot view them, but you can put a sleep function before you move the file, say a 60 second sleep (be sure to set the set_time_limit to 90 so the script does not time out. Using this method you can upload a very small file and you should be able to see it. within those 60 seconds. It could possibly be that the file is created as a "hidden" file and the FTP does not show those, I do not know. But try the above and see if you can see it then. Alternatively, you can look at the PHP Manual for Handling POST Uploads if you have not already to find out more information.
-
WHYISNT THIS MYSQL STATEMNT NOT WORKING? (php)
premiso replied to emopoops's topic in PHP Coding Help
It all depends on what you want out. If all you want is the number of rows, it is better to just pull the COUNT(column) because it does not return any data just the number of rows. If you want to actually use the data then you would want to pull out the data and do the num_rows. This will make your script more efficient as MySQL does not have to pull out any data. You have to love double negatives. -
Using INT or VARCHAR to store numbers, or convert to HEX?
premiso replied to jeremyhowell's topic in MySQL Help
I would store it as an integer just because that is what it is and it generally is a good idea to store data as the type that they are. But there are always exceptions to the rules. A good read that may help you decide: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html Check out that. -
That desktop is pretty badass. It must have taken a lot of time to do that
-
WHYISNT THIS MYSQL STATEMNT NOT WORKING? (php)
premiso replied to emopoops's topic in PHP Coding Help
If you use Count(), do not use Count(*) use Count(column) as it will be more efficient since it is only counting one column but does essentially the same thing. Doing that will be more efficient, as for your scenario it should be better doing that as CL pointed out. -
WHYISNT THIS MYSQL STATEMNT NOT WORKING? (php)
premiso replied to emopoops's topic in PHP Coding Help
You could have an error, "to" column is a reservered word mysql_query("SELECT to FROM cmnts WHERE to = 1") or trigger_error("Query Failed: " . mysql_error()); Using that will show you what to error is. To fix it either change the column name (I recommend this) or use backticks to surround the column name: mysql_query("SELECT `to` FROM cmnts WHERE `to` = 1") or trigger_error("Query Failed: " . mysql_error()); I would highly recommend getting used to doing or trigger_error as I have shown above as it will save you headache by showing you what the errors are.