IDE showing error in PHP concatenation - php

I am trying to display name and address in mail using the following piece of code this is perfect-
</tr>
<tr>
<td align="left"><p>'.$admin_message['message'].'</P></td>
</tr>
<tr>
<td align="left"><p>Kind Regards</P></td>
</tr>
<tr>
<td align="left"><p>'.ucwords($finance_info['fi_schoolname']).
'<br />'.ucwords($finance_info['fi_address']).
' <br /> Email :- '.ucwords($finance_info['fi_email']).
'<br /> Contact:- '.ucwords($finance_info['fi_phoneno']).'</P>
</td>
</tr>
Now I want to add a image logo in it for which I am trying like this -
<tr>
<td align="left"><p>'.$admin_message['message'].'</P></td>
</tr>
<tr>
<td align="left"><p>Kind Regards</P></td>
</tr>
<tr>
<td align="left"><p>'
if($_SESSION['eschools']['schoollogo']!=""){ echo displayimage("images/school_logo/".$_SESSION['eschools']['schoollogo'], "140"); }
.' '.
ucwords($finance_info['fi_schoolname']).'<br>
'.ucwords($finance_info['fi_address']).' <br />
Email :- '.ucwords($finance_info['fi_email']).'<br>
Contact:- '.ucwords($finance_info['fi_phoneno']).'</P></td>
</tr>
</table>';
But on Line No. 9 and 10 shows error by IDE I am using Dreamweaver. I need to know where I am doing mistake in concatenation.
Regards to all

this is wrong :
<td align="left"><p>'
if($_SESSION['eschools']['schoollogo']!=""){ echo displayimage("images/school_logo/".$_SESSION['eschools']['schoollogo'], "140"); }
correct code :
<?php
echo '
<tr>
<td align="left"><p>'.$admin_message['message'].'</P></td>
</tr>
<tr>
<td align="left"><p>Kind Regards</P></td>
</tr>
<tr>
<td align="left"><p>';
if($_['eschools']['schoollogo']!=""){ echo displayimage("images/school_logo/".$_['eschools']['schoollogo'], "140"); }
echo '    '.
ucwords($finance_info['fi_schoolname']).'<br>
'.ucwords($finance_info['fi_address']).' <br />
Email :- '.ucwords($finance_info['fi_email']).'<br>
Contact:- '.ucwords($finance_info['fi_phoneno']).'</P></td>
</tr>
</table>';

You don't have a semicolon after the ' after the <p> in line 8.

Related

My php Table code is not working

So, I was just trying some things, and I wanted to do a table, but when I try to run it, it gives me an error in this part of the code:
echo '
echo '
<table border = 1 width = 300px>
<tr>
<td> Name:
</td>
<td '.$Contacts[$Index]['Name']>
</td>
</tr>
<tr>
<td> Phone:
</td>
<td '.$Contacts[$Index]['Phone number']>
</td>
</tr>
<tr>
<td> Email:
</td>
<td '.$Contacts[$Index]['email']>
</td>
</tr>
';
Can someone please tell me if there is anything wrong I am not seeing?
Concatenation is not done properly.
<?php
echo '
<table border = 1 width = 300px>
<tr>
<td> Name:
</td>
<td>' . $Contacts[$Index]['Name'] .'
</td>
</tr>
<tr>
<td> Phone:
</td>
<td>' . $Contacts[$Index]['Phone number'] . '
</td>
</tr>
<tr>
<td> Email:
</td>
<td>'. $Contacts[$Index]['email'] . '
</td>
</tr>
';
There is an error in your concatenation. I would prefer you close your php tags, output simple html and use php to echo variables when required. It will keep the code clean. Here is an example
?>
<table border = 1 width = 300px>
<tr>
<td> Name:</td>
<td> <?php echo $Contacts[$Index]['Name']; ?> </td>
</tr>
<tr>
<td> Phone:</td>
<td><?php echo $Contacts[$Index]['Phone number']; ?></td>
</tr>
<tr>
<td> Email:</td>
<td> <?php echo $Contacts[$Index]['email'];?></td>
</tr>
<?php
There is another error that you are add values as <td value></td> while the correct way is <td>value<td>
I have resolved that issue.

How to automatically generate rowspan using php

