Some doubts to clear

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stanleycwb
Forum Newbie
Posts: 23
Joined: Fri Aug 15, 2008 11:33 am

Some doubts to clear

Post by stanleycwb »

Hi, i have some things that i dunno whether im doing correctly.

1)
my php coding

Code: Select all

 
if ($Future == 'NS') {
 ***coding A
}
my html coding

Code: Select all

<h3><input type="radio" value="NS" name="Future">NS</h3>
 
<h3><input type="radio" value="work" name="Future">Work</h3>
What im trying to do here is a if else statement. Since it's a radio button, the user can only select one of the option. And if the user select NS, it will execute coding A. if the user select work, it will execute coding B. But is my php coding correct? or is it double quote(") instead of single quote(') or is it cannot be done?

2)

Code: Select all

 
if (!((strng.search(/[a-z]+/) > -1) && (strng.search(/[0-9]+/) > -1))) {
  ***coding
} 
 
Is it a form validation coding that validates letters and digits must be entered? But it seems to be missing one part and i dun really know how and where to add in. Which is like it is checking which field.

3)
I looked through the net and found this email address validation coding.

Code: Select all

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $Email)) {
  die ('Invalid email address');
}
However, when i executed this coding, it display error which says unexpected '/' and '*' even after i remove them.
I dunno wat's wrong with it.

4)
Is it possible for a insert php coding to be like this?

Code: Select all

 $sql4="INSERT INTO studies (matric_no, Course_name, institution_name, Country, Studies_Description) VALUES ('$_POST[matric_no]','Nil','Nil','Nil','Nil')";
 
Because the matric_no is taken from the form while the rest i wanted it to be entered as Nil even if the user types anything on those fields in the form.

5)

Code: Select all

$sql2 = "Select * FROM jobs WHERE matric_no LIKE '%$matric_no%' ORDER BY Job_Start_Date";
$query2 = mysql_query($sql2, $con);
if(!$query2)
  {
  die('Error: ' . mysql_error());
  } 
 
print "<table border=2>";
  while ($result2 = mysql_fetch_array($query2))
  {
  extract($result2);   // assigns $ variables for all the elements in the array
   print"<tr>";
   print "<td><b>Job Industry</b></td> <td>$Job_Industry</td>";
   print"<tr></tr>";
   print "<td><b>Job Company Name</b> </td> <td>$Job_Company</td>";
   print "<tr></tr>";
   print "<td><b>Job Position</b></td> <td>$Job_Position</td>";
   print"<tr></tr>";
   print "<td><b>Job Department</b></td ><td>$Job_Department</td>";
   print "<tr></tr>";
   print "<td><b>Job Description</b> </td> <td>$Job_Description</td>";
   print "<tr></tr>";
   print "<td><b>Job Start Date</b> </td> <td>$Job_Start_Date</td>";
   print "<tr></tr>";
   print "<td><b>Job End Date</b> </td> <td>$Job_End_Date</td>";
   print "<tr></tr>";
   print "<br /><br />
 
 
///print studies table information
$sql3 = "Select * FROM studies WHERE matric_no LIKE '%$matric_no%'";
$query3 = mysql_query($sql3, $con);
if(!$query3)
  {
  die('Error: ' . mysql_error());
  } 
 
print "<table border=2>";
  while ($result3 = mysql_fetch_array($query3))
  {
  extract($result3);   // assigns $ variables for all the elements in the array
   print"<tr>";
   print "<td><b>Course Name</b></td> <td>$Course_Name</td>";
   print"<tr></tr>";
   print "<td><b>Institution Name</b> </td> <td>$institution_name</td>";
   print "<tr></tr>";
   print "<td><b>Country</b></td> <td>$Country</td>";
   print"<tr></tr>";
   print "<td><b>Course Description</b></td ><td>$studies_Description</td>";
   print "<tr></tr>";
   print "<br /><br />
 
I wan my coding to be like able to display the person's jobs information before the studies information. Then it will skip to the next person. Does my code does that? How can i improve on it?

6)
I have a search php coding.

Code: Select all

$sql = "SELECT * FROM Student WHERE ";
 
foreach($_POST as $key => $value) {
    if(isset($value)) {
      $sql .= "`$key` LIKE '%$value%' AND ";
    }
}
 
$sql = substr($sql,0,strripos($sql," AND "));
$query1 = mysqli_query($conn, $sql) or die("Query failed! " . mysql_error() . "<br>". $sql);
 
It shows no problem at all. But it could only works if the search fields are all under the 'Student' table. But wat if one of my search field is from another table? (e.g. like jobs) What can i do to improve the coding? Or there is no way other than seperating the search fields criteria into 2 html forms?

Hmm that's all my doubts. I been troubled by these and delaying my progress. Could any experts or anyone clear my confusion? I really need help.
Thanks alot.
Post Reply