deslyxia
New Members-
Posts
7 -
Joined
-
Last visited
Never
Everything posted by deslyxia
-
I gave this a shot but I get an error while ($row = mysql_fetch_assoc($result)){ echo "<tr> <td> <form id=".$row['ID']." name=".$row['ID']." method="post" action="p_select.php"> <input type="hidden" name="PID" value=".$row['ID']."> <input type="submit" value="Submit"> </form> </td> <td>".$row['FName']."</td> <td>".$row['LName']."</td> </tr>"; } the error I get is Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'
-
I have a query that I have run. I am able to output the dataset into a simple table it updates on my page beautifully. In the following code what I want to be able to do is along with the other columns i output have a 4th column that contains a button on each row and when a user clicks a button on the page it selects that particular row. This is the code I have creating my table atm. echo "<table alingn=\"center\" width=\"400px;\">"; echo "<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> </tr>"; while ($row = mysql_fetch_assoc($result)){ echo "<tr> <td>".$row['ID']."</td> <td>".$row['FName']."</td> <td>".$row['LName']."</td> </tr>"; } echo "</table>"; Basically everytime it loops through I would want the row that shows the ID to be a button that would execute a php script but pass it that ID. I dont really want the ID shown on the page.
-
In my Table I have hundreds of LName. $q comes from a user input field on the main page. The purpose here is that every time a user types a letter in the field this query selects all rows from my table that contain the user input string.
-
I am getting the following code when executing a query: Parse error: syntax error, unexpected T_VARIABLE Below is the query it came from. //query db and build name array $qry="SELECT * FROM Patient WHERE LName LIKE "$q""; $result=mysql_query($qry); I know that the issue is coming from the double quotes around $q. If I switch them to single quotes I get no error... but I also get no results. I have looked up the difference between single and double quotes and I think i have it right. Single quotes use exactly what is in them ex. echo '$q'; would be $q Double quotes will evaluate the variable and use that ex. $q = 'php'; echo "$q"; would be php So this has me kind of lost as to what the issue is in my query.
-
I have a form on my web page. When a user clicks the submit button it executes an external php file. The job of this file is to connect to my db and query a table based on user inputs. All of this is working fine so far. What i need to figure out is how to take the result of that query (which could be multiple records from my table) back into a table the user can see on the original web page. The way i see it is i need to somehow pass the query result back to the main page and then ru na loop and dump everything into a table. My form looks like this <form id="searchForm" name="searchForm" method="post" action="psearch.php" autocomplete="off"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="112"><b>First Name</b></td> <td width="188"><input name="fname" type="text" class="textfield" id="fname" /></td> </tr> <tr> <td><b>Last Name</b></td> <td><input name="lname" type="text" class="textfield" id="lname" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Search" /></td> </tr> </table> </form> External PHP file <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $fname = clean($_POST['fname']); $lname = clean($_POST['lname']); //Query the Database $query = "select * from Patient where FName like '%$fname%' and LName like '%$lname%' "; $result = mysql_query($query) or die(mysql_error()); Code to build and fill my data table with the records. //Display Results echo "<table alingn=\"center\" width=\"400px;\">"; echo "<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> </tr>"; while ($row = mysql_fetch_assoc($result)){ echo "<tr> <td>".$row['ID']."</td> <td>".$row['FName']."</td> <td>".$row['LName']."</td> </tr>"; } echo "</table>"; ?> How do i get my query result from the external PHP file into the main html doc ... and build this table AFTER the form data is submitted?
-
psearch.php is just an external php file that i execute upon submit. It logs into the DB and performs a query. I somehow need to get my result set back onto the original page. How do i do this lol
-
Good Afternoon, The issue i have is as follows. I have a form on my webpage, WHen the user clicks the submit button it excecutes an external php file which querys my database. I need to get the results of that query back into my main web page in a table. In researching this It seems that i need to use AJAX and possibly JQuery to do this ... but i have never used either so im lost. Any help with this would be a great help as well as a great learning tool. <form id="searchForm" name="searchForm" method="post" action="psearch.php" autocomplete="off"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="112"><b>First Name</b></td> <td width="188"><input name="fname" type="text" class="textfield" id="fname" /></td> </tr> <tr> <td><b>Last Name</b></td> <td><input name="lname" type="text" class="textfield" id="lname" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Search" /></td> </tr> </table> </form> PhP File <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $fname = clean($_POST['fname']); $lname = clean($_POST['lname']); //Query the Database $query = "select * from Patient where FName like '%$fname%' and LName like '%$lname%' "; $result = mysql_query($query) or die(mysql_error());