Unable to update mysql with php code. (code attached)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jlgray48
Forum Newbie
Posts: 5
Joined: Sun Apr 22, 2007 11:38 am

Unable to update mysql with php code. (code attached)

Post by jlgray48 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


UAH is my database, yahoo is a table with id and name as fields. I got some code off of another site and it works but I'm trying to use the method our instructor taught and I'm having trouble. Any help is greatly appreciated.

Code: Select all

<?

$name = "Kim";
$id = "44";
$conn=mysql_connect("127.0.0.1", "odbc", "");
mysql_select_db("uah",$conn);
$sql = "Insert into yahoo values('$id', '$name')";
mysql_query($sql,$conn);
$result = mysql_query($sql,$conn);

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Debug:

Code: Select all

<?php

$name = "Kim"; 
$id = "44"; 
$conn=mysql_connect("127.0.0.1", "odbc", "") or die (mysql_error()); 
mysql_select_db("uah",$conn) or die(mysql_error()); 
$sql = "Insert into yahoo values('$id', '$name')"; 
mysql_query($sql,$conn) or die(mysql_error()); 
$result = mysql_query($sql,$conn); 

?>
You should really pass values through mysql_real_escape_string() before putting them in queries too.
jlgray48
Forum Newbie
Posts: 5
Joined: Sun Apr 22, 2007 11:38 am

Post by jlgray48 »

That worked. So was my only problem the php at the top?

Thanks for all your help.

jg
Post Reply