Note that there are some explanatory texts on larger screens.

plurals
  1. POextracting data from a html form and comparing to a field in the database with php
    text
    copied!<p>I have been trying to get this right, but it does not work. I can retrieve all the data from the database, but I wanted to retrieve a jobname from a html form which the user input in the form and a location also input in the form by the user and compare these texts with the jobname and location field on a table on the database. I know it sounds confusing, but here is my code that does nothing:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;?php ob_start(); $host=""; // Host name $username= ""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $job=$_POST['jobName']; $mylocation=$_POST['location']; // To protect MySQL injection (more detail about MySQL injection) $job = stripslashes($job); $mylocation = stripslashes($mylocation); $job = mysql_real_escape_string($job); $mylocation = mysql_real_escape_string($mylocation); $sql="SELECT * FROM ".$tbl_name." WHERE jobName='".$job."' and location='".$mylocation."';"; $result=mysql_query($sql); $num=mysql_numrows($result); mysql_close(); ?&gt; &lt;table border="0" cellspacing="2" cellpadding="2"&gt; &lt;tr&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;jobName&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;jobType&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Location&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Description&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Contact&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php $i=0; while ($i &lt; $num) { $job=mysql_result($result,$i,"jobName"); $type=mysql_result($result,$i,"jobType"); $myLocation=mysql_result($result,$i,"location"); $desc=mysql_result($result,$i,"description"); $cont=mysql_result($result,$i,"contact"); ?&gt; &lt;tr&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $job; ?&gt;&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $type; ?&gt;&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $myLocation; ?&gt;&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $desc; ?&gt;&lt;/font&gt;&lt;/td&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $cont; ?&gt;&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php $i++; } ob_end_flush(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I just need a good tutorial to help me out although nothing I researched up to now helped me out, maybe if I can get an example code stating a similar issue, or a helping hand explaining where I am going wrong on this code. I appreciate it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload