Jump to content

reisve

Members
  • Posts

    8
  • Joined

  • Last visited

reisve's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi I hve a page with sessions. They work and I get it doing what is suposed to. However, I heve a link to destroy the session (logout) mas the user stays logedin. The script I cal from the logout link is this: <?php session_destroy(); header("Location: index.php"); ?> Can someone help me out with this?
  2. Thank You Guys. It is working now. I spent hours trying to figure out what was wrong. And it was so simple... Thank You again
  3. Hi I have the following code, but can't get the data inserted in the database. Can someone help me? <?php if ($_POST) { $comp_cat = $_POST['category']; $comp_name = $_POST['company']; $comp_link = $_POST['link']; $comp_desc = $_POST['description']; $comp_addr = $_POST['address']; $comp_county = $_POST['county']; $comp_city = $_POST['city']; $comp_state = $_POST['state']; $comp_country = $_POST['country']; $comp_duration = $_POST['duration']; $comp_date = date("Y-m-d"); } if ($_FILES) { $allowed_filetypes = array('.jpg','.jpeg','.png','.gif'); $max_filesize = 1000240; $upload_path = 'userpics/'; $comp_logo = $_FILES['file']['name']; $ext = substr($comp_logo, strpos($comp_logo,'.'), strlen($comp_logo)-1); if(!in_array($ext, $allowed_filetypes)) die('The file you attempted to upload is not allowed.'); if(filesize($_FILES['file']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); if(move_uploaded_file($_FILES['file']['tmp_name'],$upload_path . $comp_logo)) { $link = mysqli_connect($host, $user, $pass, $db); /* check connection */ if (mysqli_connect_errno()) { $msg = $error['dbconnection']; $page = '../../index.php'; header("Location: templates/frontend/error.php?msg=$msg&page=$page"); exit(); } $query = "INSERT INTO links (comp_cat, comp_name, comp_link, comp_desc, comp_addr, comp_county, comp_city, comp_state, comp_country, comp_logo, comp_date)"; $query .= " VALUES ($comp_cat, '$comp_name', '$comp_link', '$comp_desc', '$comp_addr', '$comp_county', '$comp_city', '$comp_state', '$comp_country', '$comp_duration', '$comp_date', '$comp_logo')"; if (mysqli_query($link, $query)){ echo "inserted"; } else { mysqli_error($link); } echo 'Your file upload was successful!'; } else { echo 'There was an error during the file upload. Please try again.'; } } ?> <div class = "centercontent"> <div class = "centerheader"> <?php echo $addlink['title']; ?> </div> <div class = "centertext"> <form action = "addlink.php" enctype = "multipart/form-data" method="post" id = "addlinkform"> <table border = "0" width = "100%"> <tr> <td width = "37%" align = "right" valign = "top"><label><?php echo $addlink['category']; ?></label></td> <td width = "63%"> <select id = "categories" name = "category"> <?php $link = mysqli_connect("localhost", "root", "palhaco", "negocios_angola"); if (!$link) { die('Could not connect: ' . mysqli_connect_error()); } $sql = "SELECT cat_id, cat_name, cat_parent FROM categories"; $res = mysqli_query($link, $sql); while (list($id, $name, $parent) = mysqli_fetch_row($res)) { $data[$parent][] = array('id'=>$id, 'name'=>$name); } // function to print a category then its child categories function displayHierarchy(&$arr, $parent, $indent=0) { if (isset($arr[$parent])){ foreach($arr[$parent] as $rec){ if ($indent == 0){ } elseif ($indent == 1){ echo "<option value = " . $rec['id'] . ">" . $rec['name'] . "</option>" ; }else { echo "<option value = ". $rec['id'] . ">" . str_repeat(" |", $indent) . "___" .$rec['name'] . "</option>" ; } displayHierarchy($arr, $rec['id'], $indent+1); } } } // call the recursive function displayHierarchy($data, ''); ?> </select> </td> </tr> <tr> <td colspan = "2" height = "10px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['name']; ?></label></td> <td><input name = "company" type = "text"></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['link']; ?></label></td> <td><input name = "link" type = "text"></td> </tr> <tr> <td colspan = "2" height = "10px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['desc']; ?></label></td> <td><textarea name = "description"></textarea></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['addr']; ?></label></td> <td><input name = "address" type = "text"></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['county']; ?></label></td> <td><input name = "county" type = "text"></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['city']; ?></label></td> <td><input name = "city" type = "text"></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['state']; ?></label></td> <td><input name = "state" type = "text"></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['country']; ?></label></td> <td><input name = "country" type = "text"></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['duration']; ?></label></td> <td> <select name = "duration"> <?php $sql = "SELECT * FROM duration"; $result = mysqli_query($link, $sql); while ($row = mysqli_fetch_assoc($result)) { echo "<option value = " . $row['dur_id'] . ">" . $row['duration'] . $addlink['days'] . " - " . $row['price'] . " USD</option>"; } mysqli_free_result($res); mysqli_close($link); ?> </select> </td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td align = "right" valign = "top"><label><?php echo $addlink['logo']; ?></label></td> <td><input type="file" name="file"></td> </tr> <tr> <td colspan = "2" height = "5px"></td> </tr <tr> <td colspan = "2" align = "center"><button name = "submit" type = "submit"><?php echo $addlink['submit']; ?></button></td> </tr> </table> </form> </div> </div> The only message I get is: "Your file upload was successful!", but in the data base there is nothing. Thank You. P.S. This is just a module for a bigger project
  4. That was the problem. Thank You very much
  5. It worked. Now I need to output the categories to a combobox that should be easy ThankYou
  6. according the code flow, there was an error, and if the error line is not there I got my error message. Just would like to add the MySQL error itself: $query = "INSERT INTO users (first_name, last_name, email, c_user, c_pass, c_type) VALUES ('$f_fname', '$f_lname', '$f_email', '$f_user', '$cryptpass', '$f_type')"; if (mysqli_query($link, $query)){ $page = '../../index.php'; $msg = $info['register']; header("Location: templates/frontend/info.php?msg=$msg&page=$page"); } else { $page = '../../register.php'; $msg = $error['register']; $msg .= mysql_error($link); header("Location: templates/frontend/error.php?msg=$msg&page=$page"); }
  7. Hi I'm trying to adapt a function to Display Hierarchical Data I found on sitepoint The code I got so far is: <?php // $parent is the parent of the children we want to see // $level is increased when we go deeper into the tree, // used to display a nice indented tree $link = mysql_connect("localhost", "root", "palhaco"); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('testecat', $link); if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } function display_children($parent, $level) { // retrieve all children of $parent $result = mysql_query('SELECT title FROM testcat '. 'WHERE parent="'.$parent.'";'); // display each child while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // indent and display the title of this child echo str_repeat(' ',$level).$row['title']."\n"; // call this function again to display this // child's children display_children($row['title'], $level+1); } } display_children('',0); ?> But the only thing I got is an error message: "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\Web Data\testcat.php on line 20 " Can some one help me please?
  8. Hi I have this piece of code part of a larger code block: $page = '../../register.php'; $msg = $error['register']; $msg .= mysql_error($link); header("Location: templates/frontend/error.php?msg=$msg&page=$page"); everything works if I remove the "$msg .= mysql_error($link);" line. the line bellow comes from a language, file and if the Mysql_error is not on the line, it shows up. with the mysql_error, just get ablank line Any help please?
×
×
  • 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.