rjclancy's Profile
Reputation: 1
Apprentice
- Group:
- Active Members
- Active Posts:
- 53 (0.07 per day)
- Joined:
- 18-March 11
- Profile Views:
- 834
- Last Active:
Oct 01 2012 03:28 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
Posts I've Made
-
In Topic: insert into two different tables using php
Posted 24 Sep 2012
nightscream, 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 -
In Topic: insert into two different tables using php
Posted 22 Sep 2012
nightscream, 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:) -
In Topic: Insert Form Data Into Database
Posted 22 Sep 2012
Atli, on 21 September 2012 - 05:00 PM, said:
rjclancy, on 21 September 2012 - 11:32 PM, said:i usedecho "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
-
In Topic: Insert Form Data Into Database
Posted 21 Sep 2012
RudiVisser, 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 usedecho "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:) -
In Topic: Live server login not working:(
Posted 6 Aug 2012
RudiVisser, on 06 August 2012 - 07:56 AM, said:
rjclancy, on 06 August 2012 - 03:41 PM, said:
Remove your use of session_register and learn how sessions work.
Thanks for the link...got it working and learned a bit:)
Kind regards ronan
My Information
- Member Title:
- D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Location:
- Sligo, Ireland
Contact Information
- E-mail:
- Private
Friends
|
|


Find Topics
Find Posts
View Reputation Given

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