Go Back   Novahq.net Forum > Computers > Web design and Programming
FAQ Community Calendar Today's Posts Search

Web design and Programming Discuss website creation and other programming topics.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-27-2005, 08:14 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
Sql

Hey, what's wrong with this? It won't input the values!

PHP Code:
<?
include("./config.php");

mysql_query("INSERT INTO tutorials VALUES ('1', 'test1', 'test2', 'test3') or die ("<br 

/><br />Mysql Error".mysql_error());
?>
Also can someone tell me how I can choose a specific column and row that I want to select. Thanks!
__________________
Reply With Quote
  #2  
Old 05-27-2005, 08:17 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
Ha! Ye Beggers I found out how to select certain columns I hope it is kinda the same as the rows......

PHP Code:
INSERT INTO `tutorials` (`sid`, `title`, `body`) VALUES ('ghgfh''fghgfhfg''fhg'); 
__________________
Reply With Quote
  #3  
Old 05-27-2005, 08:20 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
NM it still is not working.

This is what I am using:
PHP Code:
<?
include("./config.php");

mysql_query("INSERT INTO `tutorials` (`title`, `body`) VALUES ('fghgfhfg', 'fhg')");
?>
__________________
Reply With Quote
  #4  
Old 05-27-2005, 10:23 PM
IcIshoot is offline IcIshoot

Join Date: Mar 2004
Location: Farmington Hills, MI
Posts: 1,473

Send a message via AIM to IcIshoot Send a message via MSN to IcIshoot Send a message via Yahoo to IcIshoot
is any error message being displayed?

IcI
Reply With Quote
  #5  
Old 05-27-2005, 11:09 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
Negative.

I even put this on the end:
PHP Code:
 or die ("<br /><br />Mysql Error: ".mysql_error()); 
__________________
Reply With Quote
  #6  
Old 05-28-2005, 12:09 AM
IcIshoot is offline IcIshoot

Join Date: Mar 2004
Location: Farmington Hills, MI
Posts: 1,473

Send a message via AIM to IcIshoot Send a message via MSN to IcIshoot Send a message via Yahoo to IcIshoot
how many fields are there in the table?

You may want to read through this and see if any thing would apply to help out: http://dev.mysql.com/doc/mysql/en/insert.html

Also, if you want to select specific columns from do


SELECT field1, field2 FROM table_name


To limit it to a specific row (such as a particulare user):
//Assume $userID = 100


SELECT username, userpassword FROM user_table WHERE user_ID ='$userID'

That will provide the username and password for the user who's id is 100

IcI
Reply With Quote
  #7  
Old 05-28-2005, 12:25 AM
JonM is offline JonM
Registered User

Join Date: Jun 2004
Posts: 2,156

hmm i run into this some times...copy what PHP MY ADMIN does when your doing it, and put in some of those post variables or whatever
Reply With Quote
  #8  
Old 05-28-2005, 08:20 AM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
It is workin' fine now, I was told I need to use replace with " and '. Is there another character that I need to replace? I should make an array or function out of it
__________________
Reply With Quote
  #9  
Old 05-28-2005, 08:23 AM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
BTw that is right. The first variable is SID so I can use that as refrence I guess...time to get the exporting part done. Then I can start adding html and stuff to the fields...this tutorial script is going to rock.
__________________
Reply With Quote
  #10  
Old 05-28-2005, 09:30 AM
IcIshoot is offline IcIshoot

Join Date: Mar 2004
Location: Farmington Hills, MI
Posts: 1,473

Send a message via AIM to IcIshoot Send a message via MSN to IcIshoot Send a message via Yahoo to IcIshoot
It doesn't have to be the first variable. You can use any field.

And you can even be more selective using more WHERE clauses, using AND or OR:

Select * from user_table WHERE is_admin = '1' AND WHERE password = '$password'


IcI
Reply With Quote
  #11  
Old 05-28-2005, 09:31 AM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
Yeah but if password has ' in it then it would be password = ' ' ' which would screw it up. That is why I need to use the replace command. I guess you can do the same thing with html stuff if you want to disable html.
__________________

Last edited by atholon; 05-28-2005 at 09:37 AM.
Reply With Quote
  #12  
Old 05-28-2005, 11:26 AM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

you should only use WHERE once, AND WHERE could confuse with bigger querys.. like

SELECT * FROM tbl_name WHERE user='user' AND password='password' AND (email='email' OR phone='phone')");

using a bracket will group it together, so either one has to be true, hence the OR.
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #13  
Old 05-28-2005, 11:42 AM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
Cool
__________________
Reply With Quote
  #14  
Old 05-28-2005, 11:57 AM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

and for you user=' ' ' problem..

INSERT INTO tbl_name VALUES ('".addslashes($data)."','".addslashes($data2)." ')
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #15  
Old 05-28-2005, 12:00 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

if you get sick of typing addslashes all the time.. make a function...

function as($key) {

return addslashes($key);

}

then use as($data)




.. I do this for stripslashes and htmlspecialchars.. so comminly used but there so long to type out..

I use

function slash($key) {

$key=stripslashes($key);

return stripslashes($key);

}



function html($key) {
$key=htmlspecialchars($key);

return slash($key); //for output

}
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #16  
Old 05-28-2005, 12:03 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

you can save alot of time by writing functions ath.. like or mysql_query() or die ("theres an error yada yada".mysql_error());

function my_error() {
$key="theres an error yada yada".mysql_error();
return $key;
}

now it's just mysql_query() or die(my_error());


I write alot of functions just to shorten the name of a long function.. like number_format() would be nf() etc etc.
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #17  
Old 05-28-2005, 12:39 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
I am looking at SS site trying to use the select query and it aint working.
PHP Code:
<?
include("./config.php");
$nmi=mysql_fetch_array(mysql_query("SELECT * FROM tutorials WHERE id='1'"));
$title=htmlspecialchars(stripslashes($nmi["title"]));
$body=htmlspecialchars(stripslashes($nmi["body"]));
Echo(
"<b>Title:</b><br />\n");
Echo(
"$title<br />\n");
Echo(
"<b>Body:</b><br />\n");
Echo(
"$body<br />\n");
?>
__________________
Reply With Quote
  #18  
Old 05-28-2005, 12:45 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
I get this:

Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\easyphp\www\ath\test2.php on line 3
Title:

Body:
__________________
Reply With Quote
  #19  
Old 05-28-2005, 02:25 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

well theres nothing wrong there so it's either the name of your table or id..
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #20  
Old 05-28-2005, 03:20 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
I'll take a screen of it from phpmyadmin
__________________
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query causing blank page .Simon. Web design and Programming 3 11-05-2010 05:20 AM
Book recommendation for ASP.NET 2.0 and SQL Server DevilDog#1 Web design and Programming 0 01-05-2007 07:12 PM


All times are GMT -5. The time now is 12:44 AM.




Powered by vBulletin®