Jump to content

sambib

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sambib's Achievements

Member

Member (2/5)

0

Reputation

  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!
×
×
  • 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.