Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   Sql (https://novahq.net/forum/showthread.php?t=26098)

atholon 05-27-2005 08:14 PM

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!

atholon 05-27-2005 08:17 PM

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'); 


atholon 05-27-2005 08:20 PM

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')");
?>


IcIshoot 05-27-2005 10:23 PM

is any error message being displayed?

IcI

atholon 05-27-2005 11:09 PM

Negative.

I even put this on the end:
PHP Code:

 or die ("<br /><br />Mysql Error: ".mysql_error()); 


IcIshoot 05-28-2005 12:09 AM

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

JonM 05-28-2005 12:25 AM

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 :)

atholon 05-28-2005 08:20 AM

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 :p

atholon 05-28-2005 08:23 AM

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.

IcIshoot 05-28-2005 09:30 AM

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

atholon 05-28-2005 09:31 AM

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.

Scott 05-28-2005 11:26 AM

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.

atholon 05-28-2005 11:42 AM

Cool :)

Scott 05-28-2005 11:57 AM

and for you user=' ' ' problem..

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

Scott 05-28-2005 12:00 PM

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

}

Scott 05-28-2005 12:03 PM

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.

atholon 05-28-2005 12:39 PM

:) 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");
?>


atholon 05-28-2005 12:45 PM

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:

Scott 05-28-2005 02:25 PM

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

atholon 05-28-2005 03:20 PM

I'll take a screen of it from phpmyadmin


All times are GMT -5. The time now is 04:34 PM.

Powered by vBulletin®