Hi I am completely new to this PDO thing as Im use to coding in the old way, but is time to upgrade. I have been trying to follow tuturials on PDO but I just can not get my head arround it..
I have included the php code, so if any 1 can fix it and get it to work perfectly also allowing all symbols to me used esp ' and "
I know the code is a mess but this is just because I am trying to learn. Once this page works on my site I can then use the code to implement into the rest of the other scripts..
What I want this to do is show whats on the page (Obviously lol) and Update, if you could also add insert aswell to give me idears on what I am doing..
All help will be very much appreciated as this is stressing my nuts off lol
<?php
if (!(@include "inc/inc-header.php")) { die("Unable to Open Configuration File"); }
if (!(@include "inc/config.php")) { die("Unable to Open Configuration File"); } /// <--- basic config file no info inside apart from database details.
try {
$dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
echo 'Select Connected to database<br />';
$sql = "SELECT * FROM events WHERE status='show'";
$sql = "SELECT * FROM home WHERE id='1'";
foreach ($dbh->query($sql) as $row)
{
print $row['day'] .' - '. $row['month'] . '<br />'; // <--- this was also a mess about to see what happens
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
///// This was my last test but constantly fails like the rest
try {
$DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
# UH-OH! Typed DELECT instead of SELECT!
$DBH->prepare('SELECT * FROM events');
}
catch(PDOException $e) {
echo "<BR>I'm sorry, I'm afraid I can't do that."; /// <--- This message displays all the time showing it has failed
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
if(isset($_POST['update']))
{
$title = $_POST['title'];
$news = $_POST['news'];
$fphoto = $_POST['fphoto'];
$msg1 = $_POST['msg1'];
$msg2 = $_POST['msg2'];
$msg3 = $_POST['msg3'];
$msg4 = $_POST['msg4'];
$tmsg2 = $_POST['tmsg2'];
$tmsg3 = $_POST['tmsg3'];
$tmsg4 = $_POST['tmsg4'];
try {
$dbh = new PDO("mysql:host=$hostname;dbname=$database;", $username, $password);
echo 'Update Connected to database<br />';
$count = $dbh->exec
("UPDATE home SET title='$title', news='$news', fphoto='$fphoto', msg1=$msg1', msg2='$msg2', msg3='$msg3', msg4='$msg4', tmsg2='$tmsg2', tmsg3='$tmsg3', tmsg4='$tmsg4' WHERE id = '1'");
/*** echo the number of affected rows ***/
echo $count;
/*** close the database connection ***/
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
<form action='<?php $_PHP_SELF ?>' method='post' name='statusconfig' id="statusconfig">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="40%" rowspan="2" align="center" valign="top"><label>
<?
$sql="SELECT * FROM events WHERE status='show'";
$evresult=mysql_query($sql);
if(mysql_num_rows($evresult) <= 0)
{
echo "";
} else { ?>
<select name="fphoto">
<?php while($frows=mysql_fetch_array($evresult)){ ?>
<option value="<? echo $frows['photo']; ?>"><? echo $frows['Name']; ?></option>
<? } ?>
</select>
<? } ?>
</label>
<br />
<textarea name="fdescription" class="text" cols="30" rows="5"><? echo $rows['msg1']; ?></textarea></td>
<td width="5%" rowspan="2"> </td>
<td width="90%" valign="top"><input name="title" type="text" value="<? echo $rows['title']; ?>" size="50" /></td>
<td width="5%" rowspan="2"></td>
</tr>
<tr>
<td valign="top"><textarea name="news" class="text" cols="65" rows="20"><? echo $rows['news']; ?></textarea>
<br /></td>
</tr>
<tr>
<td colspan="4" valign="top"> </td>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td align="center"><div id="tray">
<div class="redbox first">
<input name="tmsg2" type="text" value="<? echo $rows['tmsg2']; ?>" />
<br />
<img src="../images/people.jpg" width="216" height="109" alt="Night Party" /></h2>
<p class="style1">
<textarea name="msg2" class="text" cols="24" rows="9"><? echo $rows['msg2']; ?></textarea>
</p>
</div>
</div></td>
<td> </td>
<td align="center"><div id="tray">
<div class="redbox first">
<input name="tmsg3" type="text" value="<? echo $rows['tmsg3']; ?>" />
<br />
<a href="hotel.php"><img src="../images/room.jpg" width="216" height="109" border="0"></a></h2>
<p class="style1">
<textarea name="msg3" class="text" cols="24" rows="9"><? echo $rows['msg3']; ?></textarea>
</p>
<br/>
</div>
</div></td>
<td> </td>
<td align="center"><div id="tray">
<div class="redbox first">
<input name="tmsg4" type="text" value="<? echo $rows['tmsg4']; ?>" />
<br />
<a href="celebrate.php" ><img src="../images/wedding.jpg" width="216" height="109" border="0"></a>
<p class="style1">
<textarea name="msg4" class="text" cols="24" rows="9"><? echo $rows['msg4']; ?></textarea>
<br/>
</p>
</div>
</div></td>
</tr><tr><td colspan="5" align="center" valign="bottom"><input type='hidden' name='do' value='save' />
<input name="update" type='submit' value='Update' />
<input name="reset" type='reset' value='Undo Changes' />
</td>
</tr>
</table>
</form>
<?php
include '../inc/inc-footer.php' ?>