Jump to content

Zerpex

Members
  • Posts

    40
  • Joined

  • Last visited

Everything posted by Zerpex

  1. Hmm okay, I can see, that when I use the $items and foreach to echo out the checkboxes, it doesn't even work.. Hmmz gotta find a better way, with a starting point of my static checkboxes
  2. Ahh yeah, ur right, I could just make the foreach echo out the stuff, instead of putting them in an array, and then echo out
  3. I'm trying to create a website, that echo's out a bunch of groups, where each group contains a group of checkboxes, containing A value, and a label for the checkbox, the way it is created right now, is foreach that echo's out a bunch of php arrays, which was easier than the static way before - But still, it's static in some way, or not very user friendly at the moment.. My problem is that I really want to write it in a database when I have the option. Is there anyone that can give some tips how to do? At the moment, my foreach looks like this: echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; /* NEXT WE CREATE OUR FOREACH LOOPS TO ECHO THE HTML FOR LOOKS AND CHECKBOXES */ $totalID=0; // this is a counter we use to build our check box names foreach ($items as $list){ $totalID++; // add one to the checkbox name counter echo "<h2>{$list['title']}</h2>\n"; // and echo out our section header foreach ($list['items'] as $cbox){ // now for each item in the list, call it $cbox // $cbox now holds the item name, and point value echo "<label class='checkbox'><input type='checkbox' name='totals[$totalID][]' value='{$cbox[1]}'> {$cbox[0]}</label>\n"; } } echo "</form>"; And my array is something like this: $items['computers']['title']='Computer Brand'; $items['computers']['items'][]=array('Apple iMac',1); $items['computers']['items'][]=array('Apple Macbook',.5); $items['phones']['title']='Phone Brand'; $items['phones']['items'][]=array('iPhone',1); $items['phones']['items'][]=array('HTC',1); As said, I can write this, but takes time. I want to get it into a database, that data above, but I'm having problems about echo'ing it out, I really can't see how I should do. My current database looks like this: Thank you!
  4. Thank you very much all! Got all problems fixed final code: <?php require "includes/connect.php"; $msg = ''; mysql_select_db($db_name, $connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $result = mysql_query("SELECT email FROM test_emails"); if(mysql_num_rows($result)){ throw new Exception('This email already exists in the database.'); } else { mysql_query("INSERT INTO test_emails SET email='".mysql_real_escape_string($_POST['email'])."'");{ if($ajax){ die('{"status":1}'); } } $msg = "Thank you!"; } } catch(Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } ?> the reason to it use ajax is because the ajax search in the DB for dublicates, no no need to make the dublicate thing. But really, without your guys help, I would not be able to fix it I think! Thank you very much - Problem solved!
  5. Okay, Now I have tried anything - off that small experience I have with php and mysql - and can't still get it working. I made this: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $result = mysql_query("SELECT email FROM slcoding_emails"); $num_rows = mysql_num_rows($result); mysql_query("INSERT INTO slcoding_emails SET email='".mysql_real_escape_string($_POST['email'])."'"); if("$num_rows != 1"){ throw new Exception('This email already exists in the database.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } I know that there must be huge errors, how I set it up like etc. when I Select the email col, from the tabel slcoding_emails, then I say $num_rows = mysql_num_rows($result); if("$num_rows != 1"){ throw new Exception('This email already exists in the database.'); } then it should throw the message.. But don't work, because I think I need something, or have made some big mistakes.. I really want this to work, but yeah - it's hard, and if I get it fixed, I'll learn that to next time, and remember it
  6. Okay, can't get it working.. and doesn't really wanna try more because it doesn't seems to work.. I'm a mysql and php fail..
  7. So it should be something like this? mysql_query("INSERT INTO slcoding_emails SET email='".mysql_real_escape_string($_POST['email'])."'"); $result = mysql_query("SELECT email FROM slcoding_emails"); if("$result != 1"){ throw new Exception('This email already exists in the database.'); }
  8. No, it was a guide I was following on a site - and they used mysqli - I have now converted the most of the script, it writes to the database, but the problem I have now is when it need to tell if the email already is in the DB, or if it isn't - like if it isn't in the DB it should write "Thank you!" And when it is in the DB it should write "The email already exists in the Database!" But when I'm using a mail that isn't in the DB it still write "The email already exists in the Database!" So, it should be something like: if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } mysql_query("INSERT INTO slcoding_emails SET email='".mysql_real_escape_string($_POST['email'])."'"); if(mysql_affected_rows != 1){ throw new Exception('This email already exists in the database.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } The problem is, that when the email isn't wrote to the DB yet, it still write the code: throw new Exception('This email already exists in the database.'); hmm..
  9. First of all, sorry about the 2 words.. but, things just don't work anymore, it's like mysqli really affects the webshops and some other sites.. Thats really weird :S But we're trying to take it off, and we can't just enable it on 1 account on dedicated, without installing it as 2-3 VPS - tho, I may find a solution to convert mysqli to mysql instead.. anyway, thank you for fast reply
  10. Okay, I have marked this as unsolved again - after running mysqli for around 12 hours - some of the webshop and stuff on the server started to fuck up - so we need to spend few days getting the mysqli off.. I know I have a very little exp. with translating/converting mysqli to mysql, and I should read more about it.. but don't know where.. If any have the time, or any wanna help then it would be so wonderful! Thank you very much already Regards, Zerpex
  11. I have installed mysqli extension now - My server means a dedicated, we share it between 3 people, and on of the people is pretty good at server setup and so, but isn't home at the moment, so no way to get in contact with him tho.. Will look on the database class thing, and statement of error_reporting: 22519 - display_error: on - and PHP version is 5.3.3 But problem got solved, it was all - Thank you much for helping anyway PFMaBiSmAd
  12. When I run the phpinfo(); function - nothing about mysqli is listed tho :/
  13. Oh, and by the way.. Forgot this: MySQL Version: 5.1.51 CREATE TABLE `email_test` ( `email` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`email`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  14. The way I installed MySQLi on the server: First loggin into cPanel, then going to PHP PEAR Packages, Searching for MySQLi and installed "MDB2_Driver_mysqli (1.5.0.b3 beta) I should try restart Apache tho. Thats the problem, it don't give any errors, even when I have enabled full error reporting :S
  15. Hello everyone, I'm new on this forum, and I really need some help, I've been following a guide on the internet how to make a "Coming Soon" page using PHP, Ajax and Mysql, it works as it should when using LocalHost, like WAMP or MAMP - but when I upload it to my server, it doesn't work, I just get a blank page - I searched on the net for pretty long time, and found that the Mysqli could be the problem, I went to the server and installed Mysqli plugin, but after I have installed the plugin it still don't work.. So I got the idea, making it just Mysql instead Mysqli, I'm not the best for converting stuff, and thats why I'm asking here if any can help me, so I can learn it. <?php require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO email_test SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('This email already exists in the database.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>AJAX-ed Coming Soon Page with jQuery and PHP | Tutorialzine Demo</title> <link rel="stylesheet" type="text/css" href="css/styles.css" /> <link rel="stylesheet" type="text/css" href="css/nivo-slider.css" /> </head> <body> <div id="page"> <h1>Coming Soon</h1> <div id="slideshowContainer"> <div id="slideshow"> <img src="img/slides/slide1.jpg" width="454" height="169" alt="Coming Soon: Our Awesome Web App"> <img src="img/slides/slide2.jpg" width="454" height="169" alt="Extensive Functionality"> <img src="img/slides/slide3.jpg" width="454" height="169" alt="Complete with an iPhone App"> </div> </div> <h2>Subscribe</h2> <form method="post" action=""> <input type="text" id="email" name="email" value="<?php echo $msg?>" /> <input type="submit" value="Submit" id="submitButton" /> </form> </div> <!-- Feel free to remove this footer --> <div id="footer"> <div class="tri"></div> <h1>AJAX-ed Coming Soon Page</h1> <a class="tzine" href="http://tutorialzine.com/2010/10/ajaxed-coming-soon-page/">Read & Download on</a> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script src="js/jquery.nivo.slider.pack.js"></script> <script src="js/script.js"></script> </body> </html> I know the code is pretty long, and I know I should only post the most important part, but maybe there should be changed something else in the rest of the code too - as you can see I link to the connect.php, it's my info about username, password, and so, and then some of the Mysqli: <?php error_reporting(E_ALL ^ E_NOTICE); $db_host = 'host'; $db_user = 'username'; $db_pass = 'password'; $db_name = 'email_test'; @$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name); if (mysqli_connect_errno()) { die('<h1>Could not connect to the database</h1><h2>Please try again after a few moments.</h2>'); } $mysqli->set_charset("utf8"); ?> The big problem is to convert it to normal Mysql so I should be able to use the code.. If any wanna help I would be so nice! Thank you anyway! Best regards, Zerpex
×
×
  • 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.