Jump to content

patchido

Members
  • Posts

    59
  • Joined

  • Last visited

Everything posted by patchido

  1. solved, the function sqlsrv_num_rows need this $params = array(); $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET ); $result = sqlsrv_query($conn, $tsql,$params,$options); from php.net Retrieves the number of rows in a result set. This function requires that the statment resource be created with a static or keyset cursor. For more information, see sqlsrv_query(), sqlsrv_prepare(), or ยป Specifying a Cursor Type and Selecting Rowsin the Microsoft SQLSRV documentation.
  2. Does asteriscs are for me not to reveal my info, the connection is successful, i get the right response but no rows
  3. so i am trying to connect to my sql through php. i am getting a connection, if i copy that query and place it over sql management studio i do get the results needed. what am i missing? I just get this on the response. Connection createdRows returned: <?php $serverName = "************"; $databaseName = "*********"; $connectionInfo = array("Database"=>"$databaseName", "UID"=>"*******","PWD"=>"*********"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ){ echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } else{ echo "Connection created"; } $tsql = "SELECT TOP 10 * FROM dbo.ActivityLog"; $result = sqlsrv_query($conn, $tsql); echo "Rows returned: ". sqlsrv_num_rows($result); sqlsrv_close($conn); ?>
  4. let me try that out, thats exactly what i wanted, (didn't know that existed) Thanks.
  5. the table won't show up in the forums :/ ill put part of it then. id username nombre ap_Paterno ap_Materno mail region_id localidad_id admin 2 Qualtia prueba prueba prueba prueba@qualtia.com 1 2 3 11 romtorre ROMELIA TORRES VELI romtorre@qualtia.com 1 4 2
  6. Hello, i have a table i have to fill out with info regarding other tables, is a join possible or do i have to make 2 queries? This is what i have right now. $date = date("Y-m-d H:i:s"); $sql = "INSERT INTO tblpaqueteria ( sender_id, reciever_id, AddTime, Estatus, ubicacion, tipo,slocalidad_id,rlocalidad_id ) VALUES ( '{$_POST['id_send']}', '{$_POST['id_rec']}', '{$date}', '0' , '0', '{$_POST['tipo_paq']}',0,0 )"; $res = mysql_query($sql,$this->conn); return $sql; What i need now is to change some of my insert into dynamic ones, i have to enter into "slocalidad_id" and into "ubicacion" the "id" of a table called localidad, and this id is being referenced from a table called "usuarios" (users) where "$_POST['id_send']" where localidad_id marks the id i need to insert into tblpaqueteria. I am not sure if I explained myself correctly so ill try and make an example. usuarios So for my sql above, without joins i would be receiving from POST id_send = 2 and from id_rec 11 so my query should insert this $sql = "INSERT INTO tblpaqueteria ( sender_id, reciever_id, AddTime, Estatus, ubicacion, tipo,slocalidad_id,rlocalidad_id ) VALUES ( '{$_POST['id_send']}', '{$_POST['id_rec']}', '{$date}', '0' , '2', '{$_POST['tipo_paq']}',2,4 )"; notice the numbers "2" and "4" being inserted, those are the ones i don't know how to enter dynamically, i think its a join, but i don't know how to use them in an insert. Thanks a lot
  7. solved it, this made the trick $ids = $_POST['ids']; $os = $_POST['os']; $i = 0; $sql = "UPDATE tblpaqueteria INNER JOIN guias ON (guias.id = tblpaqueteria.guia_id) SET tblpaqueteria.Estatus = 2, guias.guia = CASE tblpaqueteria.guia_id"; foreach ($os as $val) { $sql .= sprintf(" WHEN %u THEN %u ", intval($ids[$i]), intval($val)); $i++; } $sql .= "END WHERE tblpaqueteria.guia_id IN (" . implode(", ", array_map('intval', $ids)) . ")"; i used your example with the example barand made. Thanks a lot guys!
  8. so, this is what i ended up with your example. $ids = $_POST['ids']; $os = $_POST['os']; $i = 0; $sql = "UPDATE tblpaqueteria t INNER JOIN guias g ON (g.id = t.guia_id) SET t.Estatus = 2, g.guia = CASE "; foreach ($os as $val) { $sql .= sprintf("WHEN t.guia_id = %u THEN g.guia = %u ", intval($ids[$i]), intval($val)); $i++; } $sql .= "END WHERE t.guia_id IN (".implode(", ", array_map('intval', $ids)).")"; mysql_query($sql); return $sql; i got this query UPDATE tblpaqueteria t INNER JOIN guias g ON (g.id = t.guia_id) SET t.Estatus = 2, g.guia = CASE WHEN t.guia_id = 39 THEN g.guia = 50 WHEN t.guia_id = 40 THEN g.guia = 100 END WHERE t.guia_id IN (39, 40) and the table tblpaqueteria did update while the table guia didn't.
  9. a more ilustrative example, ill have a id array with this info [34,35,36] and an array $os with [134,145,256] i want to change tblpaqueteria.Estatus = 2 in all tblpaqueteria.guia_id matching 34 35 and 36, after that i want that in the guias.guia updates to 134 where guias.id = 34 and guias.guia updates to 145 where guias.id = 35 and guia.guias updates to 256 where guias.id = 36. THANSK
  10. the array "id" would also have more than 1 value, both arrays have the same length, and the indexes match for ex the id with index of 0 would have the "guia" in the "os" array with the index of 0 and ht indexed 1 would be indexed with the one of 1 too, i am not sure if i am being clear. Thanks.
  11. that worked! but sometimes ill get more than 1 value, how can i make that dynamic?
  12. it is always 2, $_POST['os'] is an array, i get an error becuase of that. <br /> <b>Warning</b>: mysql_real_escape_string() expects parameter 1 to be string, array given in <b>E:\xampplite\htdocs\Mensajeria\includes\registro.class.php</b> on line <b>184</b><br />
  13. Hi, i can't manage to think on how to update 2 tables in 1 same query. here is my context. i have a table called "guias" with a primary incremental key "id" and another field called "guia". the other table called "tblpaqueteria" has "id" a field called "guia_id" (this one matches a record from the other table) and the last field called "Estatus". i get 2 arrays via post method to my php function, one filled with the "guia_id" i want to modify, and another with the "guia" number i want to update the info to. here is my code: $ids = $_POST['ids']; $os = $_POST['os']; $sql = "UPDATE tblpaqueteria SET Estatus = 2 "; $sql .= "WHERE guia_id IN ("; foreach($ids as $id){ $sql .= $id . ","; } $sql = rtrim($sql, ','); $sql .= ")"; this works great, i change the field "Estatus" to the lines i need to, but know i also need to add the $os info to the lines in the other table matching the "id" field. HELP PLZ! THANKS
  14. I dont know what i am sending before the header, i even commented the doctype and i get this error Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\xampplite\htdocs\Mensajeria\index.php:2) in E:\xampplite\htdocs\Mensajeria\includes\session.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at E:\xampplite\htdocs\Mensajeria\index.php:2) in E:\xampplite\htdocs\Mensajeria\includes\functions.php on line 8 <!--<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">--> <? require_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/session.php"); ?> <?php require_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/connection.php"); ?> <?php require_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/functions.php"); ?> <?php if (logged_in()) { redirect_to("index.php"); } include_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/form_functions.php"); // START FORM PROCESSING if (isset($_POST['submit'])) { // Form has been submitted.
  15. actually my php.ini has this enabled, error_reporting = E_ALL
  16. and what am i sending before?? the doctype? why will it work in later versions? Thx
  17. Fixed it! thx, but now i get this error. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\xampplite\htdocs\Mensajeria\login.php:3) inE:\xampplite\htdocs\Mensajeria\includes\session.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at E:\xampplite\htdocs\Mensajeria\login.php:3) in E:\xampplite\htdocs\Mensajeria\includes\functions.php on line 6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <? require_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/session.php"); ?> <?php require_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/connection.php"); ?> <?php require_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/functions.php"); ?> <?php if (logged_in()) { redirect_to("index.php"); } include_once($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/form_functions.php"); // START FORM PROCESSING if (isset($_POST['submit'])) { // Form has been submitted. $errors = array(); // perform validations on the form data $required_fields = array('username', 'password'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); $fields_with_lengths = array('username' => 30, 'password' => 30); $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); if ( empty($errors) ) { // Check database to see if username and the hashed password exist there. $query = "SELECT id, username, region_id, localidad_id,admin "; $query .= "FROM usuarios "; $query .= "WHERE username = '{$username}' "; $query .= "AND hashed_password = '{$hashed_password}' "; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if (mysql_num_rows($result_set) == 1) { // username/password authenticated // and only 1 match $found_user = mysql_fetch_array($result_set); $_SESSION['user_id'] = $found_user['id']; $_SESSION['username'] = $found_user['username']; $_SESSION['region_id'] = $found_user['region_id']; $_SESSION['localidad_id'] = $found_user['localidad_id']; if($found_user['admin']==0) $_SESSION['admin'] = false; else $_SESSION['admin'] = $found_user['admin']; redirect_to("index.php"); } else { // username/password combo was not found in the database $message = "Username/password combination incorrect.<br /> Please make sure your caps lock key is off and try again."; } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " errors in the form."; } } } else { // Form has not been submitted. if (isset($_GET['logout']) && $_GET['logout'] == 1) { $message = "You are now logged out."; } $username = ""; $password = ""; } ?> <?php include($_SERVER["DOCUMENT_ROOT"] . "/Mensajeria/includes/header.php"); ?> <div id="content"> <h2>Inicio de Sesion</h2> <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?> <?php if (!empty($errors)) { display_errors($errors); } ?> <form action="login.php" method="post"> <table> <tr> <td>Username:</td> <td><input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" maxlength="30" value="" /></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Login" /></td> </tr> </table> </form> </td> </tr> </table> </div> <?php include("/includes/footer.php"); ?>
  18. This is my code, i still get the same error. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <? require_once($_SERVER["DOCUMENT_ROOT"] . "/includes/session.php"); ?> <?php require_once($_SERVER["DOCUMENT_ROOT"] . "/includes/connection.php"); ?> <?php require_once($_SERVER["DOCUMENT_ROOT"] . "/includes/functions.php"); ?> <?php if (logged_in()) { redirect_to("index.php"); } include_once($_SERVER["DOCUMENT_ROOT"] . "/includes/form_functions.php"); // START FORM PROCESSING if (isset($_POST['submit'])) { // Form has been submitted. $errors = array(); // perform validations on the form data $required_fields = array('username', 'password'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); $fields_with_lengths = array('username' => 30, 'password' => 30); $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); if ( empty($errors) ) { // Check database to see if username and the hashed password exist there. $query = "SELECT id, username, region_id, localidad_id,admin "; $query .= "FROM usuarios "; $query .= "WHERE username = '{$username}' "; $query .= "AND hashed_password = '{$hashed_password}' "; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); if (mysql_num_rows($result_set) == 1) { // username/password authenticated // and only 1 match $found_user = mysql_fetch_array($result_set); $_SESSION['user_id'] = $found_user['id']; $_SESSION['username'] = $found_user['username']; $_SESSION['region_id'] = $found_user['region_id']; $_SESSION['localidad_id'] = $found_user['localidad_id']; if($found_user['admin']==0) $_SESSION['admin'] = false; else $_SESSION['admin'] = $found_user['admin']; redirect_to("index.php"); } else { // username/password combo was not found in the database $message = "Username/password combination incorrect.<br /> Please make sure your caps lock key is off and try again."; } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " errors in the form."; } } } else { // Form has not been submitted. if (isset($_GET['logout']) && $_GET['logout'] == 1) { $message = "You are now logged out."; } $username = ""; $password = ""; } ?> <?php include($_SERVER["DOCUMENT_ROOT"] . "/includes/header.php"); ?> <div id="content"> <h2>Inicio de Sesion</h2> <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?> <?php if (!empty($errors)) { display_errors($errors); } ?> <form action="login.php" method="post"> <table> <tr> <td>Username:</td> <td><input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" maxlength="30" value="" /></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Login" /></td> </tr> </table> </form> </td> </tr> </table> </div> <?php include("/includes/footer.php"); ?>
  19. Hi, i made an application in my local machine, now that i am done im am going to be plalcing the files into a running server. They told me that the php version is 5.2.5 while my server version is 5.4.3. when i tried running my files int the server i got this errors. Warning: include(/includes/footer.php) [function.include]: failed to open stream: No such file or directory inE:\xampplite\htdocs\Mensajeria\index.php on line 12 Warning: include() [function.include]: Failed opening '/includes/footer.php' for inclusion (include_path='.;E:\xampplite\php\pear\') in E:\xampplite\htdocs\Mensajeria\index.php on line 12 What is this mistake? I know it is the version becuase i installed 5.2.5 version via wamp and it creates the same error, help plz! ThX!!
  20. so, i tried what you said, here is my code, the second select won't load, can you spot qhy?? thanks! $('select.region').change(function(){ $(this).parent('.select').find('select.localidad').attr("disabled","disabled"); $(this).parent('.select').find('select.user').attr("disabled","disabled"); $(this).parent('.select').find('select.localidad').html("<option>Cargando...</option>"); var id = $(this).parent('.select').find('select.region option:selected').attr('value'); $.post("includes/select_localidad.php", {id:id}, function(data){ $(this).parent('.select').find('select.localidad').removeAttr("disabled"); $(this).parent('.select').find('select.localidad').html(data); }); });
  21. I guess i will be manipulating the result with something like the nth-child() am i correct? Another thing, what exactly is ajax? Is is something inside jquery? Inside javascript? Totally apart? I know i used it but im not sure what it is
  22. yes, that is exaclty what i needed, ill modify my code, see if i can get it to work. Thanks!
×
×
  • 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.