rjclancy's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Active Members
Active Posts:
56 (0.04 per day)
Joined:
18-March 11
Profile Views:
1,271
Last Active:
User is offline May 23 2013 12:41 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Icon   rjclancy has not set their status

Posts I've Made

  1. In Topic: Android notifyDataSetChanged() not working!...

    Posted 21 May 2013

    View Postjon.kiparsky, on 21 May 2013 - 09:11 AM, said:

    Might get better traction on this in the Android forum.


    How to move???
  2. In Topic: insert into two different tables using php

    Posted 24 Sep 2012

    View Postnightscream, on 22 September 2012 - 09:05 AM, said:

    Quick writeup, between new PDO you should put the right values and the poloptions you should change to your needs
    <?php
    	$postTitle=$_POST['title'];
    	$user_id=$_POST['user_id'];
    	$postanswer1=$_POST['postan1'];
    	$postanswer2=$_POST['postan2'];
    	$postanswer3=$_POST['postan3'];
    	
    	$db = new PDO(''); // change it with the right details
    	$sql = "INSERT INTO `polls` (title, user_id) VALUES (?,?)";
    	
    	$polStmt = $db->prepare($sql);
    	$polStmt->bindValue(1, $postTitle);
    	$polStmt->bindValue(2, $user_id);
    	$polStmt->execute();
    	if($polStmt->execute())
    	{
    		$id = $db->lastInsertId();
    		$sql = "INSERT INTO poll_options(id, col1) VALUES(?,?)";
    		
    		$polOptStmt = $db->prepare($sql);
    		$polOptStmt->bindValue(1, $id);
    		$polOptStmt->bindValue(2, $postanswer1);
    		$polOptStmt->execute();
    	}
    	else
    	{
    		echo("unable to input poll");
    	}
    	
    header('Location:profile.php');
    exit();
    ?>
    


    Hi nightscream....iv been trying to get this working, and i seem to be getting somewere, but i think i might have a problem...all my code is mysql and not mysqli...i read somewere online to use PDO my code has to be mysqli????would this seem right to you???

    Thanks
  3. In Topic: insert into two different tables using php

    Posted 22 Sep 2012

    View Postnightscream, on 22 September 2012 - 09:05 AM, said:

    Quick writeup, between new PDO you should put the right values and the poloptions you should change to your needs
    <?php
    	$postTitle=$_POST['title'];
    	$user_id=$_POST['user_id'];
    	$postanswer1=$_POST['postan1'];
    	$postanswer2=$_POST['postan2'];
    	$postanswer3=$_POST['postan3'];
    	
    	$db = new PDO(''); // change it with the right details
    	$sql = "INSERT INTO `polls` (title, user_id) VALUES (?,?)";
    	
    	$polStmt = $db->prepare($sql);
    	$polStmt->bindValue(1, $postTitle);
    	$polStmt->bindValue(2, $user_id);
    	$polStmt->execute();
    	if($polStmt->execute())
    	{
    		$id = $db->lastInsertId();
    		$sql = "INSERT INTO poll_options(id, col1) VALUES(?,?)";
    		
    		$polOptStmt = $db->prepare($sql);
    		$polOptStmt->bindValue(1, $id);
    		$polOptStmt->bindValue(2, $postanswer1);
    		$polOptStmt->execute();
    	}
    	else
    	{
    		echo("unable to input poll");
    	}
    	
    header('Location:profile.php');
    exit();
    ?>
    


    Hi nightscream... i never even heard of this PDO...ill be looking into it and ill get back to you...BIG BIG thanks for the post:)
  4. In Topic: Insert Form Data Into Database

    Posted 22 Sep 2012

    View PostAtli, on 21 September 2012 - 05:00 PM, said:

    View Postrjclancy, on 21 September 2012 - 11:32 PM, said:

    i used
    echo "unable to insert comment, error: " . mysql_error();
    
    and found the problem...
    i had '' around my ints in my insert statment!!!!

    Odd. That's usually not a fatal error for MySQL. It usually just silently casts them to integers.

    Just out of curiosity, do you remember what the error message was?


    Hi Atli....

    Here is the error i got...
    unable to insert comment, error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1', '3')' at line 1 
    
    
  5. In Topic: Insert Form Data Into Database

    Posted 21 Sep 2012

    View PostRudiVisser, on 21 September 2012 - 04:17 PM, said:

    .. what's the error?

    You can get the error using mysql_error(), like this:
    echo "unable to insert comment, error: " . mysql_error();
    


    My best guess would be that you're trying to insert a ' in a comment field, which means that your strings are becoming unescaped, look into some basic error handling. But if this is the issue to fix it is simple, before the PDO/MySQLi Nazis come along you can use mysql_real_escape_string to escape all of your values before trying to insert them into the database.

    Once you're done there, look into PDO/MySQLi, specifically prepared statements. They'll help you greatly reduce errors like this in the future.

    EDIT: Note also that echo isn't a function, it's a language construct, and so doesn't need/shouldn't have parenthesis around it's "arguments".


    Hey RudiVisser...

    Big thanks for the reply...

    i used
    echo "unable to insert comment, error: " . mysql_error();
    
    and found the problem...
    i had '' around my ints in my insert statment!!!!

    Big Big thanks for the tips, ill defenitly look into PDO/MySQLi...

    again big thanks:)

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Sligo, Ireland

Contact Information

E-mail:
Private

Friends

Comments

rjclancy has no profile comments yet. Why not say hello?