In this code everything is perfect except that I could not generate rowspan in the Internal Grade cell. this line <td rowspan="<?php echo $cols;?>"> hides the bottom border while I expect to span the rows every time the code generates rows. Thanks for your input and sorry for using mysql() function. I am newbie.
<?php $cols=mysql_num_rows($grds); ?>
<table>
<?php do{ ?>
<tr>
<td> </td>
//This hide the bottom border
<td rowspan="<?php echo $cols;?>">Internal<br />Grades</td>
<td colspan="2"> <?php echo strtoupper($row_grds['grade_name']); ?></td>
<td><?php echo strtoupper($row_grds['igrade']); ?></td>
<?php } while ($row_grds=mysql_fetch_assoc($grds)); ?>
</tr>
</table>
The output is like below:
output is here
The code generated by php is:
<table>
<tr>
<td> </td>
<td rowspan="1"> </td>// A
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<tr>
<td> </td>
<td rowspan="2"> </td>//B
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>
</table>
I want to merge A and B
Expected output is:
<table>
<tr>
<td> </td>
<td rowspan="2"> Internal<br /> Grade</td>
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<tr>
<td> </td>
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>
</table>
You can do something similar to this:
<table>
<?php $row_grds = mysql_fetch_assoc($grds); ?>
<tr>
<td> </td>
<td rowspan="<?=$cols;?>">Internal<br />Grades</td>
<td colspan="2"> <?=strtoupper($row_grds['grade_name']);?></td>
<td><?=strtoupper($row_grds['igrade']);?></td>
</tr>
<?php while ($row_grds=mysql_fetch_assoc($grds)): ?>
<tr>
<td> </td>
<td colspan="2"> <?=strtoupper($row_grds['grade_name']);?></td>
<td><?=strtoupper($row_grds['igrade']);?></td>
</tr>
<?php endwhile; ?>
Its not perfect but you are using mysql_fetch_assoc, which on its own is not perfect either :D

check email address used by others in database, if yes, pop up alert, if no, continue to next step

