Jump to content

benoit1980

Members
  • Posts

    35
  • Joined

  • Last visited

Everything posted by benoit1980

  1. Hi All I am a bit confused on how to add $mysqli->affected_rows > 0 to a Mysqli Prepared statement, any help would be more than appreciated. <?php $mysqli = new mysqli('localhost', $username, $password, $db_name); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if ($stmt = $mysqli->prepare("SELECT * FROM $tbl_name WHERE phone_number=?")) { /* Bind our params */ $stmt->bind_param('s', $prefixphone); $stmt->execute(); $stmt->close(); /* Error */ printf("Prepared Statement Error: %s\n", $mysqli->error); } if ($mysqli->affected_rows > 0){ echo 'something here.....'; } ?> The above trick did not work.... My prepared function without "if ($mysqli->affected_rows > 0)" does not return any errors by the way. Thank you, Ben
  2. Hello, I am having this error, any idea why I did wrong please? Fatal error: Call to a member function format() on a non-object in /home/account/public_html/vchek/header.php on line 119 My code is this one at this line: <?php $mysqli = new mysqli("localhost", $username, $password, $db_name); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $stmt = $mysqli->prepare("INSERT INTO $tbl_name (id, date, phone_number, email, code, recommendedby, terms, vipnotifications, name, surname, age, group_leader, department, city) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param($id, $dat_date->format('Y-m-d H:i:s'), $phone_number, $email, $code, $recommendedby, $terms, $vipnotifications, $name, $surname, $age, $group_leader, $department, $city); $id = NULL; $phone_number = real_escape_string($phone_number); $email = real_escape_string($email); $code = real_escape_string($code); $recommendedby = real_escape_string($recommendedby); $terms = real_escape_string($terms); $vipnotifications = real_escape_string($vipnotifications); $name = real_escape_string($name); $surname = real_escape_string($surname); $age = real_escape_string($age); $city = real_escape_string($city); $group_leader = NULL; $department = NULL; /* execute prepared statement */ $stmt->execute(); ?> Thank you! Ben
  3. Nope my mistake, it does not work. When I echo the query, copy it and paste it in mysql it works but from the php to mysql automatically, it will not work.....weird... Thank you, Ben
  4. Hi All, I have changed this if(mysqli_affected_rows($db) <= 0){ to if(mysqli_affected_rows($db) >= 1){ and it works now. I have a few questions for you. 1)Is it normal that when I echo the query, I see the backslashes from mysqli_real_escape_string but in the database nothing is showing, is this right? 2)JcJones, I am sorry but I do not understand what you mean by "The problem is that the OP is trying to run the query two different ways", could you please explain this at a beginner level :-))...still learning PHP via Books and Youtube...I do not find it easy at all.... Thank you, Ben
  5. :-))) Sorry about that, here is what I get: Fatal error: Call to a member function execute() on a non-object in /home/piabyl/public_html/vieck3/header.php on line 126 Line 126 refers to $query->execute(); Thank you, Ben
  6. Thank you cyberRobot, Sorry for my lack of knowledge about Mysqli but this is new to me. I tried to add this but I am getting an error: $query->execute(); Can you please help me? Thank you,. Ben
  7. Hello, I cannot work this one out, I am trying to post some data into mysql using mysqli_real_escape_string but nothing happens, All I am getting is: "You are already already registered!" The database is empty and the phone_number field is set to "unique. Now What I do not understand is that the database is empty, no duplicate records in it but the mysqli_affected_row detects a duplicate or else something which I do not yet understand why it is happening. The query seems to be working ok(at least the output looks ok) but is not inputting the record in the database because mysqli_affected_rows is detecting a row. Here is my new code: <?php require_once("config.php"); $dat_date = date('Y-m-d H:i:s'); $db = new mysqli("localhost", $username, $password, $db_name); $query = sprintf("INSERT INTO $tbl_name (id, date, phone_number, email, code, recommended, terms, notifications, name, surname, age, city, leader, department) VALUES (NULL, '$dat_date', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', NULL, NULL)", $db->real_escape_string($phone_number), $db->real_escape_string($email), $db->real_escape_string($code), $db->real_escape_string($recommended), $db->real_escape_string($terms), $db->real_escape_string($notifications), $db->real_escape_string($name), $db->real_escape_string($surname), $db->real_escape_string($age), $db->real_escape_string($city), $db->real_escape_string($leader), $db->real_escape_string($department) ); if(mysqli_affected_rows($db) <= 0){ echo '<div align="center" class="text-not-correct">You are already already registered!<br></div>'; echo $query; mysqli_close($db); }else{ echo 'something'; } ?> Now the output of my query is: INSERT INTO data_xxxxx (id, date, phone_number, email, code, recommended, terms, notifications, name, surname, age, city, leader, department) VALUES (NULL, '2013-07-10 07:24:33', '0035679303062', '[email protected]', '44w787', 'o\'reilly', 'I have read and agree to the Terms and Conditions','Yes I agree to receive VIP notifications', 'o\'reilly', 'o\'reilly', '19', 'epinal', NULL, NULL) It seems that everythin is correct, any idea what did I miss please? Now the mysqli_real_escape_string seems to be working ok. Rmember, the phone mysql field is set as "unique". Thank you! Ben
  8. Hello, I would like to know if someone could tell me by giving me the php command on how to remove user accounts from Table A which are found in Table B? My table B are the unsubscribed users from Mailchimp while table a are the one subscribed from my website. Unfortunately, it is impossible to have the row deleted from Mailchimp in mysql so the only way to do this is to delete the users between the 2 tables... Any idea please? Thank you, Ben
  9. Thanks jcbones. I actually used this: if(mysqli_affected_rows($link) <= 0){ echo 'something here...'; It works very well :-))0 Hope this help someone. Bye all and thank you for your help. Ben
  10. Hello all. I have only started php a week ago and require your help as this problem is driving me crazy...... I have a form and the customers just enter their phone and email. When a duplicate of any of them is found I wish to show the message "Your phone or Mobile is already registered" Now when no duplication is found, I wish to echo something else. I have done this code below but I cannot get it to work....I created the database, everything is going well in without problem when I remove the statement <?php if(mysql_affected_rows() == 0){ echo '<div align="center" class="text-not-correct">Your Phone Number or Email or both are already registered!</div>';?> Here is part of my code, I only need in this tiny area please. <?php$link = mysqli_connect("localhost", $username, $password, $db_name)or die("cannot connect"); $mres_email = mysqli_real_escape_string($link, $_POST['email_form2']);$mres_phone = mysqli_real_escape_string($link, $_POST['phone_form2']);$mres_code = mysqli_real_escape_string($link, $_POST['code_form2']); $query = "INSERT INTO $tbl_name VALUES (NULL, '$dat_date', '$mres_phone', '$mres_email', '$mres_code')";mysqli_query($link, $query);if(mysql_affected_rows() == 0){ echo '<div align="center" class="text-not-correct">Your Phone Number or Email or both are already registered!</div>'; mysqli_close($link); }else{header("Refresh: 5;url=http://pwebsite.com/vio/page1.php");echo '<div align="center" class="text-correct">Congratulation you are now registered!</div></br>';echo '<div align="center"><img src="loading.gif" width="100" height="100" /></div>'; ?> Remember, the script is working fine but not when I try to check for duplicate. please help :-)))) Thank you! Benoit
×
×
  • 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.