Jump to content

wright67uk

Members
  • Posts

    454
  • Joined

  • Last visited

Everything posted by wright67uk

  1. Also your form should be within the <body> and </body> tags opposed to the head tags. Good luck with your learning!
  2. It looks like you close your </head> twice in the first page, and you have html in your head aswell. May be worth checking over your page structure.
  3. Could you use the badge as a background image, and then simply echo your returned variable over the image?
  4. What do you return when you echo $passcode?
  5. I'm trying to update a record if it exists and insert one if it doesn't. My select returns -1 results. And my database is inserting new records opposed to updating the current ones. Can anyone tell me where I'm going wrong please? <?php $id = ''; $name = "ed"; $year = 2013; $month = "may"; $wins = 48; if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error());exit();} $stmt = $mysqli->prepare("SELECT * FROM compare WHERE name = ? AND month = ? AND year = ?"); $stmt->bind_param('ssi', $name, $month, $year); printf("Affected rows (SELECT): %d\n", $mysqli->affected_rows); if ($mysqli->affected_rows > 0) { $stmt = $mysqli->prepare("UPDATE compare SET wins = ? WHERE name = ? AND month = ? AND year = ?"); $stmt->bind_param('isii', $wins, $name, $month, $year); $stmt->execute(); $stmt->close(); } else { $stmt = $mysqli->prepare("INSERT INTO compare VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param('isisi', $id, $name, $year, $month, $wins); $stmt->execute(); $stmt->close(); } ?>
  6. Hi, I'm new to MySQLi and I'm trying to do a basic insert into my database. I've checked the first part of my script and I'm connecting fine. I've also echoed $mysqli->host_info . "\n"; and everything is as it should be. The below php gives me an error; Fatal error: Call to undefined method mysqli::bind_param() Why is this? and how can I change my code so that I can do the insert without error? Many thanks. <?php define('HOST', '###'); define('USERNAME', '###'); define('PASSWORD', '###'); define('DB', '###'); $mysqli = new mysqli(); $mysqli->connect(HOST, USERNAME, PASSWORD, DB); $name = "nametest";//$_POST['name']; $year = 2018; //$_POST['year']; $month = "jan"; //$_POST['month']; $wins = 5; //$_POST['wins']; if ($mysqli->connect_errno) { printf("Connect failed: %s\n", $mysqli->connect_error); exit(); } $mysqli->prepare("INSERT INTO `compare` VALUES ('?','?','?','?');"); $mysqli->bind_param("sisi", $name, $year, $month, $wins); $mysqli->execute(); $mysqli->close(); ?>
  7. Apparently, if you have longtext present ($notes), you HAVE to call store_result before using bind_result.
  8. <?php include 'connect.php'; //$date = date('Y-m-d H:i:s'); //$username = "Ed"; $horse = isset($_GET['horse'])&& $_GET['horse']!=''?$_GET['horse']:''; echo "<h1>" . $horse . "</h1>"; if ($stmt = $mysqli->prepare("SELECT horse_name, username, Notes, publish_date FROM notes WHERE horse_name = ?")); { $stmt->bind_param("s", $horse); $stmt->execute(); $stmt->bind_result($horse_name, $username, $notes, $publish_date); } while ($stmt->fetch()) { printf("%s added %s \n", $username, $notes); echo "<br/><br/>-------------------------<br/>"; } ?>
  9. I'm not sure why but I can't get $notes to print. I'm very new to these methods and Was wondering if anyone could tell me where I'm going wrong and how I can debug I'm similar circumstances.
  10. I saw this code and wondered what bind result did and what purpose it serves? $color = "purple"; $stmt = $mysqli->stmt_init(); if ($stmt->prepare("SELECT FirstName, LastName FROM Friends WHERE FavoriteColor = ?")) { $stmt->bind_param("s" $color); $stmt->execute(); $stmt->bind_result($firstname, $lastname);
  11. Lol I did mean horse yes... According to the urban dictionary a hourse is a cop that takes both the side of the criminal and the cops with a price.
  12. I'm recording the date a horse was added to the database. Later on I will take notes about each horse from visitors. The date will show how relevant the note will be
  13. <?php include 'connect.php'; $date = date('Y-m-d H:i:s'); $username = "Ed"; $horse = isset($_GET['horse'])&& $_GET['horse']!=''?$_GET['horse']:''; echo $horse; // echos fine $query = "SELECT horse_name, username FROM notes where horse_name = '$horse'"; $result = $mysqli->query($query); //if table is empty then insert should happen below if(!$result){ $query = "INSERT INTO notes SET horse_name='$horse', username='$username', publish_date='$date'"; $results = $mysqli->query($query); } else{ echo 'horse is exists'; } $result->free(); $mysqli->close(); ?> Hello, i'm trying to add some details to a database if no records exist for $horse. At the moment I have an empty table, and nothing is being inserted when I test the code. $horse echo's out fine and all I get is this followed by 'horse exists'. What am I doing wrong here. (I'm new to mysqli so I maybe goig a bit wrong here) I have tested my connection.
  14. How can I test a number for digits after a decimal point? I would like to do somthing like; $num = 5.34 If the digits after the decimal point of $num are less than .10 then round down, else $num++ The idea being that this could be used in a loop until either a whole number is found, or until a number is rounded down.
  15. Look at the manual, and get confused about the difference between floatval, intval and settype lol. I could try one of these, until one works, but I dont want to cause any problems later down the line by using the wrong one
  16. That was used in a different file. In this circumstance I'm only using numbers. That was amazingly well spotted however!!!
  17. Yes your right. Is floatval best used to do that?
  18. How can I subtract from a variable, but keep my decimal places? When I try the below example I return 0 <?php $a = $_attributeSelection["backp1"]; echo $a -1; ?> // 1.53 becomes 0 However When I try the below example i return 0.69 <?php $b = 1.69; echo $b-1;?> // 1.69 becomes 0.69
  19. I'm looking to only return rows where the first two letters of $_attributeSelection["backp1"] are GB I'm sure I need to use strpos somehow, but Im not sure how to use it with my code can anyone show me how? <?php foreach ($selections as $_selection) { $_attributeSelection = $_selection->attributes(); ?> <tr> <td> <?php echo $_attributeSelection["name"] ?> </td> <td> <b><?php echo $_attributeSelection["backp1"] ?></b><br/> </td> </tr>
  20. Thanks David! bleured27 what TABTABTAB is all this CTRL AND Q all about?
  21. I'm trying to make a signup page, but i'm coming into trouble when checking for usernames and email addresses that already exist. note: My code is incomplete so I'm yet to check for things like correct email formats etc. Im using a select statement and counting the results. If results are returned then I was expecting "this username or email address already exists!" to echo but it doesn't. Would love a little help if anyone can help me! <?php if(isset($_POST['processForm'])) { $uname = mysql_real_escape_string($_POST['uname']); $fname = mysql_real_escape_string($_POST['fname']); $lname = mysql_real_escape_string($_POST['lname']); $age = mysql_real_escape_string($_POST['age']); $pass = mysql_real_escape_string($_POST['pass']); $handicap = mysql_real_escape_string($_POST['handicap']); $cpass = mysql_real_escape_string($_POST['cpass']); $email = mysql_real_escape_string($_POST['email']); if(empty($uname)) {echo "<br />You haven't entered a username<br/>"; $errors_found = true;} if(empty($fname)) {echo "<br />You haven't entered your first name<br/>"; $errors_found = true;} if(empty($lname)) {echo "<br />You haven't entered your last name<br/>"; $errors_found = true;} if(empty($age)) {echo "<br />You haven't entered a your age<br/>"; $errors_found = true;} if(empty($pass)) {echo "<br />You haven't entered a password<br/>"; $errors_found = true;} if(empty($handicap)){echo "<br />You haven't entered a handicap<br/>"; $errors_found = true;} if(empty($cpass)) {echo "<br />You haven't confirmed your password<br/>"; $errors_found = true;} if(empty($email)) {echo "<br />You haven't entered an email address<br/>";$errors_found = true;} if($pass != $cpass) {echo "<br/>Your passwords do not match!<br/>"; $errors_found = true;} $Select = "SELECT * FROM registration WHERE uname = ".$uname." OR email = ".$email." LIMIT 1"; $Result = mysql_query($Select); if (mysql_num_rows($Result) > 0) {echo 'this username or email address already exists!'; $errors_found = true;} } if (!$errors_found) {$sql = "INSERT INTO registration (uname, fname, lname, age, handicap, pass, email, status) VALUES ('$uname', '$fname', '$lname', '$age', '$handicap','$pass','$email','1')"; mysql_query($sql); echo '<span class="thanks"><br/>Thankyou for registering, you can now <a href="login.php">log in</a></span>'; } ?>
  22. header("Location:ranges2.php?a=$a&b=$b&c=$c&d=$d&e=$e"); I have no idea why but when I changed my URL, everything worked fine...
  23. I have a form which posts to ranges_process.php (shown below) I have an error; Warning: Cannot modify header information - headers already sent by (output started at urlhere/ranges_process.php:3) in sameurlhere/ranges_process.php on line 37 Ive checked and as far as I can see, im not echoing or printing anything. What could be causing this warning? <?php session_start();?> <?php $user_id = $_SESSION['user_id']; if(isset($_POST['processForm'])) { $yards = $_POST['yards']; $club = $_POST['club']; $date = $_POST['date']; $competition = $_POST['location']; if (empty($date)) {$a= "<br />You haven't entered a date"; $errors_found = true;} if (!is_numeric($yards)) {$b= "<br />You haven't entered a distance!"; $errors_found = true;} if (empty($club)) {$c= "<br/>You haven't selected a club!"; $errors_found = true;} if (empty($competition)) {$d= "<br />You haven't entered a location"; $errors_found = true;} if (!$errors_found) { $date = str_replace("-","",$date); $year =substr($date,0,4); //CONNECTION HERE $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "INSERT INTO TABLENAMEHERE (user_id, yard, club, date, year, competition) VALUES ('$user_id', '$yards', '$club', '$date', '$year', '$competition')"; mysql_query($sql); $e= '<br/><br/>A distance, has now been added.'; }}; header("Location: http://URLHERE/beta/ranges2.php?a=$a&b=$b&c=$c&d=$d&e=$e"); // line 37 //RETURN TO ORIGINAL LOCATION... ?>
×
×
  • 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.