My php Table code is not working - php

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.

Related

SQL query fails in prod environment on IIS but works in test environment running Apache

I'm having a bit of an issue with quires failing when I upload to the live environment while they are fully functional in the test environment, I'm at a loss at this point about where the error may be so I finally broke down and decided to ask those of stack overflow that may be much more skilled than myself if there's something I've missed. The quires look at serial number information from two different tables to pull system specs and any hard drive information associated with the parent serial
<?php
$Dev_HDD = 0;
$con=mysqli_connect("localhost","username","user_password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST["serial"]))
{
$SerialNumber = $_POST["serial"];
$sql ="SELECT system.Manufacturer, system.Model, system.SerialNumber, system.Processor, system.Memory FROM system WHERE SerialNumber = '" .$SerialNumber. "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$System_Manufacturer = $row[0];
$System_Model = $row[1];
$System_SerialNumber = $row[2];
$System_Processor = $row[3];
$System_Memory = $row[4];
?>
<table border="0" height="100%" width="100%" align="left" valign="top">
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">System Summary:</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>System Manufacturer</td>
<td>
<?php echo $System_Manufacturer; ?>
</td>
</tr>
<tr>
<td>System Model:</td>
<td>
<?php echo $System_Model; ?>
</td>
</tr>
<tr>
<td valign="top">System Serial Number</td>
<td valign="top">
<?php echo $System_SerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">System Processor</td>
<td valign="top">
<?php echo $System_Processor; ?>
</td>
</tr>
<tr>
<td valign="top">System Memory</td>
<td valign="top">
<?php echo $System_Memory; ?>
</td>
</tr>
<?php
}
// Free result set
mysqli_free_result($result);
}
else
{
echo "The serial number specified could not be located<br>";
}
$sql ="SELECT device.recid, device.Manufacturer, device.Model, device.SerialNumber, device.Capacity, device.RPM, device.ErasureMethod, device.ErasureResults FROM device WHERE SystemSerialNumber = '" . $System_SerialNumber . "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$Dev_Recid = $row[0];
$Dev_Manufacturer = $row[1];
$Dev_Model = $row[2];
$Dev_DeviceSerialNumber = $row[3];
$Dev_Capacity = $row[4];
$Dev_RPM = $row[5];
$Dev_ErasureMethod = $row[6];
$Dev_ErasureResults = $row[7];
?>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">Storage Summary(<?php echo $Dev_HDD = $Dev_HDD + 1; ?>):</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>Hard Drive Manufacturer</td>
<td>
<?php echo $Dev_Manufacturer; ?>
</td>
</tr>
<tr>
<td>Hard Drive Model:</td>
<td>
<?php echo $Dev_Model; ?>
</td>
</tr>
<tr>
<td valign="top">Serial Number Lookup</td>
<td valign="top">
<?php echo $Dev_DeviceSerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Capacity</td>
<td valign="top">
<?php echo $Dev_Capacity; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Speed</td>
<td valign="top">
<?php echo $Dev_RPM; ?>
</td>
</tr>
<tr>
<td>Erasure Method:</td>
<td>
<?php echo $Dev_ErasureMethod; ?>
</td>
</tr>
<tr>
<td>Erasure Results:</td>
<td>
<?php echo $Dev_ErasureResults; ?>
</td>
</tr>
<tr>
<td>Parent Serial Number:</td>
<td>
<?php echo "<a href='logs/" .$Dev_DeviceSerialNumber.".log' target='_blank'>".$Dev_DeviceSerialNumber."</a> <br>";?>
</td>
</tr>
</table>
<?php
}
}
// Free result set
mysqli_free_result($result);
mysqli_close($con);
}
?>
<?php
echo " <br>";
echo "<pre></pre>";
?>

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

IDE showing error in PHP concatenation

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.

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.

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