
MjM8082
Members-
Posts
92 -
Joined
-
Last visited
Never
Everything posted by MjM8082
-
What exactly does mysql_real_escape_string do? And please give examples not just what it is. Thanks
-
I didn't need like basically anything you guys mentioned... I got it working with this code... include "connect_to_mysql.php"; if (isset($_POST['submit'])) { $title = $_POST['title']; $content = $_POST['content']; $post_id = $_GET['post_id']; $sql = "UPDATE posts SET title ='". $title ."', content ='". $content ."'WHERE post_id = $post_id"; mysql_query($sql); I was just looking for basic code like this from the start, you guys made it seem so confusing when it was just missing a few "" here and there.
-
Here is my code exactly how it looks in my program. <form action="" method="post"> Title<input type="text" name="title" value="<?php echo $row['title']; ?>" /><br/></br> Content</br><textarea name="content" cols="50" rows="10"><?php echo $row['content']; ?></textarea><br/> <input type="hidden" name="post_id" value="<?php $_GET['post_id'] ?>" /> <input type="submit" name="submit" value="Edit" /> <input type="button" value="Back" ONCLICK="window.location.href='edit_post.php'"/> </form> </font> </p> <?php include "connect_to_mysql.php"; if (isset($_POST['submit'])) { $post_id = isset($_POST['post_id']) $_POST['post_id'] : ''; $title = isset($_POST['title']) mysql_real_escape_string($_POST['title']) : ''; $content = isset($_POST['content']) mysql_real_escape_string($_POST['content']) : ''; if ( $post_id > 0 ){ $sql = ("UPDATE posts SET title='$title', content='$content' WHERE post_id = $post_id"); mysql_query($sql); echo 'Post has been updated!</a><br /></br>'; } ?>
-
Just wondering what the best program is for coding. I use Notepad++ What do you use ones are the best?
-
I've been messing around with the things you mentioned but I seem to still be getting a error because nothing is changing in the database when I hit update.
-
I got the text box problem to work.. I'm working on my update statement now. Here is my code <form action="" method="post"> Title<input type="text" name="title" value="<?php echo $row['title']; ?>" /><br/></br> Content</br><textarea name="content" cols="50" rows="10"><?php echo $row['content']; ?></textarea><br/> <input type="hidden" name="post_id" value="<?php $post_id; ?>" /> <input type="submit" name="submit" value="Edit" /> </form> </font> </p> <?php if (isset($_POST['submit'])) { $post_id = (int)$_GET['post_id']; $sql = ("UPDATE posts SET 'title'='$_POST[title]', content='$_POST[content]' WHERE post_id = '$post_id'"); echo 'Post has been updated!</a><br /></br>'; } ?> Having trouble getting it to work. Is the update statement similar to a INSERT statement?
-
Okay I will make those changes. Right now I'm not worrying about it updating in the database, first I just want to information to display into and fill the form from the database.
-
When I click on the post I want to update it brings me to the next page to a blank form. I'm trying to make it so the form has all the information from the database in it so the user and change it and then click update. For some reason my form just keeps showing up blank and wont display the database data. Here is the update page that includes the form... <?php include "connect_to_mysql.php"; if (!isset($_POST['submit'])) { $post_id = (int)$_GET['post_id']; $sql = mysql_query ("SELECT * FROM posts WHERE post_id = '$post_id'"); $results = mysql_query($sql); $row = mysql_fetch_array($results); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Title<input type="text" name="title" value="<?php echo $row['title']; ?>" /><br/> Content<input type="text" name="content" value="<?php echo $row['content']; ?>" /><br/> <input type="hidden" name="id" value="<?php $post_id; ?>" /> <input type="submit" name="submit" value="Edit" /> </form> </font>
-
Hey thanks man, so would this work the same way if I wanted to delete the title of the post from the database instead of the entire row?
-
I created a blog and what I am trying to delete a post when I click the delete button underneath the post. I have messed around with this for a while and can't seem to figure out why it is not working. Here is my code on the post page... include "connect_to_mysql.php"; $sql = "SELECT * FROM posts ORDER BY time_posted DESC"; $results = mysql_query($sql); while($row = mysql_fetch_array($results)) { echo "</br>"; echo "</br>"; echo $row['title'] ."</br>"; echo $row['date_posted'] . "<br />"; echo $row['time_posted'] ."</br></br>"; echo $row['content'] . "<br /></br>"; echo "<a href=\"delete_post.php?post_id=" . $row['post_id'] . "\">Delete</a>"; Here is my delete_post page. include "connect_to_mysql.php"; // SQL query $sql = mysql_query ("DELETE FROM posts WHERE post_id = '$post_id'"); echo 'Post has been deleted! </br></br>Go to blog home!<a href="index.php">Click Here</a><br /></br>'; Just so you know post_id is the name of the id's in the database.. so I know my names are not wrong.
-
Notice: Undefined index: title in /home6/projeev1/public_html/maddykelley/blankpage.php on line 18 Notice: Undefined index: content in /home6/projeev1/public_html/maddykelley/blankpage.php on line 19 These are the errors I am getting
-
Sorry, I am new to PHP and trying out my first time with phpmyadmin and mysql, so this is one of my first select statements, so I'm just trying to work with the knowledge I have right now.
-
Okay I tried the new code you posted and now I just get a blank page :-\
-
Thanks for the reply, after trying that code I still came out with the same output ... $title "; } ?> That is all that appears on the page
-
Sorry, to be more specific my output just gives me this.... $title "; } ?> That is it. I messed around with my code multiple times and I have even tried the $sql instead of $query.
-
I'm trying to pull information out of my database and display it on my index.php page for my site. I know it is not my connection because my insert statement works just fine... not sure what the problem might be? Here is a look at my php code. include "connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM posts WHERE title='$title' AND content='$content'"); $result = mysql_query ($query); while ($row = mysql_fetch_array($result)) { $title = stripslashes($row['title']); $display_block .= "<p><strong></strong> $title </p>"; }
-
<?php include "connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM posts WHERE title='$title' AND content='$content'"); $result = mysql_query ($query); while ($row = mysql_fetch_array($result)) { $title = stripslashes($row['title']); $display_block .= "<p><strong></strong> $title </p>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Johns's Blog</title> <script type="text/javascript" src="jquery.js"></script> <style type="text/css"> @import url(css.css); </style> <script type="text/javascript" src="js.js"></script> <link rel="shortcut icon" href="images/maddynavi.png" /> </head> <body> <body> <div id="logo"><center><img src="images/banner.png"/></center></div> <div id="wrapper"> <h1>John's Blog</h1> <ul id="nav"> <li><a href="index.html">blog</a></li> <li><a href="about.html">about me</a></li> <li><a href="pictures.html">pictures</a></li> <li><a href="videos.html">videos</a></li> </ul> <div id="content"> <h2><img src="images/blogblog.png"/></h2> </br> <p><?php print 'title' ?></p> </div> <div id="foot"><a href="admin_login.php">Admin</a></div> </div> </body> </html> This is all the code on the index page.
-
Alright here is my updated code that I ran... require_once ("connect_to_mysql.php"); $result = mysql_query("SELECT * FROM posts") or die("SELECT Error: ".mysql_error()); //This will tell you if there is an error with the query. while($row = mysql_fetch_array($result)) { echo $row['title'] . " " . $row['content']; echo "<br />"; } After running that I received this on the page.... "; } ?> that was it.. Not sure what the error can be, everything looks right?
-
nope still nothing appears on the screen
-
I am fairly new to php and I'm learning mysql. I'm building a blog for practice, and I managed to get the blog post to insert into the database but now I want it to display on my index.php page but I can't seem to get it to work and I dont know what I am doing wrong.... here is my code include "connect_to_mysql.php"; $result = mysql_query("SELECT * FROM posts"); while($row = mysql_fetch_array($result)) { echo $row['title'] . " " . $row['content']; echo "<br />"; }
-
On my application there is 10 math questions. What I want to do when the test is finished is for it to tell the user how many they got right out of 10. Also how to put this into the database. I have everything else working fine on this application, I just would like to further enhance it by doing this. This is the code to my application. It is a small application. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Multiplication Test</title> </head> <body> </body> <?php require_once('database.php'); session_start(); define ('ROWS', 2); define ('COLS', 5); define ('MAX_NUMBER', 12); date_default_timezone_set('America/New_York'); if (isset($_POST['btn_score'])) { $result_name= $_POST['result_name']; $correct = 0; //print_r ($_POST); $time1 = $_POST['ts']; $time1_object = new DateTime($time1); $now = new DateTime(); $time_span = $now->diff($time1_object); $minutes = $time_span->format('%i'); $seconds = $time_span->format('%s'); $seconds+= $minutes * 60; echo "It took $seconds seconds to complete the test<hr />"; foreach ($_POST as $problem => $answer) { if ($problem <> "btn_score" && $problem <> "ts" && $problem <> "result_name") { //echo "$problem -- $answer <br />"; $problem = explode('_', $problem); $num1 = $problem[2]; $num2 = $problem[3]; $right = $num1 * $num2; if ($answer != $right) { echo "$num1 * $num2 = $answer , The right answer is $right<br />"; }else { $correct = $correct + 1; } } } $result_score= 0; $result_score= ($correct / 10) * 100; echo "your score is <br/>$result_score<br/>"; } { $sql = "INSERT INTO results (result_name, result_score, result_date_time) VALUES ('$result_name','$result_score', NOW());"; $db->exec($sql); } $query = "SELECT * FROM results WHERE result_name = :result_name "; $statement = $db->prepare($query); $statement->bindValue (':result_name', $result_name); $statement->execute(); $results = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $result_name </h1>"; foreach ($results as $result) { echo $result['result_name'] . " " . $result['result_score']. " " . $result['result_date_time']; echo '<br />'; } ?> <h1>Multiplication Test</h1> <form name="lab5" method="post" action="lab5b.php"> <?php $now = new DateTime(); //echo $now->format('Y-m-d H:i:s'); echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>"; ?> <table border="1" cellspacing="5" cellpadding="5"> <?php $no_of_problems = 0; for ($row=0; $row<ROWS; $row++) { echo "<tr>"; for ($col=0; $col<COLS; $col++) { $num1 = mt_rand(1,MAX_NUMBER); $num2 = mt_rand(1,MAX_NUMBER); echo "<td>$num1 * $num2 </td>"; echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>"; $no_of_problems++; } echo "</tr>"; } $colspan = 2 * COLS; echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>"; ?> </table> <br> <br> <label for="result_name">Student Name:</label> <input type="text" id="result_name" name="result_name" /><br /> </form> <br> <br> </body> </html>
-
I want to display it underneath the table. I want it to say "Your Final Grade Is... " I'm not sure where to put the code, but I tried to put it into my code as this... if ($grade_points >= 100) { $final_grade = 'A'; } But it keeps saying grade_points is undefined
-
where exactly would I put that in my code? so that it will work properly
-
Okay so I have a table that displays grades. If the stupid has 100 for the grade points then I want a A to be displayed under the table... I think it does something like this... if grade_type >=100 $final_grade = A Idk, im new to php and need help doing this... here is my code... <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (grade_id, student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:grade_id, :student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_id', $_SESSION['grade_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_points']); $statement->execute(); $statement->closeCursor(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="delete_grade.php" method="post"> <input type="submit" name="remove" value="Delete" /> <input type="submit" name="update" value="Update" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> <html> <head> <title>Delete Grade</title> </head> <body> <form method="post" action="delete_grade.php"> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') or die(mysql_error()); //delete grades if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } echo 'grade has been deleted.<br />'; } if (isset($_POST['update'])) { foreach($_POST['update'] as $update_id) { $query = "UPDATE grades SET grade_id = $update_id"; mysqli_query($dbc, $query) or die ('can\'t update user'); } } //Display grade info with checkbox to delete $query = "SELECT * FROM grades"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '" name="delete[]" />'; echo ' ' .$row['grade_type'] .' '. $row['grade_name']; echo '<br />'; } mysqli_close($dbc); ?> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="remove" value="Remove" /> <input type="submit" name="update" value="Update" /> </form> </body> </html>
-
Thanks for the reply. I fixed that part in my code. How do I make my update statement work with my check boxes? The delete button works great with the check boxes but the update won't. Also I keep getting this error when I click the update button... "invalid argument supplied for foreach()" which is this line in my code.... foreach($_POST['update'] as $update_id)