Nimbuz
Members-
Posts
30 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
Nimbuz's Achievements
Newbie (1/5)
0
Reputation
-
This code: $(".selector").each(function (i) { var capacity = Math.round($(this).text().replace(/\,/,"")); $(this).width(capacity); }).fadeIn(2000); ..returns width in px, how can I modify it to use percentage? Thanks
-
Figured it. All done. :-) Thanks for everything. :-)
-
ah, I was looking at the line mentioned, not above it. Thanks for the tip. So it was a semicolon and it did fix the error, but, the record doesn't update although there are no errors.
-
Great, Now I see how its done. On clicking edit, input fields are populated with the data of that row and the button changes to "Update Event". However, on clicking that button, it takes me to insert.php which shows this error: Parse error: syntax error, unexpected T_VARIABLE in /Volumes/disk2/Work/www/php/insert.php on line 5 insert.php contains: <?php include("hightrek_mysql.php") // mysql_select_db("hightrek", $connection); $eventName = mysql_real_escape_string($_POST['event_name']); $eventLocation = mysql_real_escape_string($_POST['event_location']); $eventDate = date('Y-m-d H:i:s', strtotime($_POST['event_date']) ); // FORMAT: 05/30/09 1:35 am if(isset($_POST['create_event'])) { // Insert Values in a Row $insert_sql = "INSERT INTO events (eventName, eventLocation, eventDate) VALUES ('$eventName', '$eventLocation', '$eventDate')"; $result = mysql_query($insert_sql, $connection) or die("Row insert failed: " . mysql_error()); // If (or not) successful... if(mysql_affected_rows() > 0) { echo "1 record added"; } } ?> <a href="viewEvents.php">Return to previous page</a> <?php // Close Connection mysql_close($connection); ?>
-
This the viewEvents.php now: <?php include("hightrek_mysql.php") ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>View Events</title> </head> <script type="text/javascript"> function confirmDelete() { if(confirm("Are you sure you want to delete this event?")) { return true; } else { return false; } } </script> <body> <form action="insert.php" method="POST"> <fieldset> <legend>Create a Row</legend> <label>Event Name:</label> <input type="text" name="event_name" <?php getEdit('event_name'); ?> /> <br /> <label>Event Location:</label> <input type="text" name="event_location" <?php getEdit('event_location'); ?> /> <br /> <label>Event Date:</label> <input type="text" name="event_date" <?php getEdit('event_date'); ?> /> <br /> <?php if(isset($_GET['action']) && $_GET['action'] == 'edit') { echo '<input type="submit" name="update_event" value="Update Event" />'; } else { echo '<input type="submit" name="create_event" value="Create Event" />'; } if(isset($_GET['id'])){ echo '<input type="hidden" name="eventId" value="'.$_GET['id'].'" />'; } ?> </fieldset> </form><br /> <?php // DELETING A RECORD if(isset($_GET['action']) && isset($_GET['eventId']) && $_GET['action'] == 'delete') { // initiate connection to DB $eventID = mysql_real_escape_string($_GET['eventId']); // sanitize the data $deleteQuery = "DELETE FROM events WHERE eventId = '$eventID'"; $result = mysql_query($deleteQuery); if (mysql_affected_rows() > 0){ echo "Row Deleted."; } } // CREATING A RECORD if(isset($_POST['create_event'])) { $insert_sql = "INSERT INTO events (eventName, eventLocation, eventDate) VALUES ('$eventName', '$eventLocation', '$eventDate')"; $result = mysql_query($insert_sql, $connection) or die("Row insert failed: " . mysql_error()); if(mysql_affected_rows() > 0) { echo "1 record added"; } } // EDITING A RECORD if(isset($_GET['action']) && $_GET['action'] && isset($_GET['id'])) { $id = $_GET['id']; $query = "SELECT * FROM events WHERE eventId = '$id'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $edit['event_name'] = $row['eventName']; $edit['event_location'] = $row['eventLocation']; $edit['event_date'] = $row['eventDate']; } } // Function for filling the attributes... function getEdit($fieldName){ global $edit; // set this to global so $edit is available inside this function. if(isset($edit[$fieldName])) { echo 'value="'.$edit[$fieldName].'"'; } } ?> <table cellspacing="5" cellpadding="5" border="1"> <?php $result = mysql_query("SELECT * FROM events", $connection); if (!$result) { die("Database query failed: " . mysql_error()); } $x = 1; while ($row = mysql_fetch_array($result)) { echo '<tr><td>'. $x++ .'</td><td>'. $row["eventName"].'</td><td>'. $row["eventLocation"].'</td><td>'. $row["eventDate"].'</td></td>'. '<td>'. '<a href="edit.php?action=edit&eventId='.$row['eventId'].'">Edit</a> / '. '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&eventId='. $row['eventId']. '"onclick="return confirmDelete()">Delete</a>'. '</td></tr>'; } ?> </table> </body> </html> <?php // Close Connection mysql_close($connection); ?> but the vars don't appear in the url (eg. http://localhost/php/edit.php?action=edit&eventId=30) and the "undefined variable" errors still show up.
-
A separate display page is probably not required if we're displaying it on edit (currently viewEvents.php) page because the list is not for public. So only two things remain now: 1. Ability to edit records. 2. User Authentication. (I think I can try it myself, seems easy.) and these are what the pages look like: viewEvents.php <?php include("hightrek_mysql.php") ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>View Events</title> </head> <script type="text/javascript"> function confirmDelete() { if(confirm("Are you sure you want to delete this event?")) { return true; } else { return false; } } </script> <body> <form action="insert.php" method="POST"> <fieldset> <legend>Create a Row</legend> <label>Event Name:</label> <input type="text" name="event_name" /> <br /> <label>Event Location:</label> <input type="text" name="event_location" /> <br /> <label>Event Date:</label> <input type="text" name="event_date" /> <br /> <?php if(isset($_GET['action']) && $_GET['action'] == 'edit') { echo '<input type="submit" name="update_event" value="Update Event" />'; } else { echo '<input type="submit" name="create_event" value="Create Event" />'; } ?> </fieldset> </form><br /> <?php // DELETING A RECORD if(isset($_GET['action']) && isset($_GET['eventId']) && $_GET['action'] == 'delete') { // initiate connection to DB $eventID = mysql_real_escape_string($_GET['eventId']); // sanitize the data $deleteQuery = "DELETE FROM events WHERE eventId = '$eventID'"; $result = mysql_query($deleteQuery); if (mysql_affected_rows() > 0){ echo "Row Deleted."; } } // CREATING A RECORD if(isset($_POST['create_event'])) { $insert_sql = "INSERT INTO events (eventName, eventLocation, eventDate) VALUES ('$eventName', '$eventLocation', '$eventDate')"; $result = mysql_query($insert_sql, $connection) or die("Row insert failed: " . mysql_error()); if(mysql_affected_rows() > 0) { echo "1 record added"; } } ?> <table cellspacing="5" cellpadding="5" border="1"> <?php $result = mysql_query("SELECT * FROM events", $connection); if (!$result) { die("Database query failed: " . mysql_error()); } $x = 1; while ($row = mysql_fetch_array($result)) { echo '<tr><td>'. $x++ .'</td><td>'. $row["eventName"].'</td><td>'. $row["eventLocation"].'</td><td>'. $row["eventDate"].'</td></td>'. '<td>'. '<a href="edit.php?action=edit&eventId='.$row['eventId'].'">Edit</a> / '. '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&eventId='. $row['eventId']. '"onclick="return confirmDelete()">Delete</a>'. '</td></tr>'; } ?> </table> </body> </html> <?php // Close Connection mysql_close($connection); ?> and insert.php <?php include("hightrek_mysql.php") mysql_select_db("hightrek", $connection); $eventName = mysql_real_escape_string($_POST['event_name']); $eventLocation = mysql_real_escape_string($_POST['event_location']); $eventDate = date('Y-m-d H:i:s', strtotime($_POST['event_date']) ); // FORMAT: 05/30/09 1:35 am if(isset($_POST['create_event'])) { // Insert Values in a Row $insert_sql = "INSERT INTO events (eventName, eventLocation, eventDate) VALUES ('$eventName', '$eventLocation', '$eventDate')"; $result = mysql_query($insert_sql, $connection) or die("Row insert failed: " . mysql_error()); // If (or not) successful... if(mysql_affected_rows() > 0) { echo "1 record added"; } } ?> <a href="viewEvents.php">Return to previous page</a> <?php // Close Connection mysql_close($connection); ?>
-
Great, the other error is gone, but I think what the "undefined variable" says is that php has no new data to update the table because I reach this page (edit.php) by simply clicking on "edit" link on viewevents. To enter new data, do I need a new form on edit.php?
-
For displaying ID (serial #), I'm using this: $x = 1; while ($row = mysql_fetch_array($result)) { echo '<tr><td>'. $x++ .'</td><td>'. $row["eventName"].'</td><td>'. $row["eventLocation"].'</td><td>'. $row["eventDate"].'</td></td>'. '<td>'. '<a href="edit.php?action=edit&eventId='.$row['eventId'].'">Edit</a> / '. '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&eventId='. $row['eventId'].'">Delete</a>'. '</td></tr>'; } is there an elegant solution?
-
edit.php now contains this codeblock: if(isset($_GET['action']) && isset($_GET['eventId']) && $_GET['action'] == 'edit') { $update_sql = mysql_query("UPDATE events SET eventName = '$eventName' , eventLocation = '$eventLocation', eventDate = '$eventDate' where eventId = '$eventId' "); $result = mysql_query($update_sql, $connection) or die("Row update failed: " . mysql_error()); } else { echo "Update Failed!"; } and php displays this error: Notice: Undefined variable: eventName in /Volumes/disk2/Work/www/php/edit.php on line 10 Notice: Undefined variable: eventLocation in /Volumes/disk2/Work/www/php/edit.php on line 11 Notice: Undefined variable: eventDate in /Volumes/disk2/Work/www/php/edit.php on line 12 Notice: Undefined variable: eventId in /Volumes/disk2/Work/www/php/edit.php on line 12 Row update failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 Should i have the same form on edit.php?
-
EDIT: Sorry, delete worked. I'd forgotten to place the following code in viewEvents.php if(isset($_GET['action']) && isset($_GET['eventId']) && $_GET['action'] == 'delete') { // initiate connection to DB $eventID = mysql_real_escape_string($_GET['eventId']); // sanitize the data $deleteQuery = "DELETE FROM events WHERE eventId = '$eventID'"; $result = mysql_query($deleteQuery); if (mysql_affected_rows() > 0){ echo "Deleted Row"; } } ?>
-
Yes, I prefer your (Nate) method as well. sprintf makes it difficult to read. There was a syntax error - an extra semicolor after $_SERVER['PHP_SELF']; - fixed it it now displays the page fine. So now "Delete" should alteast work but it isn't working.
-
Thanks for the great tip. But, ahem, I still can't get myself past the syntax errors, please check: while ($row = mysql_fetch_array($result)) { echo "<tr><td>" .$row["eventId"]."</td><td>" .$row["eventName"]."</td><td>" .$row["eventLocation"]."</td><td>" .$row["eventDate"]."</td></td>" ."<td>" .'<a href="edit_event.php?action=edit&eventId='.echo $row['eventId'];.'">Edit Event</a>' .'<a href="'.$_SERVER['PHP_SELF'];.'?action=delete&eventId='.echo $row['eventId'];.'">Delete Event</a>' ."</td></tr>" ; } error is: Parse error: syntax error, unexpected T_ECHO in /Volumes/disk2/Work/www/php/viewEvents.php on line 49 Thanks!
-
So I replaced my static html button with this code block in viewEvents.php: <?php if(isset($_GET['action']) && $_GET['action'] == 'edit') { echo "<input type=\"submit\" name=\"update_event\" value=\"Update Event\" />"; } else { echo "<input type=\"submit\" name=\"create_event\" value=\"Create Event\" />"; } ?> .but I don't understand where to place those edit/delete links. Should it be within the while loop so they're displayed on each row? Thanks
-
I added the code block for updating the row: <?php // DB Connection $connection = mysql_connect("localhost","root","mypass"); if (!$connection) { die("Database connection failed: " . mysql_error()); } // Select DB mysql_select_db("hightrek", $connection); // sanitize the data to protect against injection attacks $eventName = mysql_real_escape_string($_POST['event_name']); $eventLocation = mysql_real_escape_string($_POST['event_location']); // we take what was entered in the date field, and run it through strtotime() (string to time) which gives a unix timestamp // then we run it through the date function and put it in the format we need for mysql. $eventDate = date('Y-m-d H:i:s', strtotime($_POST['event_date']) ); // FORMAT: 05/30/09 1:35 am // CODE BLOCK if(isset($_POST['create_event'])) { // Insert Values in a Row $insert_sql = "INSERT INTO events (eventName, eventLocation, eventDate) VALUES ('$eventName', '$eventLocation', '$eventDate')"; $result = mysql_query($insert_sql, $connection) or die("Row insert failed: " . mysql_error()) // If (or not) successful... if(mysql_affected_rows() > 0) { echo "1 record added"; } } else { // the form has not been submitted yet.. no need to do anything here } /* * UPDATING A ROW */ if(isset($_POST['update_event'])) { $update_sql = mysql_query("UPDATE events SET eventName = '$eventName' , eventLocation = '$eventLocation', eventDate = '$eventDate' where eventId = '$eventId' "); $result = mysql_query($update_sql, $connection) or die("Row update failed: " . mysql_error()); } else { echo "Update Failed!"; } ?> <a href="viewEvents.php">Return to previous page</a> <?php // Close Connection mysql_close($connection); ?> ...and it doesn't work, ofcourse. :-) Can you please check?
-
I guess updating the fields could be done using: UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value but not sure how to implement that. Create an Update button next to the submit button and a new code block for it on insert.php?