Page 1 of 1

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

Posted: Sun Apr 22, 2007 11:41 am
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]

Posted: Sun Apr 22, 2007 11:50 am
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.

Posted: Sun Apr 22, 2007 12:10 pm
by jlgray48
That worked. So was my only problem the php at the top?

Thanks for all your help.

jg