PDA

View Full Version : code php and html error


loveallah
11-26-2008, 09:54 PM
peace upon you
hi,
this code with php give me an error


<body bgcolor=blue>
<form action="element.php" method=post>



<?

$connect=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('phonebook');
$sqlquery = "select * from book";
$result = mysql_query($sqlquery);
$number = mysql_affected_rows();
$i=0;


if($number == 0 )
{
print "<center>No previous orders</center>";

print "<table border=1>
<tr><th></th><th>Name</th><th>Home Number</th><th>Mobile Number</th>
<tr bgcolor=red>
<td align=center><input type="submit" size="5" value="Submit" onClick="fun()"></td>
<td><input type="text" name="name" size="20" maxlength="20"></td>
<td><input type="text" name="home" size="20" maxlength="20"></td>
<td><input type="text" name="mobile" size="20" maxlength="20"></td>
</table>" ;
exit;

}
else
{
print"<center>Add new Person Number</center> <br>";

print"

<table border=1>
<tr><th></th><th>Name</th><th>Home Number</th><th>Mobile Number</th>
<tr bgcolor=red>
<td align=center><input type="submit" size="5" value="Submit" onClick="fun()"></td>
<td><input type="text" name="name" size="20" maxlength="20"></td>
<td><input type="text" name="home" size="20" maxlength="20"></td>
<td><input type="text" name="mobile" size="20" maxlength="20"></td> ";

while($number>$i)
{
$name=mysql_result($result,$i,"Name");
$home=mysql_result($result,$i,"home");
$mobil=mysql_result($result,$i,"mobile");
$i++;
print"<tr><td></td><td>$name</td><td>$home</td><td>$mobil</td>";
}
}

</form>

</body>
it's output is two tables an the php code as it is
what can i do
please any one reply me quickly

sajidali
12-05-2008, 05:00 AM
as you said, full php is showing as the output. it means, either your file extension is not .php or your php server is not properly configured.

Also the code below is now error free, as your submitted code was messy with multiple double quotes that will stop script from execution.
Notice there are some modifications.

<body bgcolor=blue>
<form action="element.php" method=post>


<?

$connect=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('phonebook');
$sqlquery = "select * from book";
$result = mysql_query($sqlquery);
$number = mysql_affected_rows();
$i=0;


if($number == 0 )
{
print "<center>No previous orders</center>";

print '<table border=1>
<tr><th></th><th>Name</th><th>Home Number</th><th>Mobile Number</th>
<tr bgcolor=red>
<td align=center><input type="submit" size="5" value="Submit" onClick="fun()"></td>
<td><input type="text" name="name" size="20" maxlength="20"></td>
<td><input type="text" name="home" size="20" maxlength="20"></td>
<td><input type="text" name="mobile" size="20" maxlength="20"></td>
</table>' ;
exit;

}
else
{
print"<center>Add new Person Number</center> <br>";

print'

<table border=1>
<tr><th></th><th>Name</th><th>Home Number</th><th>Mobile Number</th>
<tr bgcolor=red>
<td align=center><input type="submit" size="5" value="Submit" onClick="fun()"></td>
<td><input type="text" name="name" size="20" maxlength="20"></td>
<td><input type="text" name="home" size="20" maxlength="20"></td>
<td><input type="text" name="mobile" size="20" maxlength="20"></td>';

while($number>$i)
{
$name=mysql_result($result,$i,"Name");
$home=mysql_result($result,$i,"home");
$mobil=mysql_result($result,$i,"mobile");
$i++;
print"<tr><td></td><td>$name</td><td>$home</td><td>$mobil</td>";
}
}
?>
</form>

</body>

For clearing your idea more lets read below.

print "<table border=1>
<tr><th></th><th>Name</th><th>Home Number</th><th>Mobile Number</th>
<tr bgcolor=red>
<td align=center><input type="submit" size="5" value="Submit" onClick="fun()"></td>
<td><input type="text" name="name" size="20" maxlength="20"></td>
<td><input type="text" name="home" size="20" maxlength="20"></td>
<td><input type="text" name="mobile" size="20" maxlength="20"></td>
</table>" ;

you r using double quotes to start a string and inside it you have some html code which also have some double quotes, this is not proper way. you can do three things here. either escape your double quotes of the html like this.

print "<table border=1>
<tr><th></th><th>Name</th><th>Home Number</th><th>Mobile Number</th>
<tr bgcolor=red>
<td align=center><input type=\"submit\" size=\"5\" value=\"Submit\" onClick=\"fun()\"></td>
<td><input type=\"text\" name=\"name\" size=\"20\" maxlength=\"20\"></td>
<td><input type=\"text\" name=\"home\" size=\"20\" maxlength=\"20\"></td>
<td><input type=\"text\" name=\"mobile\" size=\"20\" maxlength=\"20\"></td>
</table>" ;

or you can use non matching quotes like this.

print '<table border=1>
<tr><th></th><th>Name</th><th>Home Number</th><th>Mobile Number</th>
<tr bgcolor=red>
<td align=center><input type="submit" size="5" value="Submit" onClick="fun()"></td>
<td><input type="text" name="name" size="20" maxlength="20"></td>
<td><input type="text" name="home" size="20" maxlength="20"></td>
<td><input type="text" name="mobile" size="20" maxlength="20"></td>
</table>' ;

also the closing php tag was missing before the closing form tag. :)

let me know if u still found anything missing. I will try to help you....

loveallah
12-11-2008, 10:04 AM
thanks you very much
I have understan how to write ahtml code inside the php code:)

and thanks there is no any thing left