Jump to content

Doug

Members
  • Posts

    75
  • Joined

  • Last visited

Everything posted by Doug

  1. Doug

    White space?

    Thanks all for the cometns. Especially for the code AbraCadaver. It works!
  2. Doug

    White space?

    thnaks...that got rid of the errors., sadly it also got rid of the images on the page! www.onesevenoaks.co.uk
  3. Doug

    White space?

    Yes, I did! It's wjat I started out with. No difference sadly. I get the error message 6 times but there are ten images being displayed. Why would that be?
  4. I've been trying to solve this for the past 2 days! Please help. I get this message while trying to validate the code in W3c valifation service. bad value %20images/image_name%20 for attribute src on element img: Whitespace in path component. Use %20 in place of spaces. There is no white space in the lines below. OR is there? I have put %20 in all white spaces that I could find with no effect. if (is_file(MM_UPLOADPATH . $row['picture']) . filesize(MM_UPLOADPATH . $row['picture']) > 0){echo'%20<a href="pictures.php">%20<img src="%20' . MM_UPLOADPATH . $row['picture'] . '%20" alt="sevenoaks latest pic" style="width:75px; maxheight:110px; margin:5px; padding:5px;"></a>'; if (is_file(MM_UPLOADPATH . $row['picture']) . filesize(MM_UPLOADPATH . $row['picture']) > 0){echo'%20<a href="pictures.php">%20<img src="%20' . MM_UPLOADPATH . $row['picture'] . '%20" alt="sevenoaks latest pic" style="width:75px; maxheight:110px; margin:5px; padding:5px;"></a>';
  5. I've been trying to solve this for the past 2 days! Please help. I get this message while trying to validate the code. bad value %20images/image_name%20 for attribute src on element img: Whitespace in path component. Use %20 in place of spaces. There is no white spave in the lines below. OR is there? I have put %20 in all white space if (is_file(MM_UPLOADPATH . $row['picture']) . filesize(MM_UPLOADPATH . $row['picture']) > 0){echo'%20<a href="pictures.php">%20<img src="%20' . MM_UPLOADPATH . $row['picture'] . '%20" alt="sevenoaks latest pic" style="width:75px; maxheight:110px; margin:5px; padding:5px;"></a>';
  6. ok..i must have read th wrong thing. This file is only a few weeks old! The programs work on my local host. They work in the all other programs I have used. It is only this one that it does not work as expected, giving out 40 characters rather than 6 Thnaks for your continued help!
  7. um...think both are the same: On. How would I turn them off? Is this advisable?
  8. UPDATE: It works the first time the page is entered. Refresh and the 40 characters appear
  9. I expect the Captcha.php to out put a string of six characters (letters). Which it does with the first program. With the second, for some reason it outputs a string of 40 characters (letters and numbers)
  10. I have created a Captcha image to use on various forms. It works fine in one are creating a row of letters that when entered correctly send the information to the correct email. However when I cut and paste the exact same code the image creates numbers that cannot be read and therefore the form cannot be sent. I cannot for the life of me see why this would be? Or at least prevent numbers form appearing? Thanks very much in advance for any help Code below: <?php session_start(); // Set some important CAPTCHA constants define('CAPTCHA_NUMCHARS', 6); define('CAPTCHA_WIDTH', 100); define('CAPTCHA_HEIGHT', 25); // Generate the random pass-phrase $pass_phrase = ""; for ($i = 0; $i < CAPTCHA_NUMCHARS; $i++) { $pass_phrase .= chr(rand(97, 122)); } // Store the encrypted pass-phrase in a session variable $_SESSION['pass_phrase'] = SHA1($pass_phrase); // Create the image $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT); // Set a white background with black text and gray graphics $bg_color = imagecolorallocate($img, 255, 255, 255); // white $text_color = imagecolorallocate($img, 0, 0, 0); // black $graphic_color = imagecolorallocate($img, 64, 64, 64); // dark gray // Fill the background imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color); // Draw some random lines for ($i = 0; $i < 5; $i++) { imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Sprinkle in some random dots for ($i = 0; $i < 50; $i++) { imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Draw the pass-phrase string imagettftext($img, 18, 0, 5, CAPTCHA_HEIGHT - 5, $text_color, 'Courier New Bold.ttf', $pass_phrase); // Output the image as a PNG using a header header("Content-type: image/png"); imagepng($img); // Clean up imagedestroy($img); ?> The above works wioth this code below: <?php $from = ""; $subject = ""; $onesevenoaksmail = ""; if (isset($_POST['submit'])) { $from = $_POST ['from']; $subject = $_POST ['subject']; $onesevenoaksmail = $_POST ['onesevenoaksmail']; $email = "support@onesevenoaks.co.uk"; $output_form = 'no'; if (empty($subject)) { //$subject is blank echo '<p class="error">You forgot to enter a subject.</p>'; $output_form = 'yes'; } if (empty($onesevenoaksmail)) { // $onesevenoaksmail is blank echo '<p class="error">You forgot to enter your message.</p>'; $output_form = 'yes'; } //Check the CAPTCHA pass-phrase for verification $user_pass_phrase = sha1($_POST['verify']); if ($_SESSION['pass_phrase'] != $user_pass_phrase) { echo '<p class="error">Please enter the verification pass phrase exactly as shown.</p>'; $output_form = 'yes'; } if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\._\-&!?=#]*@/', $from)) { //$email is invlaid beacsue local name is bad echo '<p class="error">Your email address is incorrect.</p>'; $output_form = 'yes'; } else { //strip out everything but the domain from the email $domain = preg_replace('/^[a-zA-Z0-9][a-zA-Z0-9\._\-&!?=#]*@/', '', $from); //Now check if $domain is registered function win_checkdnsrr($domain,$recType='') { if (!empty($domain)) { if ($recType=='') $recType="MX"; exec("nslookup -type=$recType $domain",$output); foreach($output as $line) { if (preg_match("/^$domain/", $line)) { return true; } return false; } return false; } } } } else { $output_form = 'yes'; } if ($output_form == 'yes') { ?> <table> <tr> <td> <form enctype="multipart/form-data" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="from">Email:</label></td> <td><input id="from" name="from" type="text" size="60" value="<?php echo $from; ?>"/></td></tr> <tr> <td> <label for="subject">Subject of email: </label></td> <td><input type="text" id="subject" name="subject" size="60" value="<?php echo $subject; ?>" /> </td> </tr> <tr> <td> <label for="onesevenoaksmail">Body of email: </label></td> <td><textarea id="onesevenoaksmail" name="onesevenoaksmail" rows="8" cols="60"><?php echo $onesevenoaksmail; ?></textarea> </td> </tr> <tr> <td>Verification:</td> <td> <input type = "text" id="verify" name="verify" size="30" /> <img src="captcha.php" alt="Verification pass-phrase" /> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Submit" /> </td> </tr> </table> <hr> </form> <?php } else if ($output_form == 'no') { $msg = "Dear Doug\n Subject: $subject\n Message: $onesevenoaksmail\n From: $from"; $headers = "doug_pitchers@hotmail.com"; mail($headers, $subject, $msg, 'from:' . 'dougpitchers@yahoo.co.uk'); echo '<p> Thank you for the message! We will respond within 48 hours</p>'; } ?> but not this code below: <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Web development kent - Contact DP Web Development </title> <link rel="stylesheet" href="dpwebdevelopment1.css" type="text/css" /> </head> <body id="contact"> <div id="wrap4"> <div id="header"> DP WEB DEVELOPMENT </div> <?php require_once('navmenu.php'); ?> <img alt='contactus image' src='webdevelopmentimages/reflowers.jpg' border='0'/> <H1>Contact DP Web Development</h1> &nbsp<div id="phone"> <img src="webdevelopmentimages/phoneicon.gif" alt="phone DP Web Development">07939014511 </div> <p>Whatever your situation we would love to hear from you</p> <?php $firstname = ""; $lastname = ""; $from = ""; $subject = ""; $dpwebdevelopmentmail = ""; $number = ""; $webmail = ""; if (isset($_POST['submit'])) { $firstname = $_POST ['firstname']; $lastname = $_POST ['lastname']; $from = $_POST ['from']; $subject = $_POST ['subject']; $dpwebdevelopmentmail = $_POST ['dpwebdevelopmentmail']; $email = "doug_pitchers@hotmail.com"; $number = $_POST ['number']; $webmail = $_POST['webmail']; $output_form = 'no'; if (empty($firstname)) { //$firtsname is blank echo '<p class="error">You forgot to enter your first name.</p>'; $output_form = 'yes'; } if (empty($lastname)) { //$lastname is blank echo '<p class="error">You forgot to enter your last name.</p>'; $output_form = 'yes'; } if (empty($subject)) { //$subject is blank echo '<p class="error">You forgot to enter a subject.</p>'; $output_form = 'yes'; } if (empty($dpwebdevelopmentmail)) { // $dpwebdevelopmentmail is blank echo '<p class="error">You forgot to enter your message.</p>'; $output_form = 'yes'; } //Check the CAPTCHA pass-phrase for verification $user_pass_phrase = sha1($_POST['verify']); if ($_SESSION['pass_phrase'] != $user_pass_phrase) { echo '<p class="error">Please enter the verification pass phrase exactly as it is shown.</p>'; $output_form = 'yes'; } if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\._\-&!?=#]*@/', $from)) { //$email is invlaid beacsue local name is bad echo '<p class="error">Your email address was not recognised. Please enter it again..</p>'; $output_form = 'yes'; } else { //strip out everything but the domain from the email $domain = preg_replace('/^[a-zA-Z0-9][a-zA-Z0-9\._\-&!?=#]*@/', '', $from); //Now check if $domain is registered function win_checkdnsrr($domain,$recType='') { if (!empty($domain)) { if ($recType=='') $recType="MX"; exec("nslookup -type=$recType $domain",$output); foreach($output as $line) { if (preg_match("/^$domain/", $line)) { return true; } return false; } return false; } } } } else { $output_form = 'yes'; } if ($output_form == 'yes') { ?> <table> <tr> <td> <form enctype="multipart/form-data" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr> <td> <label for="firstname">First Name: </label></td> <td><input type="text" id="firstname" name="firstname" size="60" value="<?php echo $firstname; ?>" /> </td> </tr> <tr> <td> <label for="lastname">Last Name: </label></td> <td><input type="text" id="lastname" name="lastname" size="60" value="<?php echo $lastname; ?>" /> </td> </tr> <tr> <td> <label for="subject">Subject of email: </label></td> <td><input type="text" id="subject" name="subject" size="60" value="<?php echo $subject; ?>" /> </td> </tr> <tr> <td> <label for="dpwebdevelopmentmail">Message </label></td> <td><textarea id="dpwebdevelopmentmail" name="dpwebdevelopmentmail" rows="8" cols="60"><?php echo $dpwebdevelopmentmail; ?></textarea> </td> </tr> <tr> <td> <label for="from">Your Email address:</label></td> <td><input id="from" name="from" type="text" size="60" value="<?php echo $from; ?>"/></td></tr> <tr> <td> <label for="from">Your contact phone number:</label></td> <td><input id="number" name="number" type="text" size="60" value="<?php echo $number ?>"/> </td> </tr> <tr> <td> <label for="contact">How would you prefer to be contacted?:</label></td> <td>Email <input id="webmail" name="webmail" type="radio" value="webmail" checked /> Phone<input id="webmail" name="webmail" type="radio" value="phone" /> </td> </tr> <tr> <td>Verification:</td> <td> <input type = "text" id="verify" name="verify" size="30" /> <img src="captcha.php" alt="Verification pass-phrase" /> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Submit" /> </td> </tr> </table> <hr> </form> <?php } else if ($output_form == 'no') { $msg = "Dear Doug\n FirstName: $firstname\n Lastname: $lastname\n Subject: $subject\n Message: $dpwebdevelopmentmail\n Phone: $number\n Contact: $webmail\n From: $from"; $headers = "doug_pitchers@hotmail.com"; mail($headers, $subject, $msg, 'from:' . 'dougpitchers@yahoo.co.uk'); echo '<p> Thank you for the message! We will respond within 24 hours</p>'; } ?> </body> </html>
  11. Doug

    Captcha

    Hi, I have no idea why the code below does not work. I cannot see anything wrong. ! get the following error: <b>Warning</b>: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in....on line 64 There is no line 64 Any help much appreciated. COde: <?php session_start(); // Set some important CAPTCHA constants define('CAPTCHA_NUMCHARS', 6); define('CAPTCHA_WIDTH', 100); define('CAPTCHA_HEIGHT', 25); // Generate the random pass-phrase $pass_phrase = ""; for ($i = 0; $i < CAPTCHA_NUMCHARS; $i++) { $pass_phrase .= chr(rand(97, 122)); } // Store the encrypted pass-phrase in a session variable $_SESSION['pass_phrase'] = SHA1($pass_phrase); // Create the image $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT); // Set a white background with black text and gray graphics $bg_color = imagecolorallocate($img, 255, 255, 255); // white $text_color = imagecolorallocate($img, 0, 0, 0); // black $graphic_color = imagecolorallocate($img, 64, 64, 64); // dark gray // Fill the background imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color); // Draw some random lines for ($i = 0; $i < 5; $i++) { imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Sprinkle in some random dots for ($i = 0; $i < 50; $i++) { imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Draw the pass-phrase string imagettftext($img, 18, 0, 5, CAPTCHA_HEIGHT - 5, $text_color, 'Courier New Bold.ttf', $pass_phrase); // Output the image as a PNG using a header header("Content-type: image/png"); imagepng($img); // Clean up imagedestroy($img); ?>
  12. yes, I understand that. Thank you so much for your help
  13. Sorry....that doesn't work...the user goes straight to "Your profile has been successfully updated" which is wrong (and also untrue!) they should get the one of the two earlier messages Thanks so much for your continued help Doug
  14. I have made the changes...I get one error now: Warning: mysqli_query() expects at least 2 parameters, 1 given Obviously I'm missing something. I tied adding $dbc and swapping the parameters around but these didn't work. if (!empty($name)&& !empty($phone) && !empty($address1) && !empty($address2)) { // Only set the picture column if there is a new picture if (!empty($new_picture)) { //if (!empty($postcode)){ $query = "UPDATE companies SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', picture = '$new_picture', username = '$username', cat = '$cat' WHERE user_id = '" . $row['user_id'] ."'"; if( !$result = mysqli_query($query) ) { if( mysql_errno() === 1062 ) { echo "You have already claimed a business, moron."; } else { echo "Sorry, the database gagged and puked up your input."; } } else { $query = "UPDATE companies set name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', username = '$username', cat = '$cat' WHERE user_id = '" . $row['user_id'] ." '"; }}} mysqli_query($dbc, $query) or die("<br>Query $query<br>Failed with error: " . mysql_error($dbc) . '<br>On line: ' . __LINE__); if( !$result = mysqli_query($query) ) { if( mysql_errno() === 1062 ) { echo "You have already claimed a business, moron."; } else { echo "Sorry, the database gagged and puked up your input."; ?> 1<P>GO <a href="index5.php">Home</a></p> <?php }} else { // Confirm success with the user echo 'USER ID = ' . $row["user_id"] . ''; ?> <br /> <?php echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile7.php">view your profile</a>?</p>'; } mysqli_close($dbc); exit(); }
  15. Hi. That is nearly there. The problem is I am now unable to access the one business I have claimed and I get the following message with any other business I try to claim: Warning: mysql_query() [function.mysql-query]: Can't connect to MySQL server on 'localhost' (10061) in C:\Program Files (x86)\EasyPHP5.2.10\www\OneSevenoaks\editbusprofile9.php on line 205 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Program Files (x86)\EasyPHP5.2.10\www\OneSevenoaks\editbusprofile9.php on line 205 Sorry, the database gagged and puked up your input. Any ideas? Modified code below: if (!$error) { if (!empty($name)&& !empty($phone) && !empty($address1) && !empty($address2)) { // Only set the picture column if there is a new picture if (!empty($new_picture)) { //if (!empty($postcode)){ $query = "UPDATE companies SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', picture = '$new_picture', username = '$username', cat = '$cat' WHERE user_id = '" . $row['user_id'] ."'"; if( !$result = mysql_query($query) ) { if( mysql_errno() === 1062 ) { echo "You have already claimed a business, moron."; } else { echo "Sorry, the database gagged and puked up your input."; } } else { $query = "UPDATE companies set name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', username = '$username', cat = '$cat' WHERE user_id = '" . $row['user_id'] ." '"; }}} mysqli_query($dbc, $query) or die("<br>Query $query<br>Failed with error: " . mysqli_error($dbc) . '<br>On line: ' . __LINE__); if( !$result = mysql_query($query) ) { if( mysql_errno() === 1062 ) { echo "You have already claimed a business, moron."; } else { echo "Sorry, the database gagged and puked up your input."; ?> <P>GO <a href="index5.php">Home</a></p> <?php }} else { // Confirm success with the user echo 'USER ID = ' . $row["user_id"] . ''; ?> <br /> <?php echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile7.php">view your profile</a>?</p>'; } mysqli_close($dbc); exit(); }
  16. username in MySQL is set to unique. If the user tries to claim another business MySQL objects as it is replicating a username which should be unique. So you get for example: Query UPDATE companies set name = 'Business', phone = '012345, address1 = 'first line', address2 = 'Second line', postcode = 'postcode', email = 'email entered', webadd = 'web entered', username = 'doug', cat = 'bakers' WHERE user_id = '12 ' Failed with error: Duplicate entry 'doug' for key 'username' On line: 203 This is the page I would like to avoid if possible?
  17. Hello, I am creating a website where users can "claim" their business by clicking on a link. I have managed to code so that users can claim their business or get a message that the business has already ben claimed by another user. Where I'm coming stuck is if a user wants to claim more than one business (I want to limit each user to one). I have made the MySQL table for username unique so that if a user does try to claim more than one business they get the MySQL objection. My question is how do I, instead of seeing this message, redirect to a "you have already claimed a business message"? I am at a loss as how to do this or is my logic wrong? Any help greatly appreciated. This is the relevant code I already have: $username1 = $_SESSION['username']; if (($username != ($username1)) && (!empty($username))) { echo '<p class="error"> This profile is taken</p>'; ?> <?php echo('<p class="login">You are logged in as ' . $username1 . '. <a href="logout3.php">Log out</a>.</p>'); ?> <?php echo('<p class="login">The owner of this account is ' . $username . '. </p>'); ?> <p><a href="index5.php">Return to homepage</a></p> <?php exit(); } else { echo '<p class="error">There was a problem accessing your profile.</p>'; }} mysqli_close($dbc); ?>
  18. Doug

    Easy question!

    Thanks but I was hoping to do it once the numbers are already there. So I have auto_increment 1,2,3,4 etc. I would like to change 1,2,3,4 to 10, 20, 30, and 40. Is this possible without manually changing each one? I'm sure it must be
  19. Doug

    Easy question!

    I get: Error 1064 (42000) you have an error in your SQL sytnax; check teh manual that corresposnd to your MySQL server version for the right syntax near user_id int auto_increment=16
  20. Doug

    Easy question!

    maybe it's harder than I thought. Is it possible?
  21. Doug

    Easy question!

    I should know this and can't believe it is not anywhere to be seen on Google I would like to know how how to add a column (user_id) to an existing table that auto increments from 16 (rather than 1) I have alter table table name add column user_id not null auto_increment = 16 but this doesn't work Help appreciated Doug
  22. Thank you all. It was $row not $row['user_id'] Yes I will tidy up the code, apologies, remnants of previuos attempts to solve problem! Doug
  23. Hello, I have hit a brick wall with the following problem. To me it defies logic. I have a MySQL table that has various details in me and to link it to a particular user I use the code below. The problem is it works for on "cat" but not for any other. Even though IT IS THE SAME CODE except for the cat name. Why would this be? The user_id reverts to 1 (even though this user_id does not exist in the table) at the crucial moment. At every other stage I have tested it displays the correct user_id. This only happens when I choose a cat other than the first 5. Any help with this would be most gratefully received. Code below: THe one is th "editing" part so you can edit detials and save them It is where the user_id reverts to 1. <?php error_reporting(E_ALL); session_start(); ?> <?php require_once('appvars.php'); require_once('connectvars1.php'); //$datbase= $_POST['$datbase']; // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); $row = $_POST['user_id']; if (!isset($_GET['user_id'])) { $query = "SELECT * FROM companies WHERE user_id = '" . $row['user_id'] . "'"; } else { $query = "SELECT * FROM companies WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query) or die("Error: ".mysqli_error($dbc)); if (mysqli_num_rows($data) == 1) { $row = mysqli_fetch_array($data); } ?> <?php require_once('appvars.php'); require_once('connectvars1.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login1.php">log in</a> to access this page.</p>'; exit(); } // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); if(!empty($username)) { echo '<p class="login">This page is already taken please <a href="index5.php"">go home</a> and try again.</p>'; } if (isset($_POST['submit'])) { // Grab the profile data from the POST $name = mysqli_real_escape_string($dbc, trim($_POST['name'])); $phone = mysqli_real_escape_string($dbc, trim($_POST['phone'])); $address1 = mysqli_real_escape_string($dbc, trim($_POST['address1'])); $address2 = mysqli_real_escape_string($dbc, trim($_POST['address2'])); $postcode = mysqli_real_escape_string($dbc, trim($_POST['postcode'])); $webadd = mysqli_real_escape_string($dbc, trim($_POST['webadd'])); $email = mysqli_real_escape_string($dbc, trim($_POST['email'])); $old_picture = mysqli_real_escape_string($dbc, trim($_POST['old_picture'])); $new_picture = mysqli_real_escape_string($dbc, trim($_FILES['new_picture']['name'])); $new_picture_type = $_FILES['new_picture']['type']; $new_picture_size = $_FILES['new_picture']['size']; $username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $cat = mysqli_real_escape_string($dbc, trim($_POST['cat'])); $user_id = mysqli_real_escape_string($dbc, trim($_POST['user_id'])); if (!empty($_FILES['new_picture']['tmp_name'])) {list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']); } //list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']); $error = false; // Validate and move the uploaded picture file, if necessary if (!empty($new_picture)) { if ((($new_picture_type == 'image/gif') || ($new_picture_type == 'image/jpeg') || ($new_picture_type == 'image/pjpeg') || ($new_picture_type == 'image/png')) && ($new_picture_size > 0) && ($new_picture_size <= MM_MAXFILESIZE) && ($new_picture_width <= MM_MAXIMGWIDTH) && ($new_picture_height <= MM_MAXIMGHEIGHT)) { if ($_FILES['new_picture']['error'] == 0) { // Move the file to the target upload folder $target = MM_UPLOADPATH . basename($new_picture); if (move_uploaded_file($_FILES['new_picture']['tmp_name'], $target)) { // The new picture file move was successful, now make sure any old picture is deleted if (!empty($old_picture) && ($old_picture != $new_picture)) { } } else { // The new picture file move failed, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Sorry, there was a problem uploading your picture.</p>'; } } } else { // The new picture file is not valid, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Your picture must be a GIF, JPEG, or PNG image file no greater than ' . (MM_MAXFILESIZE / 1024) . ' KB and ' . MM_MAXIMGWIDTH . 'x' . MM_MAXIMGHEIGHT . ' pixels in size.</p>'; } } $error = false; // Update the profile data in the database if (!$error) { if (!empty($name)&& !empty($phone) && !empty($address1) && !empty($address2)) { // Only set the picture column if there is a new picture if (!empty($new_picture)) { //if (!empty($postcode)){ $query = "UPDATE companies SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', picture = '$new_picture', username = '$username', cat = '$cat' WHERE user_id = '" . $row['user_id'] ."'"; } else { $query = "UPDATE companies set name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', username = '$username', cat = '$cat' WHERE user_id = '" . $row['user_id'] ." '"; }} mysqli_query($dbc, $query) or die("<br>Query $query<br>Failed with error: " . mysqli_error($dbc) . '<br>On line: ' . __LINE__); // Confirm success with the user echo 'USER ID = ' . $row["user_id"] . ''; ?> <br /> <?php echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile7.php">view your profile</a>?</p>'; mysqli_close($dbc); exit(); } else { echo '<p class="error">You must enter all of the profile data (the picture is optional).</p>'; } } // End of check for form submission else { // Grab the profile data from the database $query="SELECT * FROM companies WHERE user_id= '" . $row['user_id'] . "'"; $data = mysqli_query($dbc, $query) or die("Error: ".mysqli_error($dbc)); $row = mysqli_fetch_array($data); if ($row != NULL) { $name = $row['name']; $phone = $row['phone']; $address1 = $row['address1']; $address2 = $row['address2']; $postcode = $row['postcode']; $email = $row['email']; $webadd = $row['webadd']; $old_picture = $row['picture']; $username = $_SESSION['username']; $cat = $row['cat']; $user_id = $row['user_id']; } else { echo '<p class="error">There was a problem accessing your profile.</p>'; } } mysqli_close($dbc); ?> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MM_MAXFILESIZE; ?>" /> <fieldset> <legend>Personal Information</legend> <label for="name">Name:</label> <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="phone">Phone:</label> <input type="text" id="phone" name="phone" value="<?php if (!empty($phone)) echo $phone; ?>" /><br /> <label for="address1">Address1:</label> <input type="text" id="address1" name="address1" value="<?php if (!empty($address1)) echo $address1; ?>" /><br /> <label for="address2">Address2:</label> <input type="text" id="address2" name="address2" value="<?php if (!empty($address2)) echo $address2; ?>" /><br /> <label for="postcode">Postcode:</label> <input type="text" id="postcode" name="postcode" value="<?php if (!empty($postcode)) echo $postcode; ?>" /><br /> <label for="email">Email:</label> <input type="text" id="email" name="email" value="<?php if (!empty($email)) { echo $email; } else { echo 'No email entered';} ?>" /><br /> <label for="webadd">Web address:</label> <input type="text" id="webadd" name="webadd" value="<?php if (!empty($webadd)) { echo $webadd; } else { echo 'No web entered';} ?>" /><br /> <input type="hidden" name="old_picture" value="<?php if (!empty($old_picture)) echo $old_picture; ?>" /> <label for="new_picture">Picture:</label> <input type="file" id="new_picture" name="new_picture" /> <?php if (!empty($old_picture)) { echo '<img class="profile" src="' . MM_UPLOADPATH . $old_picture . '" alt="Profile Picture" style: height=100px;" />'; } ?> <br /> <label for="address2">username:</label> <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br /> <label for="cat">cat:</label> <input type="text" id="cat" name="cat" value="<?php if (!empty($cat)) {echo $cat; } else { echo 'bakers';} ?>" /><br /> <label for="user_id">User ID:</label> <input type="text" id="user_id" name="user_id" value="<?php echo '' . $row['user_id'] . '' ; ?>" /><br /> </fieldset> <input type="submit" value="Save Profile" name="submit" /> </form> <?php echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout3.php">Log out</a>.</p>'); echo '<class = "label">USER ID: ' . $row['user_id'] . ''; ?> <br /> <?php echo 'Username = ' . $row["username"] . '' ?><br /> <?php echo 'This category is ' . $row["cat"] . '' ?> <br /> <p><a href="index5.php">Return to homepage</a></p> <?php require_once('footer.php'); ?> </body> </html> THis is where the data is sent from <?php require_once('top1.php'); ?> <h3>Antique Shops</h3> <?php require_once('navmenu.php'); ?> <?php require_once('businessmenu.php'); ?> <?php require_once('retailrightmenu.php'); ?> <div id="localareamain"> <?php require_once('connectvars1.php'); // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); // Retrieve the user data from MySQL $query = "SELECT * FROM companies where cat = 'antique'"; $result = mysqli_query($dbc, $query); //$datbase= "antique"; //if records are present if (mysqli_num_rows($result) > 0) { //Print list while ($row = mysqli_fetch_array($result)) { echo 'Name: ' . $row['name']; ?> <br /> <?php echo 'Phone: ' . $row['phone']; ?> <br /> <?php echo 'Address: ' . $row['address1']; ?> <br /> <?php echo ' ' . $row['address2']; ?> <br /> <?php echo ' ' . $row['postcode']; ?> <br /> <?php echo ' ' . $row['username']; ?> <br /> <?php echo '<a href="editbusprofile9.php?user_id=' . $row["user_id"] .'">Is this business yours? Claim it and add more details </a>'; ?> <br /> <hr> <?php } } ?> </div> <?php require_once('footer.php'); ?> </div> </div> </body> </html>
  24. So, is it impossible to select the name of the table form the lines above? I have 20 different tables. Are you saying it should be one huge table? Or 20 different programs depending on the user’s choice? Thanks or continued help. For context the whole program is below. I eventually want the name of the table to be automatically entered but chose the few lines as a start <?php error_reporting(E_ALL); session_start(); ?> <?php require_once('appvars.php'); require_once('connectvars1.php'); //$datbase= $_POST['$datbase']; // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); $row = $_POST['user_id']; if (!isset($_GET['user_id'])) { $query = "SELECT * FROM butcher WHERE user_id = '" . $row['user_id'] . "'"; } else { $query = "SELECT * FROM butcher WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query) or die("Error: ".mysqli_error($dbc)); if (mysqli_num_rows($data) == 1) { $row = mysqli_fetch_array($data); } ?> <?php require_once('appvars.php'); require_once('connectvars1.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login1.php">log in</a> to access this page.</p>'; exit(); } // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); if(!empty($username)) { echo '<p class="login">This page is already taken please <a href="index5.php"">go home</a> and try again.</p>'; } if (isset($_POST['submit'])) { // Grab the profile data from the POST $name = mysqli_real_escape_string($dbc, trim($_POST['name'])); $phone = mysqli_real_escape_string($dbc, trim($_POST['phone'])); $address1 = mysqli_real_escape_string($dbc, trim($_POST['address1'])); $address2 = mysqli_real_escape_string($dbc, trim($_POST['address2'])); $postcode = mysqli_real_escape_string($dbc, trim($_POST['postcode'])); $webadd = mysqli_real_escape_string($dbc, trim($_POST['webadd'])); $email = mysqli_real_escape_string($dbc, trim($_POST['email'])); $old_picture = mysqli_real_escape_string($dbc, trim($_POST['old_picture'])); $new_picture = mysqli_real_escape_string($dbc, trim($_FILES['new_picture']['name'])); $new_picture_type = $_FILES['new_picture']['type']; $new_picture_size = $_FILES['new_picture']['size']; $username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $user_id = mysqli_real_escape_string($dbc, trim($_POST['user_id'])); if (!empty($_FILES['new_picture']['tmp_name'])) {list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']); } //list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']); $error = false; // Validate and move the uploaded picture file, if necessary if (!empty($new_picture)) { if ((($new_picture_type == 'image/gif') || ($new_picture_type == 'image/jpeg') || ($new_picture_type == 'image/pjpeg') || ($new_picture_type == 'image/png')) && ($new_picture_size > 0) && ($new_picture_size <= MM_MAXFILESIZE) && ($new_picture_width <= MM_MAXIMGWIDTH) && ($new_picture_height <= MM_MAXIMGHEIGHT)) { if ($_FILES['new_picture']['error'] == 0) { // Move the file to the target upload folder $target = MM_UPLOADPATH . basename($new_picture); if (move_uploaded_file($_FILES['new_picture']['tmp_name'], $target)) { // The new picture file move was successful, now make sure any old picture is deleted if (!empty($old_picture) && ($old_picture != $new_picture)) { } } else { // The new picture file move failed, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Sorry, there was a problem uploading your picture.</p>'; } } } else { // The new picture file is not valid, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Your picture must be a GIF, JPEG, or PNG image file no greater than ' . (MM_MAXFILESIZE / 1024) . ' KB and ' . MM_MAXIMGWIDTH . 'x' . MM_MAXIMGHEIGHT . ' pixels in size.</p>'; } } $error = false; // Update the profile data in the database if (!$error) { if (!empty($name)&& !empty($phone) && !empty($address1) && !empty($address2)) { // Only set the picture column if there is a new picture if (!empty($new_picture)) { //if (!empty($postcode)){ $query = "UPDATE butcher SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', picture = '$new_picture', username = '$username' WHERE user_id = '" . $row['user_id'] ."'"; } else { $query = "UPDATE butcher set name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', username = '$username' WHERE user_id = '" . $row['user_id'] ."'"; }} mysqli_query($dbc, $query) or die("<br>Query $query<br>Failed with error: " . mysqli_error($dbc) . '<br>On line: ' . __LINE__); // Confirm success with the user echo 'USER ID = ' . $row["user_id"] . ''; ?> <br /> <?php echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile7.php">view your profile</a>?</p>'; mysqli_close($dbc); exit(); } else { echo '<p class="error">You must enter all of the profile data (the picture is optional).</p>'; } } // End of check for form submission else { // Grab the profile data from the database $query="SELECT * FROM '". $row['cat'] . "' WHERE user_id= '" . $row['user_id'] . "'"; $data = mysqli_query($dbc, $query) or die("Error: ".mysqli_error($dbc)); $row = mysqli_fetch_array($data); if ($row != NULL) { $name = $row['name']; $phone = $row['phone']; $address1 = $row['address1']; $address2 = $row['address2']; $postcode = $row['postcode']; $email = $row['email']; $webadd = $row['webadd']; $old_picture = $row['picture']; $username = $_SESSION['username']; $user_id = $row['user_id']; } else { echo '<p class="error">There was a problem accessing your profile.</p>'; } } mysqli_close($dbc); ?> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MM_MAXFILESIZE; ?>" /> <fieldset> <legend>Personal Information</legend> <label for="name">Name:</label> <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="phone">Phone:</label> <input type="text" id="phone" name="phone" value="<?php if (!empty($phone)) echo $phone; ?>" /><br /> <label for="address1">Address1:</label> <input type="text" id="address1" name="address1" value="<?php if (!empty($address1)) echo $address1; ?>" /><br /> <label for="address2">Address2:</label> <input type="text" id="address2" name="address2" value="<?php if (!empty($address2)) echo $address2; ?>" /><br /> <label for="postcode">Postcode:</label> <input type="text" id="postcode" name="postcode" value="<?php if (!empty($postcode)) echo $postcode; ?>" /><br /> <label for="email">Email:</label> <input type="text" id="email" name="email" value="<?php if (!empty($email)) { echo $email; } else { echo 'No email entered';} ?>" /><br /> <label for="webadd">Web address:</label> <input type="text" id="webadd" name="webadd" value="<?php if (!empty($webadd)) { echo $webadd; } else { echo 'No web entered';} ?>" /><br /> <input type="hidden" name="old_picture" value="<?php if (!empty($old_picture)) echo $old_picture; ?>" /> <label for="new_picture">Picture:</label> <input type="file" id="new_picture" name="new_picture" /> <?php if (!empty($old_picture)) { echo '<img class="profile" src="' . MM_UPLOADPATH . $old_picture . '" alt="Profile Picture" style: height=100px;" />'; } ?> <br /> <label for="address2">username:</label> <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br /> <label for="user_id">User ID:</label> <input type="text" id="user_id" name="user_id" value="<?php echo '' . $row['user_id'] . '' ; ?>" /><br /> </fieldset> <input type="submit" value="Save Profile" name="submit" /> </form> <?php echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout3.php">Log out</a>.</p>'); echo '<class = "label">USER ID: ' . $row['user_id'] . ''; ?> <br /> <?php echo 'Username = ' . $row["username"] . '' ?><br /> <?php echo 'This category is ' . $row["cat"] . '' ?> <br />; <p><a href="index5.php">Return to homepage</a></p> <?php require_once('footer.php'); ?> </body> </html>
×
×
  • 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.