Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP & SQL help PLEASE :O)

  • 10-06-2014 12:27pm
    #1
    Registered Users, Registered Users 2 Posts: 4


    Hi Good people of Boards... Its my first time here and first post, so forgive me if it is in the incorrect area

    I have a tiny issue and am seeking help/assistance...

    I am building a website in which a person can search a database for location and language... The HTML Form is:

    <form name="hotelSearch" action="hotelSearchRes1.php" method="post">
    Search for language <select name="hotelLang">
    <option value="English">English</option>
    <option value="French">French</option>
    <option value="German">German</option>
    </select>
    <select name="hotelLoc">
    <option value="Galway">Galway</option>
    <option value="Sligo">Sligo</option>
    <option value="Mayo">Mayo</option>
    <input name="Submit" type="submit" value="Submit" />
    </form>

    So hotelLang is language, hotelLoc is location.

    I have sent this to a new page and created a recordset to check the database. This is going good if I want to search for just 1 item. But I am looking for 2.. I have tried to alter the MySQL to search for 2, but to no avail... My PHP/SQL code generated by Dreamweaver is:


    $maxRows_Recordset1 = 10;
    $pageNum_Recordset1 = 0;
    if (isset($_GET)) {
    $pageNum_Recordset1 = $_GET;
    }
    $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

    $colname_Recordset1 = "-1";
    if (isset($_POST)) {
    $colname_Recordset1 = $_POST;
    $loc = $_POST; <
    I have made loc to be filled with the posting from the location of the form
    }
    mysql_select_db($database_mainConn, $mainConn);
    $query_Recordset1 = sprintf("SELECT * FROM hotel WHERE hotelLang = %s", GetSQLValueString($colname_Recordset1, "text"));
    $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
    $Recordset1 = mysql_query($query_limit_Recordset1, $mainConn) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);

    if (isset($_GET)) {
    $totalRows_Recordset1 = $_GET;
    } else {
    $all_Recordset1 = mysql_query($query_Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
    }
    $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
    ?>

    Any guidance is greatly appreciated..... PEACE

    PoppaFluff


Comments

  • Registered Users, Registered Users 2 Posts: 1,987 ✭✭✭Ziycon


    Add both values your searching for in your SQL:

    SELECT * FROM hotel WHERE hotelLang = %s AND hotelLoc = %s


  • Registered Users, Registered Users 2 Posts: 4 PoppaFluff


    Ziycon wrote: »
    Add both values your searching for in your SQL:

    SELECT * FROM hotel WHERE hotelLang = %s AND hotelLoc = %s

    Hi - Thanks so much for your help..

    When I added what was advised I was greeted with the following error message:

    "Warning: sprintf(): Too few arguments in C:\xampp\htdocs\Project\hotelSearchRes1.php on line 47
    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 'LIMIT 0, 10' at line 1"

    Any idea?

    Thanks again...


  • Registered Users, Registered Users 2 Posts: 29 B000


    This should work:

    $query_Recordset1 = sprintf("SELECT * FROM hotel WHERE hotelLang = %s AND hotelLoc = %s", GetSQLValueString($colname_Recordset1, "text"), GetSQLValueString($loc, "text"));


  • Registered Users, Registered Users 2 Posts: 4 PoppaFluff


    B000 wrote: »
    This should work:

    $query_Recordset1 = sprintf("SELECT * FROM hotel WHERE hotelLang = %s AND hotelLoc = %s", GetSQLValueString($colname_Recordset1, "text"), GetSQLValueString($loc, "text"));

    Hi B000,

    Thank for you for your assistance....your advice is very close, but I got the following error:

    Unknown column 'hotelLoc' in 'where clause'

    Any idea?

    Thanks again


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    What is the schema of the hotel table?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 4 PoppaFluff


    What is the schema of the hotel table?
    What is the schema of the hotel table?

    Hi Colonel Panic,

    If this helps... I am using PHPMYADMIN... Database is called Project files... in this DB I have 2 tables - User and Hotel.... Both are readable and accessible as I can echo values from them

    My table is pretty basic so far.. I have tired to upload a pic but cannot as I am only new... However, I can read the DB and echo out the individual elements stored...

    I have also echoed out the search results at the bottom of the table after the back link...

    I dont know if that offers assistance,

    Thank you very much for your assistance here! I REALLY appreciate it!!

    Richie


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    What are the columns in the Hotel table? Is hotelLoc one of them? In your script, you should echo the generated SQL query and try that from PHPMyAdmin also.


  • Registered Users, Registered Users 2 Posts: 66 ✭✭CathalC2011


    You should really look into PSR standards.


  • Registered Users, Registered Users 2 Posts: 772 ✭✭✭maki


    It's probably not causing you any problems at the moment, but you really should be using mysqli instead mysql.
    The entire mysql extension is deprecated and will be removed at some point. You're much better off learning to use mysqli now rather than later.


Advertisement