Jump to content

surreal5335

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

surreal5335's Achievements

Member

Member (2/5)

0

Reputation

  1. I appologize, I realized I copied in the wrong function. Here is the correct one: function create_profile($params) { $connection = db_connect(); $query = sprintf("INSERT INTO profile SET first_name = '%s', last_name = '%s', born = '%s', death = '%s', interests = '%s', personality = '%s', describe = '%s', time = NOW(), profile_id = '%s'", mysql_real_escape_string($params['first_name']), mysql_real_escape_string($params['last_name']), mysql_real_escape_string($params['born']), mysql_real_escape_string($params['death']), mysql_real_escape_string($params['interests']), mysql_real_escape_string($params['personality']), mysql_real_escape_string($params['describe']), mysql_real_escape_string($params['time']), mysql_real_escape_string($params['profile_id'])); $result = mysql_query($query); if (!$result) return false; else return true; } Thanks a lot for your help
  2. I am working on a database that will submit data to it upon a button click then retreive said info and displaying in a particular format. Sounds simple, but there seems to be something I am missing in my code thats stopping it from completing its job. I am using a MVC setup and from the echos I have setup, my controller and my url array routes are working fine. It seems to come down to the calling of the function and the function itself which processes the database query is not working properly. Here is my controller: case "create_profile": if(create_profile($params['profile'])) { flash_notice('Successfully created profile!'); redirect_to(''); } else { flash_notice('Profile creation unsuccessful!'); echo "$params[post] = ".$params['post']."<br />". "$params[profile] = ".$params['profile']."<br />"; print_r($params); } my echo "$params = ".$params['post']."<br />". "$params[profile] = ".$params['profile']."<br />"; isnt producing anything significant. my print_r($params); is giving me this output upon submition. This is what I typed into the form, so something must working right. Here is my function that doing the querying and submitting into the database: function create_post($params) { $connection = db_connect(); $query = sprintf("INSERT INTO comtable SET title = '%s', name = '%s', txt = '%s', email = '%s', time = NOW(), user_id = '%s'", mysql_real_escape_string($params['title']), mysql_real_escape_string($params['name']), mysql_real_escape_string($params['txt']), mysql_real_escape_string($params['email']), mysql_real_escape_string($params['time']), mysql_real_escape_string($params['user_id'])); $result = mysql_query($query); if (!$result) return false; else return true; } I appreciate the help
  3. I am working on creating a post that will replace all carriage returns with a <br /> tag so the format the user entered will be preserved. here is the code I am using for my create_post() and the str_replace() for replacing carraige returns. $body = str_replace("\r","<br />",$_POST['txt']); /************************************************************************/ function create_post($params) { $connection = db_connect(); $body; $query = sprintf("INSERT INTO comtable SET title = '%s', name = '%s', txt = '%s', email = '%s', time = NOW(), user_id = '%s'", mysql_real_escape_string($params['title']), mysql_real_escape_string($params['name']), mysql_real_escape_string($params['txt']), mysql_real_escape_string($params['email']), mysql_real_escape_string($params['time']), mysql_real_escape_string($params['user_id'])); $result = mysql_query($query); if (!$result) return false; else return true; } here is my post page for displaying the database results: <?php include_once('model/post.php'); ?> <table width="400" border="1"> <tr> <td> <h2><?php echo $post['title']; ?></h2> </td> </tr> <tr> <td> name: <?php echo '<a href="'.$post['email'].'">'.$post['name'].'</a>'; ?> <!--date created: <?php echo $hr.':'.$min.' '.$timetype.' '. $mo.'/'.$da.'/'.$yr; ?>--> post id: <?php echo $post['post_id']; ?> </td> </tr> <tr> <td> comment: <br/> <?php echo $body; ?> </td> </tr> </table> The file included is the one containing the create_post() and $body. It seems to me right now I am not getting any database data in $body, just the function to replace the returns with <br />. The form that is getting this data and the returns from the user is below: <textarea cols="40" name="post[txt]" rows="5"></textarea> obviously there is more, but this is the relvent part. The method of the form is set to "post" I appreciate the help
  4. I have a comment board that is nearly completed although right now when you submit a new comment, the form action is done right but stays on the new page without calling the create_post() I created. The function does work, I have seen it work recently but while trying to get a page redirect from the called page back to the main page with all posts I was not able to get create_post() working again (I have not made any changes to create_post() ). Here is the code for the form and where the action takes you to: <form action = "<?php echo DS.APP_ROOT.DS;?>views/posts/create.php" method="post"> <?php include('_form.php'); ?> </form> Here is the code for the page the form takes the user to (I expect this not to do anything valuable): <?php print_r($params); ?> This is the controller end that is suppose to call create_post() and hopefully execute the redirect back to the main page (this is my problem child): switch($route['view']) { case "create": if(create_post($params['post'])) { flash_notice('Successfully created post!'); redirect_to('posts'); } header( 'Location: http://www.royalvillicus.com/comment_board/' ) ; break; } This all worked at one point w/out the redirect. While trying to get the redirect to work, this stopped getting called. I did put an HTML redirect into my create.php file (the one with the print_r() ), the redirect worked but nothing got submitted to the database. I am an array for the url routes in my config file. The one that helps determine which case: to execute in my controller. Here is the code for my 'create' url route. 'url' => '/^posts\/create$/', 'controller' => 'posts', 'view' => 'create'), To see what I am talking about, here is my site url: http://royalvillicus.com/comment_board/ Thanks a lot for the help
  5. Thanks a lot for the info, that solved the problem.
  6. I am working on a database that sends off user entered info to a databse upon submit of the form. The problem is when this occurs preg_match() is getting weird results for its two separate string to match for a proper url route while going to a new page. I have figured out what the weird behavior is: the $route['url'] is just picking the url route that appears at the end of the array. I have no idea how to fix this. Currently no info is being submitted to the database. My site: http://royalvillicus.com/comment_board/ once the data is submitted I am left with this feedback: $route['url'] = /^\/(?P\d+)\/delete$/ $url = posts/create no route found $route['url'] and $url are the two strings being checked for a match. This check is being done with this code: // routes for all the controllers $routes = array( array('url' => '/^\/(?P<id>\d+)$/', 'controller' => 'posts', 'view' => 'show'), array('url' => '/^\/(?P<id>\d+)\/edit$/', 'controller' => 'posts', 'view' => 'edit'), array('url' => '/^\/new$/', 'controller' => 'posts', 'view' => 'new'), array('url' => '/^\/create$/', 'controller' => 'posts', 'view' => 'create'), array('url' => '/^\/?$/', 'controller' => 'posts', 'view' => 'index'), //array('url' => '/^\/(?P<id>\d+)\/update$/', 'controller' => 'posts', 'view' => 'update'), //array('url' => '/^\/(?P<id>\d+)\/delete$/', 'controller' => 'posts', 'view' => 'delete') ); /** * Return array of $_GET and $_POST data * @return array **/ function parse_params() { $params = array(); if(!empty($_POST)) $params = array_merge($params, $_POST); if(!empty($_GET)) $params = array_merge($params, $_GET); return $params; } function dispatcher($routes) { // $_SERVER['REQUEST_URI'] gets the URL typed in by the user $url = $_SERVER['REQUEST_URI']; // Removes Application root from URL $url = str_replace(DS.APP_ROOT.DS,'',$url); //Holds the Named Captures, $_POST Data $params = parse_params(); // $_SERVER['QUERY_STRING'] - string in the url used to access the current page $url = str_replace('?'.$_SERVER['QUERY_STRING'], '', $url); //Becomes true if $route['url'] matches $url $route_match = false; // loops over $routes looking for a match foreach($routes as $urls => $route) { // sets $route_match to true // exits loop after match found if(preg_match($route['url'],$url,$matches)) { // if match found appends $matches to $params $params = array_merge($params, $matches); $route_match = true; break; } } // if no route matched display error if (!$route_match) { echo "\$route['url'] = ".$route['url']."<br />"; echo "\$url = ".$url."<br />"; exit('no route found');} include CONTROLLER_PATH.$route['controller'].'.php'; if(file_exists(VIEW_PATH.'layout'.DS.$route['controller'].'.php')) include VIEW_PATH.'layout'.DS.$route['controller'].'.php'; else include VIEW_PATH.'layout'.DS.'application.php'; // reset flashs back to empty $_SESSION['flash']['notice'] = ''; $_SESSION['flash']['warning'] = ''; } I have no idea why its doing this or know where to go in order to fix it. I appreciate the help
  7. I am working on a database that sends off user entered info to a databse upon submit of the form. The problem is when this occurs preg_match() is getting weird results for its two separate string to match for a proper url route while going to a new page. Currently no info is being submitted to the database. My site: http://royalvillicus.com/comment_board/ once the data is submitted I am left with this feedback: $route['url'] = /^\/(?P\d+)\/delete$/ $url = posts/create no route found $route['url'] and $url are the two strings being checked for a match. This check is being done with this code: function dispatcher($routes) { // $_SERVER['REQUEST_URI'] gets the URL typed in by the user $url = $_SERVER['REQUEST_URI']; // Removes Application root from URL $url = str_replace(DS.APP_ROOT.DS,'',$url); //Holds the Named Captures, $_POST Data $params = parse_params(); // $_SERVER['QUERY_STRING'] - string in the url used to access the current page $url = str_replace('?'.$_SERVER['QUERY_STRING'], '', $url); //Becomes true if $route['url'] matches $url $route_match = false; // loops over $routes looking for a match foreach($routes as $urls => $route) { // sets $route_match to true // exits loop after match found if(preg_match($route['url'],$url,$matches)) { // if match found appends $matches to $params $params = array_merge($params, $matches); $route_match = true; break; } } When the data is submited from the form it links to action = "<?php echo DS.APP_ROOT.DS;?>posts/create" (DS.APP_ROOT.DS gets replaced with nothing using str_replace()) So this would explain $url being equal to "posts/create". My real problem is trying to figure out where $route['url'] got the "/^\/(?P\d+)\/delete$/" from. I realize it came from with in the array bc it is an option, but how did it get refered to that one? There is a lot of code involved in this, so I am going to stop here to see what suggestions you may have as to how to diagnose the problem.
  8. I am working on displaying some posts created by a user, grabing from a database, then looping through fields in the database displaying all the entries created in the table. My problem is the file that holds the html output with the php code used to plug in the variables during the loop. here is the error I am getting: I have seen this type before, and find them usually easy to fix, but this time, I have tried everything and the error doesnt change. Its now refering to a blank line with no code what so ever! Here is the file that running the loop from the database: <?php ini_set('display_errors',1); error_reporting(E_ALL); include_once('com_db_fns.php'); db_connect(); /** Gathers data from database and processes time stamp * @return resource */ $result = mysql_query("SELECT * FROM comtable ORDER BY post_id DESC"); if (!$result) { echo("Error performing query: " . mysql_error() ); exit(); } // end $result error check while ($row = mysql_fetch_array($result) ) { $msgTxt = $row["txt"]; $msgId = $row["post_id"]; $SigName = $row["name"]; $SigDate = $row["time"]; $msgTitle = $row["title"]; $url = $row["email"]; // divides data taken from TIMEDATE stamp field 'time' into separate variables $yr = substr($SigDate, 2, 2); $mo = substr($SigDate, 4, 2); $da = substr($SigDate, 6, 2); $hr = substr($SigDate, 8, 2); $min = substr($SigDate, 10, 2); // converts military time (TIMEDATE default format) over to conventional time format if ($hr > "11") { $x = "12"; $timetype = "PM"; $hr = $hr - 12; }else{ $timetype = "AM"; } // if user leaves email blank in form, email field $url takes a value of # if (!$url) { $url = "#"; }else{ $stat = $url; $url = "mailto:" . $url . ""; } // displays the data taken from the field include_once('_view.php'); } // end while loop ?> here is _view.php before I started gutting the php code to try and narrow down the problem: the error refers to this line: date created: <?php echo $hr.':'.$min $timetype; ?> <table width="400" border="1"> <tr> <td> <h2><?php echo $msgTitle; ?></h2> </td> </tr> <tr> <td> name: <?php echo '<a href="'.$url.'">'.$SigName.'</a>'; ?> date created: <?php echo $hr.':'.$min $timetype; ?> post id: <?php echo $msgId; ?> </td> </tr> <tr> <td> comment: </br> <?php echo $msgTxt; ?> </td> </tr> </table> The file is connecting to the database fine and as you can see I have error reporting set to all, but I am not getting any extra info from it. I hope you have some idea as to what is going on
  9. Thanks for the suggestions, I checked the path for $img and it came out fine. My $original I have not been able to get a reponse back if its true or false. here is the methods I have tried to achieve this: if(!$original) { echo "original is false"; } else { echo "original is true"; } if($original == false) { echo "original is false"; } else { echo "original is true"; } echo imagecreatefromjpeg($img); I put these inside my small() function so the local variable $original would be accessible. Any suggestions?
  10. Thanks alot for the help, got rid of the error. My last problem is... while the cropped canvas appears in the folder specified, its completely black. Seems that I am not getting the image from the folder or setting it to the canvas properly. Mind giving me an idea as to how I could remedy this issue? Thanks a lot Ben
  11. I am trying to crop an image and I used a tutorial showing how to create a new canvas, shrink it 75 by 75, shrink the original image's copy to 1/4 of its size. Then take a cut out of it (75 by 75) out of the center. function small($id) { // original image location $img = "photos/original/".$id.".jpeg"; // set our image canvas $canvas_width = 75; $canvas_height = 75; // create a blank canvas $canvas = imagecreatetruecolor($canvas_width, $canvas_height); // get width and height of original image list($img_width, $img_height) = getimagesize($img); // $original now holds the image in the memory banks $original = imagecreatefromjpeg($img); // copy original onto canvas // 0, 0: sets the x and y position at top left hand corner of $original // (($canvas_width / 2) * 4)) the * 4 is used to balance the $image_width / 4 to keep the crop in the center imagecopyresampled($canvas, $orignal, 0, 0, (($img_width / 2) - (($canvas_width / 2) * 4)), (($img_height / 2) - (($canvas_height / 2) * 4)), $image_width / 4, $image_height / 4, // fills last parameter of original height and width not scaled down. $image_width, $image_height ); // line 38 if(imagejpeg($canvas, 'photos/small/'.$id.'.jpeg', 80)){ return true; } else { return false; } } // end small() The error I am getting from this is: Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home1/royalvil/public_html/photo_voting/photo_fns.php on line 38 line 38 has been commented in the code. Would this error be refering to original images path? Likes it unable to find the image? I checked the directory path to the image to be copied and its correct. What else could this error be refering to? I appreciate the help
  12. Thanks for the help, I was able to get rid of the two errors but another one popped up... mind taking a look? http://royalvillicus.com/photo_voting/db_fns.php Thanks a lot
  13. While I have sucessfully done this in the past, I cant get it to connect for this project. Here is the link to my site: http://royalvillicus.com/photo_voting/db_fns.php Here is my code I am using to connect: function db_connect() { $connection = mysql_connect('localhost', '5335', '12345678'); if (!$connection) { return false; } } if (!mysql_select_db('photovote')) { return false; } return $connection; if(db_connect()) { echo "connected to server"; } Thanks a lot for the help
  14. would it matter that the defined $post variable is inside a switch?
×
×
  • 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.