Jump to content

deadendstreet

New Members
  • Posts

    7
  • Joined

  • Last visited

deadendstreet's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello I'm trying to make my php more secure with PDO. Below is the sample code I have for the "view" page. It works except for two things. 1. It only echo's one of the submissions in the database (there are currently 7). 2. I'd rather post the information in a table. before I updated it, I had something echo "<h2>" . $row['program'] . "</h2>"; and so one. But I when I try to do something similar here, it screws it up. Here's my PHP any ideas? <?php /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'waldro'; /*** mysql password ***/ $password = '123456'; try { $dbh = new PDO("mysql:host=$hostname;dbname=teamcontent", $username, $password); /*** echo a message saying we have connected ***/ echo 'Connected to database<br />'; /*** The SQL SELECT statement ***/ $sql = "SELECT * FROM calendar ORDER BY airdate"; /*** fetch into an PDOStatement object ***/ $stmt = $dbh->query($sql); /*** echo number of columns ***/ $result = $stmt->fetch(PDO::FETCH_ASSOC); /*** loop over the object directly ***/ foreach($result as $key=>$val) { echo $key.' - '.$val.'<br />'; } /*** close the database connection ***/ $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); }
  2. Nope, that's the code. The tutorial I found showed that to be the only code (in that file). Let me ask this, do you know of a good PDO tutorial that you'd recommend? The ones I've found have been somewhat confusing...granted, I've been under the weather for the past week. Thanks for your help.
  3. So I figured out the form issues I was having (basically, I'm allowing users to add/edit information to a database). It's been working great. Then I did some reading on PDO's. The first step I did was update my db-connect.php code.Now I get a Access denied for user 'user'@'localhost' (using password: NO) error message. Thinking I typed something wrong, I literally copied and pasted the database name, etc. from the earlier version of the file., but it still doesn't work. What would be causing this? I literally followed step-by-step directions from a website I found and in the comments section everyone said it was working. <?php $host = 'localhost'; $dbname = 'name'; $user = 'user'; $pass = 'pass'; try { $DB = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); } catch(PDOException $e) { echo $e->getMessage(); } ?>
  4. I have error reporting turned on in my init file using error_reporting( E_ALL & ~E_NOTICE). I've had issues with another page that I was able to figure out thanks to this. The links appear to be correct. It's the full length that's in the code plus the program name. Before I posted, it was going to a wrong link....in that instance, it was bring up my 404 error page. I made the corrections and now the page is just blank. I'm going to values seem to be correct (I've copied a lot from the add form I created and that works fine. I'll go back and check to make sure.
  5. Hello all, I'm trying to allow users who have logged in to be able to update information that's in a database. On the display page, the user can select "edit" and it should take them to a page where they can edit the information set for the program. Here's the display page" <?php require_once("db_connx.php"); $result = mysql_query("SELECT * FROM `Content_Calendar` ORDER BY Program") or die($myQuery."<br/><br/>".mysql_error()); while($row = mysql_fetch_array($result)){ $program = $row['Program']; echo "<h2>" . $row['Program'] . "</h2>"; echo "<p>" . $row['Description'] . "</p>"; echo "<p><strong> On-Air: </strong>" .$row['Production'] . "<br />"; echo "<p> <strong>Promotion: </strong> " .$row['Promotion'] . "<br />"; echo "<p><strong> Online: </strong>" .$row['Web'] . "<br />"; echo "<p><strong> In the Community: </strong>" .$row['Community'] . "<br />"; echo "<a href=\"edit_record_form.php?idi={$program}\">Edit> </a>"; } require_once("db_connx_close.php"); ?> It appears to take them to the right link. Problem is, it's not display any information at all. Here's the code I have for that: <?php require_once("db_connx.php"); $program = $_GET['program']; $sql_rec = “Select * from Content_Calendar where program = “.$program.””; $row=$mysql_fetch_array($result); $program= $row[‘program’]; $air_date = $row[‘air_date']; $description = $row[‘description’]; $production = $row[‘production']; $promotion = $row[‘promotions’]; $community = $row[‘community']; $web = $row[‘web’]; $row = ‘’; ?> <html> <head> <title>Update Program Form</title> </head> <body> <form method=”post” action=”update_record.php”> Program : <br/> <input type=”text” name=”name” value=”<?php echo “’. $program.’”;?>”> Air Date<br/> <input type=”text” name=”name” value=”<?php echo “’. $air_date.’”;?>”> Description: <br /> <textarea name=”description”><?php echo “’. $description.’”;?> </textarea> On-Air: <br /> <textarea name=”description”><?php echo “’. $production.’”;?> </textarea> Promotion: <br /> <textarea name=”description”><?php echo “’. $promotion.’”;?> </textarea> Community: <br /> <textarea name=”description”><?php echo “’. $community.’”;?> </textarea> Web: <br /> <textarea name=”description”><?php echo “’. $web.’”;?> </textarea> <input type=”submit” value=”Submit Record” > </form> Any ideas on why this isn't working?
  6. Yup, that worked. Thanks guys, I knew it would be something simple.
  7. Hello, I'm trying to post this form information to a database I created. However, when I hit submit, it takes me to the right page, but the page is blank. I go check the database and nothing has posted. I'm not getting an error message or anything. Thoughts? <form name="Add" id="Add" method="post" action="programadd.php"> <p>Program Name: <input name="program" type="text" id="program" /> </p> <p>Air Date <input name="air date" type="text" id="airdate" /> </p> <p>Description <input name="description" type="text" id="description" /> </p> <p>Production <input name="production" type="text" id="production" /> </p> <p>Promotions <input name="promotion" type="text" id="promotion" /> </p> <p>Community <input name="community" type="text" id="community" /> </p> <p>Web <input name="web" type="text" id="web" /> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> Here's the program add page <?php require_once("db_connx.php"); $program = $_POST['Program']; $air_date = $_POST['Air_Date']; $description = $_POST['Description']; $production = $_POST['Production']; $promotion = $_POST['Promotions']; $community = $_POST['Community']; $web = $_POST['Web']; f (mysql_query ("INSERT INTO Content_Calendar(Program, `Air_Date`, Description, Production, Community, Promotion, Web) VALUES ('$program', '$air_date', '$description','$production', '$promotion', '$community', '$web')")) { echo "Program successfully added to the database <br />"; } else { die(mysql_error()); } require_once("db_connx_close.php"); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.