Jump to content

sambib

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by sambib

  1. [quote author=Crayon Violent link=topic=112756.msg457815#msg457815 date=1161847407] okay if (@mysql_query($query)) { you are trying to run a query on a result source. should change that to $sql not $query. but you're still running the same query twice. just get rid of the previous one. [/quote] Aha....! thanks alot for your promt help I understand where I went wrong. cheers.....!!!!
  2. I did try the IF EXISTS but got the same result. here's the full page without comments. like i said it does the job but still get the error messages [code]<?php $sql = "DROP TABLE IF EXISTS contacts"; $query = mysql_query($sql); if (@mysql_query($query)) { //set the variable to the required string $result =  "<p>the query was successful: contacts table dropped.</p>"; } else { //set the variable to the required string $result = "<p>could not drop the table: " . mysql_error() . " </p>"; } echo "$result"; $sql = "CREATE TABLE contacts (id INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, date TIMESTAMP, surname VARCHAR(32) NOT NULL, firstName VARCHAR(120) NOT NULL, email VARCHAR(120) NOT NULL, PRIMARY KEY(id))"; $query = mysql_query($sql); if (@mysql_query($query)) { //inform the table was created echo "<p>the query was successful: contacts table re-created.</p>"; } else { //inform the user that the attempt was not successful echo "<p>could not create the table: " . mysql_error() . " </p>"; } $LDAP_SERVER = "xxx.xxx.xxx.xxx"; $LDAP_ROOT_DN = "ldap stuff here";   //Connect to LDAP $connect_id = ldap_connect($LDAP_SERVER); if($connect_id) {   //Authenticate   $bind_id = ldap_bind($connect_id, "ldap stuff here");     //Perform Search   $search_id = ldap_search($connect_id, "ldap stuff here", "ldap stuff here");     //Assign Result Set to an Array   $result_array = ldap_get_entries($connect_id, $search_id);    } else {     //Echo Connection Error   echo "Could not connect to LDAP server"; }   //Sort results if search was successful if($result_array) {   for($i=0; $i<count($result_array); $i++) {     $format_array[$i][0] = strtolower(stripslashes($result_array[$i]["sn"][0]));     $format_array[$i][1] = strtolower($result_array[$i]["gn"][0]);     $format_array[$i][2] = strtolower(stripslashes($result_array[$i]["mail"][0]));     }   //Sort array   sort($format_array, "SORT_STRING");   for($i=0; $i < count($format_array); $i++) {     $sn = ucwords(addslashes($format_array[$i][0]));     $gn = ucwords($format_array[$i][1]);     $email = addslashes($format_array[$i][2]); if($sn && $gn && $email) { //echo "<p>data ready</p>"; $query = "INSERT INTO contacts SET surname = '$sn', firstName = '$gn', email = '$email'"; //If the query was successful if (@mysql_query($query)) { //inform the user the records were added $result = "<p>the query was successful</p>"; } else { //inform the user that the attempt was not successful $result = "<p>could not query the database: " . mysql_error() . " </p>"; } }       } } else {     echo "Result set empty for query: " . $ldap_query . "";   } //Close Connection ldap_close($connect_id);  echo "<p>$result</p>"; [/code]
  3. [quote author=Crayon Violent link=topic=112756.msg457802#msg457802 date=1161842364] ...and there are no other queries running in your script anywhere? [/quote] No that's the only script on the page, there are others but they're commented out. the page drops the table, re-creates it and then runs an ldap query which feeds a mysql query to a database. it works really well, I just get the errors. the scripts look OK don't they I've been looking at them all day and am a bit blinded by them right now....
  4. Hi, I'm running a query with php that drops a table (it's going to be created again and populated later in the page). It works fine as the table is dropped however a myqsl error is reported back to the page: "[i]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1[/i]" any ideas why this would happen....? [code]<?php $sql = "DROP TABLE contacts"; $query = mysql_query($sql); if (@mysql_query($query)) { //set the variable to the required string $result =  "<p>the query was successful: contacts table dropped.</p>"; } else { //set the variable to the required string $result = "<p>could not drop the table: " . mysql_error() . " </p>"; } echo "$result"; ?>[/code]
  5. still looking for more help if anyone's able to......! thanks for those, I've actually tried putting every availaible sort function sort(), asort(), ksort(), and krsort() with no luck. I've also tried taking out the "SORT_STRING" and nothing has changed the way it's sorted. I'll be honest and say that I don't even know how it's sorted now. It may be by one of the array elements that I'm not using (another ldap context attribute that I'm not actually using in the output). The only thing that did work is when I tried shuffle() instead of sort (jsut as an experiment) and that did shuffle the results but I want them sorted by "sn" (which is the surname of the user). [code]i <?php if($result_array) {   for($i=0; $i<count($result_array); $i++) {     $format_array[$i][0] = $result_array[$i]["sn"][0];     $format_array[$i][1] = $result_array[$i]["gn"][0];     $format_array[$i][2] = $result_array[$i]["mail"][0];     }   //Sort array sort($format_array, "SORT_STRING"); // *******this is where I'm struggling*******   for($i=0; $i < count($format_array); $i++) {     $sn = $format_array[$i][0];     $gn = $format_array[$i][1];     $email = $format_array[$i][2];     if($sn && $gn && $email) {.......rest of cosde ?>[/code]
  6. Hi, I'm pulling some data from an ldap query and want to sort (and display) the data by one of the returned elements in the array. This the part of code I'm struggling with. At the moment it's working fine except it's sorting by the email address (mail or $email) but I want to sort it by the surname (sn or $sn). [code]?>   <table id="ldap">   <caption>Staff Contacts</caption>     <tr>   <th>Surname</th>         <th>First Name</th>         <th>E-Mail</th>     </tr>   <?php //Sort results if search was successful if($result_array) {   for($i=0; $i<count($result_array); $i++) {     $format_array[$i][0] = $result_array[$i]["sn"][0];     $format_array[$i][1] = $result_array[$i]["gn"][0];     $format_array[$i][2] = $result_array[$i]["mail"][0];     }   //Sort array   sort($format_array, "SORT_STRING");   for($i=0; $i < count($format_array); $i++) {     $sn = $format_array[$i][0];     $gn = $format_array[$i][1];     $email = $format_array[$i][2];     if($sn && $gn && $email) { echo "<tr><td class=\"name\">" . $sn . "</td><td class=\"name\">" . $gn . "</td><td class=\"email\"><a href=\"mailto:$email\">" . $email . "</a></td></tr>"; }           }   } else {     echo "Result set empty for query: " . $ldap_query . "";   }   ?></table>[/code] any help greatly recieved.... cheers
  7. cheers.... when i was using php4 that code looked like this (and worked): <input type="hidden" name="firstName" value="<?= $_POST['firstName']; ?>" /> but that doesn't work in php5 so i replace the [color=blue]<?=[/color] with [color=blue]<?php[/color], so the 'echo' wasn't required previously... so there you go, you learn something new everyday....
  8. Hi, I've got a long php/html form which I've broken up into pages for usability and I want to pass the collected vlaues from page to page in hidden fields, however it's not working. the data from the first page gets passed to the second like so: [color=blue][font=Verdana]<?php if(isset($_POST['submit'])) { echo "<p>you entered: $dateOfBirth</p>"; echo "<p>you entered: " . ($_POST['firstName']) . "</p>";[/font][/color] this is just for testing and at this stage it works (ie. the values appear on the page as i expect) [b]The values don't however get passed from here on....?[/b]: [color=blue]<form id="downloadForm" name="downloadForm" action="surveyform3.php" method="post"> <input type="hidden" name="firstName" value="<?php ($_POST['firstName']); ?>" /> <input type="hidden" name="dateOfBirth" value="<?php $dateOfBirth; ?>" /> <label for="submit" class="required"><span class="labelText">Continue to Page 3 of the Form:</span> <input id="submit" type="submit" name="submit" value="Next Page" /> </label> </form>[/color] Here's the code for the following page and these echo statements don't show any values being passed: [color=blue]if(isset($_POST['submit'])) { echo "<p>you entered: " . ($_POST['dateOfBirth']) . "</p>"; echo "<p>you entered: " . ($_POST['firstName']) . "</p>";[/color] the form continues...... I've recently upgraded to php5 and I'm sure this was working a few weeks ago before the upgrade, so is there some syntax error or anything else I've missed....?
  9. [b]$CFG->[/b]wwwroot  = 'http://site.local'; i can't find -> anywhere in my two php books or online to tell me what this piece of code is doing... I'll take a guess that it's seeting a variable to 'http://site.local' but don't really understand why the -> is used or what it's there for...? thanks
  10. I've just tried to upgrade both my php and mysql from to version 5 (respectively) and all my php scripts work except for any that connect to my databases. all i get is a total blank screen and nothing in 'view source', but like i said this is ONLY for scripts that require a databse connection. I can manipulate my mysql using msql query browser and like I said I can see all of my other scripts, so I'm guessing that it's the config between mysql/php and maybe apache but I've come to a bit of a standstill as to where to go from here. I did mess up the mysql upgrade intially as I didn't stop the mysql service and so uninstalled both the 4.1 and the 5.0 installs. I then re-installed mysql 5.0 and used the GUI tools to create my 'old' database tables. I'd now like to put the data back in from my custom web interface but it's that that is not working (blank screens). any ideas as to what to test or what to try would be a great help. EDIT: sorted, I hadnt' loaded the libmysql.dll into the windows folder.... In fact even though I've read the documentation I'd hadn't seen that file mentioned...... :-\ all's well that ends well I suppose!
  11. "then you could just config apache to not allow this (dont allow files with certain extensions to be loaded" could you tell me where in the config this is....? thanks!
  12. I've built a content management system which has a file upload page (for a newsletter) and for security purposes I want to have that folder outside of my webroot, though I can't get the file to download. Here's the line in the current download page (this page sits at the webroot): echo "<td>Issue No: <a href=\"../uploads/{$row['upload_id']}.pdf\" target=\"_blank\">{$row['file_name']}</a></td>\n"; I've seen that you can write a download.php page and have that file sent using the page headers but I was wondering if I could just amend this script. can this be sorted with .htaccess, or is there some other way?
  13. sorted..... the date field is a data type of DATE and collected from the form and formatted like so $date = $year.'-'.$month.'-'.$day; and retrieved and displayed using: $query = "SELECT date_format(date, '%d %M %Y') as date, heading, col_left, col_right FROM future_fix WHERE id=$id"; f@#king hell, today's my last day at work before a months holiday at the snow(Oz) and then asia/europe. i'm so pleased to get this sorted. the code may be butt ugly, but it works.... Hussar!
  14. i'm actually getting more confused so maybe it's better to tell you guys what I need to happen.... I want a user to enter some fixtures into a database. the crucial element is the date for the fixtures as this is how the fixtures need to look in an ordered list. I want the user to enter a date (from a drop down menu or as a string if that's easier) and it's THAT field that will determine the order of the returned data, not when it's entered or edited but the chronological order of the fixtures: for example 12 august 2006 21 september 2006 3 october 2006 at the moment nothing's working. I've tried to check the drop down list i was using in the code above and that's not giving me the dates i've selected. thanks guys...
  15. *bump* this really can't be that hard can it...... :-\
  16. Hi, I want a page to show future sports fixtures. the user will enter and edit the fixtures and I want them to show on the page in chronological order in a list (ie by the fixture dates not when they were entered or edited). the problem is the date is entered in the database as 0000-00-00 rather than 2006-08-25. I'm using strtotime() but obviously not correctly, could anyone help with this...? *----- mysql table -----* create table future_fix ( id TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, date DATE, heading TEXT, col_left TEXT, col_right Text, PRIMARY KEY(id) ); *-------- to insert a fixture -------* if (dbConn()){ if (isset($_POST['submit'])) { //store all collected data in variables $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $date = strtotime($year-$month-$day); $query = @mysql_query("SELECT id FROM future_fix WHERE heading = '$heading'"); if (mysql_num_rows($query) > 0) { } else { //define the SQL query $query = "insert into future_fix set date = '$date'"; //If the query was successful if (@mysql_query($query)) { //inform the user the record was added echo "<p>the query was successful</p>"; } else { //inform the user that the attempt was not successful echo "<p>could not query the database: " . mysql_error() . " </p>"; } } //Display the links to the view records page and the Add record page ?> <ul> <li><a href="<? $_SERVER['PHP_SELF']; ?>">Add Future Fixtures</a></li> </ul> <? //Else if the form is not being submitted } else { ?> <form action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <? //make the months array $months = array (1 => '01', '02', '03', '04', '05','06','07','08','09', '10','11','12'); $year = date('Y'); ?> <select name="month"> <? foreach ($months as $key => $value) { echo "<option value=\"$key\">$value</option>"; } ?>   </select> <select name="day"> <? for ($day = 1; $day <= 31; $day++) { echo "<option value=\"$day\">$day</option>"; } ?> </select> <input type="hidden" name="year" value="<? $year; ?>" /> <input class="submit" type="submit" name="submit" value="save record" /> </form> <? } }
  17. [!--quoteo(post=359861:date=Mar 30 2006, 10:44 AM:name=catlover)--][div class=\'quotetop\']QUOTE(catlover @ Mar 30 2006, 10:44 AM) [snapback]359861[/snapback][/div][div class=\'quotemain\'][!--quotec--] I'm not familiar with how Invision boards work, so I didn't know the reply was "meshing" with the last reply. Does anyone know how to sort how many "articles" are in a particular "breed" based on the previous code change (thanks to Firedrop for the first problem!)? All the script needs now is the sorting of "articles" pertaining to the particular "breed". I've fooled with quite a few queries, arrays, etc, but I don't "get it". [/quote] only guessing but---> $breed = animals['breed']; $num = count(animals['breed']); echo '<p>$breed ($num)</p>';
  18. [!--quoteo(post=359646:date=Mar 29 2006, 11:07 PM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 29 2006, 11:07 PM) [snapback]359646[/snapback][/div][div class=\'quotemain\'][!--quotec--] I may be wrong, but I THINK they happen because the characters are not what you think they are... let me give an example, then you can tell me I'm wrong... when you do " in m$ word, it changes it the those funny " that are different when you start the quote than when you end the quote, like the first ones are upside down or whatever. I think that is what you are seeing... I have dealt with them in the past with str_replace() [/quote] I changed the charset of my pages to charset=utf-8 and it seems to have done the trick...
  19. [!--quoteo(post=359883:date=Mar 30 2006, 01:22 PM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ Mar 30 2006, 01:22 PM) [snapback]359883[/snapback][/div][div class=\'quotemain\'][!--quotec--] ok so far heres my script <?php $link = mysql_connect('localhost', 'user', 'pass); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br>'; ?> know i want it to display information from the database "test" on table "people" please help me with the code! [/quote] [code]<?php {     //attempt to connect to the database server     //if the attempt was successful     if (@mysql_connect('localhost', 'user', 'pass))) {              //attempt to select the mycms databse         //if the attempt was successful         if (@mysql_select_db("test")) {              //return true         return TRUE;                  //Or if the selection was unsuccessful         } else {                      //display error message             echo "<p>Unable to select the database .</p>";                          //Return False             return FALSE;         }              } else {              //Display the error message         echo "<p>Unable to connect to the database server</p>";              //return false         return FALSE;     } } $query = "SELECT * FROM people"; //put some other criteria in to refine your query $result = mysql_query ($query); // check to see how many rows we have. if we have 0 rows then nothing has returned if(mysql_num_rows($result) < 1) {     echo('<p>the is no data in the table!</p>'); } else {                   //run through the results of the query and put the result into an array called $row     while ($row = mysql_fetch_assoc($result)) { ?>//stop the while loop and display the records <p>here are the details of the field name<?= $row['fieldName'] ?></p> <!--change field name and fieldName for the correct names of the table fields. --> <?php      } //end the while loop ?> [/code] that should get you started
  20. [!--quoteo(post=359609:date=Mar 29 2006, 08:45 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 08:45 PM) [snapback]359609[/snapback][/div][div class=\'quotemain\'][!--quotec--] Wow, it works!! Thanks so much :) :) I used the second one, the first would still not work. Thanks :D Michelle [/quote] no worries, I'm learning myself so i know how frustrating this can be......:)
  21. [!--quoteo(post=359560:date=Mar 29 2006, 04:24 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 04:24 PM) [snapback]359560[/snapback][/div][div class=\'quotemain\'][!--quotec--] For the first one I got: Parse error: syntax error, unexpected T_VARIABLE in /home/homebuy/public_html/towns.php on line 77 and for the second i got: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/homebuy/public_html/towns.php on line 77 and for this: <?php //fetch details for county $sql = 'select * from counties where id = '.$_REQUEST['CountyID']; $R = mysql_query($sql,$myconn) or die(mysql_error()); while ($country = mysql_fetch_array($R)) { //and this is line 69? or try mysql_fetch_assoc($R); echo $country['title']; } ?> I get: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 [/quote] there's an error on this line of the first one: $country = mysql_fetch_array($R) - the semi colon is missing from the end of the line.....!!!! it should be: $country = mysql_fetch_array($R); for the second one try: while ($country = mysql_fetch_array($R)) { //or try mysql_fetch_assoc($R); echo "<p>you chose " . $country['title'] . "</p>"; } if these don't work then when you post the error message please post the line from the code where the error is....:) by the way is register_globals = On in your php.ini file...... if not and you can access the file find the entry f register_globals = Off and change it to on. save the file and restart your webserver.....
  22. [!--quoteo(post=359544:date=Mar 29 2006, 03:09 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 03:09 PM) [snapback]359544[/snapback][/div][div class=\'quotemain\'][!--quotec--] I get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/homebuy/public_html/towns.php on line 69 :( I don't get it! [/quote] so does you code look like this: [code]<?php //fetch details for county $sql = 'select * from counties where id = '.$_REQUEST['CountyID']; $R = mysql_query($sql,$myconn) or die(mysql_error()); $country = mysql_fetch_array($R) //and this is line 69? or try mysql_fetch_assoc($R); $city = $country['title']; ?> <p>the city you chose was <?= $city ?></p>[/code] or this: [code]<?php //fetch details for county $sql = 'select * from counties where id = '.$_REQUEST['CountyID']; $R = mysql_query($sql,$myconn) or die(mysql_error()); while ($country = mysql_fetch_array($R))  { //and this is line 69? or try mysql_fetch_assoc($R); echo "<p> the city you chose was $country['title'] </p>"; } ?>[/code] either of those usually works for me ...
  23. [!--quoteo(post=359541:date=Mar 29 2006, 02:41 PM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 29 2006, 02:41 PM) [snapback]359541[/snapback][/div][div class=\'quotemain\'][!--quotec--] hi! Do you mean leave the: //fetch details for county $sql = 'select * from counties where id = '.$_REQUEST['CountyID']; $R = mysql_query($sql,$myconn) or die(mysql_error()); $county = mysql_fetch_assoc($R); in? Because I always seem to get this error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 But when I take it out and put this in: <? while ($county = mysql_fetch_assoc($R)) { ?> <? echo $county['title']; ?><? } ?> I get: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/homebuy/public_html/towns.php on line 66 Thanks :) [/quote] try: <? while ($county = mysql_fetch_array($R)) { ?> <? echo $county['title']; ?><? } ?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.