i am constructing a registration page for new members. after filling in the form, it will proceed to the confirm page. after confirmation, it will proceed to the reg_add.php to add the data from the form to the database.
reg_new.php --> reg_confirm.php --> reg_add.php
i am trying to edit the code in the confirm page (reg_confirm.php) to include the email availability check. it seems that it can automatically detect the duplicate email and after clicking the confirm button.
Duplicate entry 'shop#gmail.com' for key 'PRIMARY' will be shown.
yet, it is not success to have a pop up alert and stay in the confirm page. please help.
<?php
session_start();
$_SESSION['email'] = $_POST['email_reg'];
$_SESSION['password'] = $_POST['password_reg'];
$_SESSION['name_reg'] = $_POST['name_reg'];
$_SESSION['month'] = $_POST['month'];
$_SESSION['telephone_reg'] = $_POST['telephone_reg'];
$_SESSION['room_reg'] = $_POST['room_reg'];
$_SESSION['floor_reg'] = $_POST['floor_reg'];
$_SESSION['block_reg'] = $_POST['block_reg'];
$_SESSION['building_reg'] = $_POST['building_reg'];
$_SESSION['estate_reg'] = $_POST['estate_reg'];
$_SESSION['street_reg'] = $_POST['street_reg'];
$_SESSION['district_reg'] = $_POST['district_reg'];
$_SESSION['region_reg'] = $_POST['region_reg'];
$regemail = $_POST["email_reg"];
$connect = mysql_connect("127.0.0.1","root","") or die("not connecting");
mysql_select_db("shop") or die("no db :'(");
$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");
if ($numrows!=0)
{
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
?>
</head>
<body>
<div align="center" class="style1"><span class="style2">Registeration Confirm</span>
<p class="style2"> </p>
<form action="reg_add.php" method="post" enctype="multipart/form-data" name="form1">
<table width="602" height="180" border="1">
<tr>
<td colspan="3">Login Information</td>
</tr>
<tr>
<td width="160" class="style6">Email address: </td>
<td colspan="2"><span class="style7"><?php echo $_SESSION['email']?></span></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="3">User information </td>
</tr>
<tr>
<td><span class="style6">Name:</span></td>
<td colspan="2"><?php echo ($_SESSION['name_reg'])?></td>
</tr>
<tr>
<td><span class="style6">Month of birth :</span></td>
<td colspan="2"><?php echo ($_SESSION['month'])?>
</tr>
<tr>
<td><span class="style6">Contact telephone:</span></td>
<td colspan="2"><?php echo ($_SESSION['telephone_reg'])?></td>
</tr>
<tr>
<td rowspan="8"><span class="style6">Contact address:</span></td>
<td width="153"><p class="style6">Room/ Flat no.: </p> </td>
<td width="267"><p class="style6"><?php echo ($_SESSION['room_reg'])?></p> </td>
</tr>
<tr>
<td><span class="style6">Floor: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['floor_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Block/ Tower:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['block_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Building:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['building_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Estate: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['estate_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Street:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['street_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">District:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['district_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Region: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['region_reg'])?></span></td>
</tr>
<tr>
<td colspan="3" class="style6"> </td>
</tr>
</table>
<p>
<input name="confirm" type="submit" id="confirm" value="Confirm">
</p>
</form>
<p>
<input name="modifty" type="submit" id="modifty" value="Modify" onClick="history.go(-1)">
</p>
</div>
</body>
</html>
Your problem is how you are retrieving the number of rows from the database.
mysql_query() does not retrieve the number of rows. It retrieves a result set.
Instead of:
$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");
if ($numrows!=0)
{
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
Use:
$email = mysql_real_escape_string($_POST["email_reg"]);
$result = mysql_query("SELECT COUNT(memberemail) AS emailCount FROM member WHERE memberemail='{$email}'");
$row = mysql_fetch_row($result);
if($row[0]>0){
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
ALWAYS make sure you escape your data before using it in a database query.

How To Format This Scraped Content

I'm grabbing the content from all the td's in this table with the class="job" using this.
$table01 = $salary->find('table.table01');
$rows = $table01[0]->find('td.job');
Then I'm using this to output it which works, but obviously only outputs it as plaintext, I need to do some more with it...
foreach($table01[0]->find('td.job') as $element) {
$jobs .= $element->plaintext . '<br />';
}
Ultimately I would like it outputted to this format. Notice the a href is using the job name and replacing spaces and / with a -.
<tr>
<td class="small"> Graphic Artist / Designer
$23,755 – $55,335 </td>
</tr>
<tr>
<td class="small"> Sales Associate<br />
$15,577 – $56,290 </td>
</tr>
<tr>
<td class="small"> Film / Video Editor<br />
$24,184 – $94,493 </td>
</tr>
Heres the table im scraping
<table cellpadding="0" cellspacing="0" border="0" class="table01">
<tr>
<td class="head">Test</td>
<td class="job">
Graphic Artist / Designer<br/>
$23,755 – $55,335
</td>
</tr>
<tr>
<td class="head">Test</td>
<td class="job">
Sales Associate<br/>
$15,577 – $56,290
</td>
</tr>
<tr>
<td class="head">Test</td>
<td class="job">
Film / Video Editor<br/>
$24,184 – $94,493
</td>
</tr>
</table>
may be better to use regexps
<?php
$html=file_get_contents('1.html');
$jobs='';
if(preg_match_all("/<tr>.*?<td.*?>.*?<\/td>.*?<td\sclass=\"job\">.*?<a.+?href=\"(.+?)\".+?>(.*?)<\/a>(.*?)<\/td>.*?<\/tr>/ims", $html, $res))
{
foreach($res[1] as $i=>$uri)
{
$uri=strtolower(urldecode($uri));
$uri=preg_replace("/_\/_/",'-',$uri);
$uri=preg_replace("/_/",'-',$uri);
$jobs.='<tr><td class="small"> '.$res[2][$i].''.$res[3][$i].'</td></tr>'."\n";
}
}
echo $jobs;

Can php code execute while creation of pdf using tcpdf?

I m working on module in which i have to make pdf from php page. I m Using tcpdf for that but m facing one problem that file contain some mysql queries and php coding which is not executed by pdf page.
$prn_no = $_POST['prn_no'];
$current_sem = $_POST['current_sem'];
$qr_fetch_sem_res_id = mysql_query("SELECT * FROM table1 WHERE ((prn='$prn_no') AND (semisterName='$current_sem'))")or die(mysql_error());
$qr_fetch_sem_result_ans = mysql_fetch_array($qr_fetch_sem_res_id);
<tr>
<td colspan="11" align="left" valign="middle">Programme Name: <?php echo $qr_fetch_sem_result_ans['programme_name'];?></td>
</tr>
<tr>
<td colspan="11" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="27%">Seat No.: <?php echo $qr_fetch_sem_result_ans['seatNo'];?></td>
<td width="3%"> </td>
<td width="22%">PR No. : <?php echo $qr_fetch_sem_result_ans['prn'];?></td>
<td width="2%"> </td>
<td width="17%">Semester : <?php echo $qr_fetch_sem_result_ans['semisterName'];?></td>
<td width="1%"> </td>
<td width="25%">Month / Year Of Exam : <?php echo $qr_fetch_sem_result_ans['month_year_of_exam'];?> </td>
<td width="3%"> </td>
</tr>
<tr>
<td colspan="3">Name: <?php echo $qr_fetch_sem_result_ans['student_name'];?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="7">College / Institute: <?php echo $qr_fetch_sem_result_ans['institute_name'];?></td>
<td> </td>
</tr>
</table></td>
</tr>
I'm going to go out on a limb here and suggest that you run your queries fist and then build your pdf file. If you run the queries after you build the pdf then of course it will not have access to your data. If that doesn't help then I must not understand what you're asking.

Categories