Jump to content

Kristoff1875

Members
  • Posts

    242
  • Joined

  • Last visited

Posts posted by Kristoff1875

  1. my reply has nothing to do with your question, but your code shows that you are trying to find the first empty column to store a value in. this is a bad database design that results in overly complicated queries and code.

     

    you need to store one piece of data per row in your database table. then storing or finding the data becomes simple.

     

    I basically need to find which of the OneDel columns are not empty and then give them a value of 1 (not in the database) just to use them for a bit of calculation. If there's a better way I'm always happy to learn if you can inform me :)

  2. Currently i've got this code:

    	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    		{
    			if (!empty($row['OneDel1'])){ $OneDel1 == 1; }
    		}
    

    How would I go about replacing the if statement with a foreach statement that cycles through a number of columns from the database? Basically a shorter way of:

    	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    		{
    			if (!empty($row['OneDel1'])){ $OneDel1 == 1; }
    			if (!empty($row['OneDel2'])){ $OneDel2 == 1; }
    			if (!empty($row['OneDel3'])){ $OneDel3 == 1; }
    			if (!empty($row['OneDel4'])){ $OneDel4 == 1; }
    		}
    

    And so on?

     

    Thanks in advanced!

  3. Right. I've just turned off all of my add-ons, and guess what, it's not inserting the extra row... The only issue is, I've turned them all back on, and it's still not inserting the extra row!!

     

    Frustrating i've wasted so much time on it for nothing!

     

    Tip to everyone who may have this same issue: DISABLE ALL OF YOUR EXTENSIONS, TRY INCOGNITO OR TRY ANOTHER BROWSER BEFORE YOU WASTE TOO MUCH TIME ON SOMETHING THAT MAY NOT BE AN ISSUE WITH YOUR CODE!!!!!

  4. I mean:

    //note there are TWO semicolons below; one is for SQL...
    $sql = "insert into mysql_conventions (id,name,description) values ('','Semicolons','SQL statements should end with a semicolon.'); ";
    $query = mysqli_query($some_server,$sql);

     

    At this point, we're kind of grasping at straws. You might double-check Barand's question; perhaps the page IS being submitted more than once...

    I'm literally not even submitting the page anymore, simply loading up a page and having the insert on that page. Barand's question made me consider the browser, and it's working on safari but not chrome. Not sure whether this may be an addon causing it?

     

    Edit: Have just tested incognito in chrome, and that only inserts one... which suggests to me that it's an addon!

  5. Using this:

    <? 
    include("connect.php");
    
    $query = "INSERT INTO User (UserID, Name, Telephone, Email, FirstReg, LastLogin) VALUES ('NULL','Name','Telephone','Email',NOW(),NOW())";
    
    $result = mysql_query($query);
    if (!$result) {
       echo "error";
    } else {
      echo "Insert successful.  Last insert id: ".mysql_insert_id();
    
    }
    
    
    	?>
    

    I have just had:

     

     

     

    Insert successful. Last insert id: 15759

     

    However it has also inserted id 15759

  6. Sorry, how do you mean adding semicolons in the right place?

     

    I've taken everything out of the code, and using this:

    <? 
    include("connect.php");
    
    mysql_query("INSERT INTO User (UserID, Name, Telephone, Email, FirstReg, LastLogin) VALUES ('NULL','Name','Telephone','Email',NOW(),NOW())") or die(mysql_error());	
    	?>
    

    Results in 2 rows being inserted, although both contain the same data, just different ID's.

  7. +1

    I liked to use that after just doing a SELECT COUNT() query - ie a single field, single row result set.

     

    Kristoff - I see you aren't checking if any data was actually posted. Is it the absence of data that's causing your blanks?

     

    I don't believe so, the data is definitely being posted and the row is being populated, but it then goes on to create a second row that has no data in it.

  8. Is it much work to move to mysqli? I will look in to it, thanks.

     

    After trying: 

    <? session_start();
    
    include("connect.php");
        
    
    $_SESSION['Email'] = mysql_real_escape_string($_POST["Email"]);
    $_SESSION['Name'] = mysql_real_escape_string($_POST["Name"]);
    $_SESSION['Telephone'] = mysql_real_escape_string($_POST["Telephone"]);
    
     
    //note we'll be telling it to set the ID ... change "ID" as necessary for your database.  Using the null string will suffice.
    $query = "INSERT INTO User (UserID, Name, Telephone, Email, FirstReg, LastLogin) VALUES ('NULL','{$_SESSION['Name']}','{$_SESSION['Telephone']}','{$_SESSION['Email']}',NOW(),NOW())";
    
    $result = mysql_query($query);
    if (!$result) {
       //your error code
    } else {
      echo "Insert successful.  Last insert id: ".mysql_insert_id();
    
    }
        
    ?>
    

    Resulted in:

     

     

     

    Insert successful. Last insert id: 15724

     

    And only inserting one row and no blank one... Table structure:

    CREATE TABLE `User` (
     `UserID` int(11) NOT NULL AUTO_INCREMENT,
     `Email` tinytext NOT NULL,
     `Name` tinytext NOT NULL,
     `Address1` text NOT NULL,
     `Address2` text NOT NULL,
     `Address3` text NOT NULL,
     `Town` text NOT NULL,
     `County` text NOT NULL,
     `Postcode` text NOT NULL,
     `FirstReg` datetime NOT NULL,
     `LastLogin` datetime NOT NULL,
     `UseBizAddress` int(11) NOT NULL,
     `Telephone` text NOT NULL,
     `ContactBy` varchar(11) NOT NULL,
     `Agree` int(11) NOT NULL
    
  9. Hi guys, having a strange issue at the moment whereby my insert is being followed up by a completely blank row other than the auto inc of the ID, which is how i know it's being inserted after.

     

    Here's the code:

    <? session_start(); 
    
    include("connect.php");
    	
    $_SESSION['Email'] = mysql_real_escape_string($_POST["Email"]);
    $_SESSION['Name'] = mysql_real_escape_string($_POST["Name"]);
    $_SESSION['Telephone'] = mysql_real_escape_string($_POST["Telephone"]);
    
    mysql_query("INSERT INTO User (Name, Telephone, Email, FirstReg, LastLogin) VALUES ('{$_SESSION['Name']}','{$_SESSION['Telephone']}','{$_SESSION['Email']}',NOW(),NOW())") or die(mysql_error());	
    ?>
    

    The form before this is as follows:

    <form id="addnew" action="page1.php" method="post">
    
    <label for="Name" class="label large">Your Name</label>
    
    <input name="Name" type="text" />
    
    <label for="Telephone" class="label large">Telephone</label>
    
    <input name="Telephone" type="text" />
    
    <label for="Email" class="label large">Your Email</label>
    
    <input name="Email" type="text" />
    
    
    <input type="submit" />
    </form>
    

    And this page with the form also includes a session open, destroy and close at the top to make sure any old details are cleared from the session.

     

    Anybody got any ideas why it's inserting a rogue row?!

     

    Thanks in advance!

     

    Edit: To rule out the session being an issue i've used the following:

    <? session_start(); 
    
    include("connect.php");
    	
    $Email = mysql_real_escape_string($_POST["Email"]);
    $Name = mysql_real_escape_string($_POST["Name"]);
    $Telephone = mysql_real_escape_string($_POST["Telephone"]);
    
    mysql_query("INSERT INTO User (Name, Telephone, Email, FirstReg, LastLogin) VALUES ('$Name','$Telephone','$Email',NOW(),NOW())") or die(mysql_error());	
    ?>
    
    

    And this also comes up with the same issue.

     

    Second Edit:

    <? session_start(); 
    
    include("connect.php");
    	
    $Email = mysql_real_escape_string($_POST["Email"]);
    $Name = mysql_real_escape_string($_POST["Name"]);
    $Telephone = mysql_real_escape_string($_POST["Telephone"]);
    
    mysql_query("INSERT INTO User (Name, Telephone, FirstReg, LastLogin) VALUES ('$Name','$Telephone',NOW(),NOW())") or die(mysql_error());	
    ?>
    
    

    Results in just one row... as does:

    <? session_start(); 
    
    include("connect.php");
    	
    $Email = mysql_real_escape_string($_POST["Email"]);
    $Name = mysql_real_escape_string($_POST["Name"]);
    $Telephone = mysql_real_escape_string($_POST["Telephone"]);
    
    mysql_query("INSERT INTO User (Name, Email, FirstReg, LastLogin) VALUES ('$Name','$Email',NOW(),NOW())") or die(mysql_error());	
    ?>
    
    

    and

    <? session_start(); 
    
    include("connect.php");
    	
    $Email = mysql_real_escape_string($_POST["Email"]);
    $Name = mysql_real_escape_string($_POST["Name"]);
    $Telephone = mysql_real_escape_string($_POST["Telephone"]);
    
    mysql_query("INSERT INTO User (Telephone, Email, FirstReg, LastLogin) VALUES ('$Telephone','$Email',NOW(),NOW())") or die(mysql_error());	
    ?>
    
    

    But put all 3 (Name, Telephone and Email) in and it inserts an extra row.

  10. Hi guys,


    Apologies if this is the wrong forum, I didn't quite know where to put it.


    Does anyone know if this is possible in Wordpress?


    The first part of what I'd like to do is to send all posts, upon submission, to a second database that holds my forum. I literally only need to post_content and post_title to be inserted to the forum posts database and the username will always be the same.


    The second part of what I'd like to do, and this may not even be possible, is to return the URL of the forum post to show (in my template if possible) below the post.


    Thanks in advance


  11. Currently lay in bed and it just popped in to my head (sad I know!) I'm not sure how I'd go about having featured items...

     

    If you've got a pagination showing 10 items per page, would it be possible to call everything from the "Male" (for example) column and then have the top 3 rows on each page random entries where they have the required value in the Featured column?

  12. Sorry, yes I'd like to end up with the select box in the second query:
     

    <select name="Area" id="Area" class="dropdown" style="width:260px;">
            <option> Any </option>
            <option <?php if ($row1['Area']=='London') { echo 'selected="SELECTED"'; } ?> value="London"> London </option>
            <option <?php if ($row1['Area']=='Birmingham') { echo 'selected="SELECTED"'; } ?> value="Birmingham"> Birmingham </option>
    </select> 
    

    With the results from the first, so:

    <option <?php if ($row1['Area']=='***RESULT FROM QUERY 1***') { echo 'selected="SELECTED"'; } ?> value="***RESULT FROM QUERY 1***"> ***RESULT FROM QUERY 1*** </option>
    

    To for the second if possible.

  13. I have a form that has 2 select menus, I was hoping I could pre-populate the menus using the fields that exist in the table of the database, is this possible? I've created a dropdown, using the following:

    	/* Get data. */
    	$sql = "SELECT DISTINCT Area FROM Users ORDER BY Area ASC";
    	$result = mysql_query($sql1); 
    
    while($row = mysql_fetch_array($result))
    		{
     '<option value="'.$row['Area'].'"> '.$row['Area'].' </option>';
    			  }
    
    With <select> tags wrapped around it works just how I wanted it to, apart from it not being involved with the second dropdown:

    $sql1 = "SELECT * FROM Users WHERE UserID = $UserID";
    $result1 = mysql_query($sql1); 
    
    while($row1 = mysql_fetch_array($result1))
    {
    
    <select name="Area" id="Area" class="dropdown" style="width:260px;">
            <option> Any </option>
            <option <?php if ($row1['Area']=='London') { echo 'selected="SELECTED"'; } ?> value="London"> London </option>
            <option <?php if ($row1['Area']=='Birmingham') { echo 'selected="SELECTED"'; } ?> value="Birmingham"> Birmingham </option>
            </select> 
    }
    
    Is there a way of integrating the first result in to the second? Or even better, integrating them in to one query? I wasn't sure if that was possible as i'm searching for one row in the second query.

     

    Thanks in advance.

  14. Ok, have changed some things that I thought may be the problem... But still no joy:

    $query = "SELECT o.*, p.*, COUNT(*) as num
    	FROM Offers o
    	INNER JOIN Partners p USING (PartnerID)
    	WHERE PartnerArea = '$offerarea'";
    	
    	$total_pages = mysql_fetch_array(mysql_query($query));
    	$total_pages = $total_pages[num];
    	
    	/* Setup vars for query. */
    	$targetpage = "searchoffers.php";			//your file name  (the name of this file)
    	$limit = 1; 								//how many items to show per page
    	$page = $_GET['page'];
    	if($page) 
    		$start = ($page - 1) * $limit; 			//first item to display on this page
    	else
    		$start = 0;								//if no page var is given, set start to 0
    	
    	/* Get data. */
    	$sql = "SELECT o.*, p.*
    	FROM Offers o
    	INNER JOIN Partners p USING (PartnerID) WHERE PartnerArea = '$offerarea' LIMIT $start, $limit";
    	$result = mysql_query($sql);
    
  15. Yep, would that be the problem?

    $query = "SELECT o.*, p.*, COUNT(*) as num
    FROM Offers o
    INNER JOIN Partners p USING (PartnerID)";
    
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];
    
    /* Setup vars for query. */
    $targetpage = "searchoffers.php"; //your file name  (the name of this file)
    $limit = 5; //how many items to show per page
    $page = $_GET['page'];
    if($page) 
    $start = ($page - 1) * $limit; //first item to display on this page
    else
    $start = 0; //if no page var is given, set start to 0
    
    /* Get data. */
    $sql = "SELECT o.*, p.*, COUNT(*) as num
    FROM Offers o
    INNER JOIN Partners p USING (PartnerID) WHERE PartnerArea = '$offerarea' LIMIT $start, $limit";
    
  16. Hi, could anyone tell me why this isn't working?

    SELECT o.*, p.*, COUNT(*) as num
    	FROM Offers o
    	INNER JOIN Partners p USING (PartnerID) LIMIT $start, $limit
    

    The LIMIT is to make pagination, it's working when just calling info from one table, but when I INNER JOIN the tables, the second page is just displaying blank.

     

    Any help appreciated. Thanks

×
×
  • 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.